Hacker News new | past | comments | ask | show | jobs | submit login

What kind of sugar are you looking for? I'd like to have first-class comprehensions in any language I use, but having decent map/filter/reduce|fold implementations is good enough for the most part.

(1..100).map({ it + 10 })

Doesn't seem so bad.




Mutable hashmap/associative array/whatever literals like:

    var map = {"a": 6, "b": 12}
[Whatever list type is most common/idiomatic in Kotlin] literals like:

    var list = [1, 2, 3]
etc.

Plus list/map comprehensions like Python or Haskell, as you mentioned.

Not a big deal or anything. It's only a little bit of extra typing. And the syntax sugar they do add is definitely a massive step-up over Java.

I know it'd be hard to add the map literal syntax since it would clash with Java's normal array literal syntax. And I also realize that Java has a wide variety of container types for a reason, and Kotlin wants to be a subset of and not replacement for Java, so doing this may not make a lot of sense.

I guess on reflection, my complaints aren't really valid given that context. I've just had it ingrained in me to use special characters for basic container types, since Python and JavaScript were my first languages for many years.


While somewhat longer, you do have

    var map = hashMapOf("a" to 6, "b" to 12)
    var list = listOf(1, 2, 3)
This is still not Java-level verbosity.


I like that a lot, but the `to` syntax bugs me. Why not a colon, or Scala's `->`?


You type "->" faster and easier then "to"?


No, but it's visually clearer to me at a glance. It feels weird using letters, let alone full English words, to describe a mapping or anything else that I think a symbol is more suited for.

To me it would feel like assigning a variable with:

   a equals 6
   n equals "A"
Just feels icky, somehow.

Again, that wouldn't dissuade me from using the language whatsoever. It's only a minor irritation.


Because "to" isn't actually syntax at all. It's an infix function that creates a Pair. You can alt-click it in the IDE to go to the definition.


`->` in Scala is also just a method, but I think it's fair to call such things syntax even if they're not true "baked-in" language syntax.


You can even get rid of the final parentheses.

(1..100).map { it + 10 }


Somehow that seems even less readable to me.


This is simply "parentheses in a call can be omitted entirely if the lambda is the only argument to that call." This one feature allows for type safe DSL's which eases GUI construction on Android and other domains. https://github.com/Kotlin/anko/wiki/Anko-Layouts

Its also used for chaining stream code which takes in functions. You get used to this feature very quickly.


I know what it is, I'm just saying that in a Java-esque language, omitting parens for function application feels worse than doing so in eg Haskell or even Ruby.


Swift also supports trailing closures. It's a concept that's become pretty familiar of late.


Never wrote any Groovy? Java developers had no problem picking this style up a decade ago.


Nope, never. Just coming back to the JVM ecosystem, actually, as I've been away since around the Java 7 release time (with the exception of some Jython work).


I think you'll be pleasantly surprised how the ecosystem has changed. Legacy code is legacy code, but Java 8 changed a lot and people have mostly also adapted well to ideas coming out of the Scala / Groovy / Kotlin ecosystems primarily because there is just more of it and it's fairly familiar and common to run across libs and projects written those languages now if you're working in Java.


It's actually "if the lambda is the last argument in the call you can close the parens after the penultimate argument".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: