Skip to content

Instantly share code, notes, and snippets.

@KyLeggiero
Last active May 13, 2018 19:24
Show Gist options
  • Save KyLeggiero/1582a959592cadcfee2a0beba3820084 to your computer and use it in GitHub Desktop.
Save KyLeggiero/1582a959592cadcfee2a0beba3820084 to your computer and use it in GitHub Desktop.
Proposal: Kotlin collection literals
@KyLeggiero
Copy link
Author

@ssadedin I agree with you. Kotlin, among many other things, aims to be easy to learn for those who already know another programming language. It would be silly for us to use a brand new syntax for something so commonplace. That's why I chose the same syntax used in Groovy and Swift, which only barely differs from that used in Python and JS (square vs curly braces).

@alanfo
Copy link

alanfo commented May 8, 2018

@BenLeggiero I agree with you that ':' seems on the face of it better than '='.

However, there was a development recently in another long running debate - whether to include the conditional (ternary) operator in Kotlin.

I've always been against this, partly because it's unnecessary when we already have the if/else expression, but mainly because '?' signifies something to do with nullability in Kotlin.

I thought that the latter would be the critical point but it turns out that the ':' is the problem! This is because the Kotlin team want to reserve its use for something else such as slices. So, if you do propose it for 'map' literals, you might run up against the same objection.

@KyLeggiero
Copy link
Author

Thank you for the insight, @alanfo! That's very useful :)

@KyLeggiero
Copy link
Author

KyLeggiero commented May 11, 2018

I've released the first draft of the collection literals KEEP proposal. You can view it on my GitHub here:
https://github.com/BenLeggiero/KEEP/blob/collection-literals/proposals/collection-literals.md

I have started going over it and refining it to become a final draft before submitting a pull request. Any comments about it here would be greatly appreciated!

@KyLeggiero
Copy link
Author

KyLeggiero commented May 13, 2018

This is now in a KEEP proposal: Kotlin/KEEP#112
Please place further discussion there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment