[poorly written spoilers] would be interesting to ...
# advent-of-code
j
[poorly written spoilers] would be interesting to get some feedback on how bad my Kotlin is at the moment - solved day 1 in a rush https://gist.github.com/CraicOverflow89/bbb15b69d82c22d0845380514a43d613 https://gist.github.com/CraicOverflow89/ece2fc083f39d2c63889156628ecd317
p
looks like writing C in Kotlin tbh 🙂
j
is that comment on not cuddling my braces? let's not get into that right now haha
d
So a couple of comments: I very very rarely see prefix increment / decrement outside of C.
p
yep what Derek said
j
in terms of the ways in which the code could be more efficient by using list comprehensions though, what can be improved?
ok so what would the more kotlin way of doing things be?
d
The other thing is that I the solution (for the first part, I haven’t done the second part yet), using a functional programming style with filter/map/sum
p
also opening-brace-on-the-same-line is a choice in Java but it's pretty much a must in Kotlin, because of how lambdas are defined
j
ya know I hated Go from day one due to the lack of choice about where to put the braces.... i'm in the minority wanting symmetry, i know that but honestly, it's more readable like this for me
p
have you tried defining lambdas like this though?
j
i tend to write them inline
filter { it.isInline }
p
many lambdas wont fit in one line
j
but multiline i did notice IDEA was getting frustrated with me when i tried to next line the opening brace
p
idk.. just wondering if it's even feasible to do it
j
see in CF i would do
Copy code
list.map((x, y) => 
{
    x + y
})
p
i know but lambdas in kotlin are fully enclosed in
{
}
thats why i dont think you can put the opening on a sperate line
but feel free to try, it might be fine
j
like i said, IntelliJ IDEA doesn't like it... seemed to get caught in a loop of recommending lambdas then not recognising what i was doing... can't say for actual compilation, the red underlines were enough to discourage me
d
I vaguely recall there’s a case where the language grammar doesn’t work the same if you put the opening brace on the following line. Looks like at least one case happens with
return
âž• 1
j
yeah i wouldn't argue with that. don't recall exactly what happened so i'm going not state anything but i don't mind cuddling my braces now and then, if it means i can leverage the awesome power of kt