4 ms·
val list = listOf("Saab", "Volvo") val map = mapOf("firstName" to "John", "lastName" to "Doe") The above seems a really strange decision for a "new" language
by hoodoof 8y ago
val list = listOf("Saab", "Volvo")
val map = mapOf("firstName" to "John", "lastName" to "Doe")
The above seems a really strange decision for a "new" language - why would you not just use the most common structure, being JSON?
- cytzol 8y agoJSON doesn’t support non-String keys, for one thing.
- singularity2001 8y agoJS does
- jscissr 8y agoActually no, all keys are strings in JS, and if you use something that isn't a string as a key, it is converted to a string (unless you meant Maps[1], which don't use object notation). [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/docs/Web/JavaScript/Reference/...
- jscissr 8y agoOk, I forgot Symbol, so you were correct.
- singularity2001 8y agoEvidence that designers of Kotlin have no taste
- kllrnohj 8y agoPerhaps worth noting that none of that is langauge syntax, it's library syntax. mapOf takes vararg pairs: Pair<K, V>, and then the 'to' operator is an infix function that makes a Pair<K,V>. So you could trivially do your own listOf or mapOf that creates whatever data structure you want, whereas languages with special syntax for this tend to hardcode the result of it. That's a valid choice, sure, but just that there are tradeoffs here rather than it being obviously better one way or the other.
- singularity2001 8y agohow can a newly designed language not make lists and maps first class citizens?
- kllrnohj 8y agoSo that you can use any map or list implementation without them being second-class citizens, that's why.
- DeonPenny 8y agoBecause it allowed them to use basic understandable functions rather than writing special use cases. listof and mapOf are just functions and to is just a infix function that makes a pair out of two elements. It makes far more sense for someone making a language.
- bobbyi_settv 8y agoOne of my biggest annoyances in Scala is not having literal syntax for sequences and maps. The language seemingly tries to have every syntax convenience that's ever existed in every language, even when they conflict with each other and cause confusion, and then misses the most basic one. I've been told that it's because "how would it know which specific sequence and map class you want", but it already has Seq() and Map() which give you the default immutable sequence and map classes, so obviously a literal syntax would give you the same one.