4 ms·
Mutable hashmap/associative array/whatever literals like: var map = {"a": 6, "b": 12} [Whatever list type is most common/idiomatic in Kotlin] literals lik
by shallot_router 9y ago
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.
- itp 9y agoWhile 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.
- shallot_router 9y agoI like that a lot, but the `to` syntax bugs me. Why not a colon, or Scala's `->`?
- ssijak 9y agoYou type "->" faster and easier then "to"?
- shallot_router 9y agoNo, 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.
- mike_hearn 9y agoBecause "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.
- shallot_router 9y ago`->` 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.