https://kotlinlang.org logo
x

xenoterracide

12/27/2018, 7:23 PM
suggestion: allow trailing commas to be optional (same way ; can be noise punctuation), the following code should compile, and behave the same way as if the last comma were not present
Copy code
val modules = listOf(
    "ph-db-migration",
    "ph-emr-entity",
    "ph-emr-event-type",
    "ph-events",
    "redox",
)
you probably wouldn’t write this like this, but it makes the last comma more obvious
Copy code
val modules = listOf( "ph-db-migration", "ph-emr-entity", "ph-emr-event-type", "ph-events", "redox",)
would compile to the same thing as
Copy code
val modules = listOf( "ph-db-migration", "ph-emr-entity", "ph-emr-event-type", "ph-events", "redox")
👍 7
2
💯 2
k

karelpeeters

12/27/2018, 7:24 PM
Yes!
o

orangy

12/27/2018, 7:49 PM
How do you distinguish
a b c
between a list of 3 elements and a list of 1 element where
b
is infix function?
k

karelpeeters

12/27/2018, 7:50 PM
I think you misunderstood, this is specifically about making trailing commas optional instead of disallowed, not making all commas entirely optional like
;
.
👍 2
x

xenoterracide

12/27/2018, 7:53 PM
if you wanted the former, I might suggest perls’s “quote word” e.g.
qw( a ) b
, but yeah this is about trailing comma’s not lists of auto quoted words, symbols or other functions
updated the OP, to reflect that I’m talking about the last comma before the parens
r

Ruckus

12/27/2018, 8:05 PM
@orangy I believe he only meant adding a comma after
"redox"
should be allowed, not making all commas optional.
👍 1
x

xenoterracide

12/27/2018, 8:05 PM
updated
o

orangy

12/27/2018, 8:18 PM
Thanks, indeed I misunderstood. This is on the radar
x

xenoterracide

12/27/2018, 8:57 PM
@orangy so you’re saying this is already in the backlog to be added somewhere? maybe v1.4?
o

orangy

12/27/2018, 8:58 PM
No promises, as usual. You can track it here https://youtrack.jetbrains.com/issue/KT-9476
👍 2
youtrack 1
p

poohbar

01/03/2019, 1:43 AM
I don't like that it's optional. It's just another thing to argue about when deciding on project conventions. I personally would not allow trailing commas in my projects and the compiler would no longer enforce it for me. Modern IDEs have no problem moving statements or parameters around and will handle the trailing commas automatically. This is a resounding 👎 from me.
x

xenoterracide

01/03/2019, 11:37 PM
@poohbar guess I need you to teach me how to use my IDE. I'm the opposite I would require a trailing comma on any vertically aligned "list", especially since when you changed the code you'd no longer get a 2 line difference in your diff, only the one you actually changed. To me the benefits would outweigh any concern over an extra character.
p

poohbar

01/03/2019, 11:45 PM
I guess I do. The action is called "Moved Element Right" (or Left) in IntelliJ and works flawlessly. Sure the diff will show the difference on 2 lines but that's more about the diff renderer. It can ignore that line if needed. Just like it can ignore whitespace etc. To me the benefits are minuscule and it just needlessly complicates the grammar.
k

karelpeeters

01/03/2019, 11:49 PM
It really annoys me that I have to deal with trailing
,
whenever I comment out a line in a multiline call, eg
Copy code
val x = listsOf(
    4654231,
    7898798,
    //1349846   -- oops, now there's a trailing comma!
)
I'd like the compiler to just carry on. The problem of conventions can then be solved like eg. spacing,
Ctrl+Alt+L
fixes it.
👍 1
p

poohbar

01/03/2019, 11:52 PM
Trailing commas are so ugly. 😕
4 Views