I have the opposite opinion here. Commas should be like semi-colons: only required if you want multiple statements on a line.
Eg
fruit = [
“apples”
“oranges”
“bananas”
]
No commas yet still extremely explicitI have the opposite opinion here. Commas should be like semi-colons: only required if you want multiple statements on a line.
Eg
fruit = [
“apples”
“oranges”
“bananas”
]
No commas yet still extremely explicitCommas as separator is pretty much orthogonal, and… well, better overall.
In Murex (my own language) both commas and semi-colons can be dropped if the statement or expression is terminated by a line feed.
list = %[
chair
table
“bed-side table”
]
YAML, for all of its warts, also behaves similarly too.It’s a much better way to handle lists and objects because the comma only exists for the same reason the semi-colon does in C-like syntax: as a parser hint. But if you’ve got a new line then that hint is completely redundant.
list = %[
chair, table
]
And this? list = %[
chair, table,
] » %[ chair, table ]
[
"chair",
"table"
]
» %[ chair, table, ]
[
"chair",
"table"
]
Here you can see that internally it understands you're writing a JSON object however it relaxes the semantics a little (without going full on YAML) because chasing that erroneous comma is probably the least fun part of programming.Yeah, I did say "several" not "all".
There is very little benefit in new languages making terminator tokens necessary when followed by LF. We are long past the point of needing to optimise language syntax for parser efficiency.
However having a comma terminator when followed by a LF doesn’t. The whitespace is larger and more visible than the comma. In that scenario the comma doesn’t add enough visual distinction to add value to the syntax.
1fruit = ["apples","oranges","bananas"]
2fruit = [apples oranges bananas]
was only talking about commas being required like semicolons since multiple statements use space within, so need something else unlike lists, so it's not comparableotherwise you need parenthesis around expressions with operators: [1 (2 + 3) 4]
unary operators don't create a need for commas, nor the f(x) function call syntax with a single parameter: [1 f(x) ~2 ~f(x)]
now, mild redundancy in syntax is a good thing. it enables detecting whether some code is mistaken (perhaps because a botched copy and paste, for example), giving syntax errors
[1 2+3 4]
doesn't need a comma, and the rule "if you value space in values, quote/bracket those" is a fine simple ruleRedundancy is also a bad thing, it's a tradeoff, so the proper approach is to allow enabling it for those and in those case when the value of the good part is higher
I’m not someone that subscribes to the notion that saving keystrokes increases productivity (eg function key words being “fn”). I only think it’s worthwhile removing tokens if they add to the cognitive overhead. In the case of trailing semicolons and commas, it’s something you need to remember to add. So why not make it optional?
However using whitespace as a delimiter and having expressions require zero spaces between tokens is adding to a developer’s cognitive overhead. As well as inviting hard to find bugs.
Expressions don't require zero spaces, use (), this was just an illustration that there is no need for a comma.
That’s exactly why I’m advocating that trailing commas should be optional ;)
> Expressions don't require zero spaces, use (), this was just an illustration that there is no need for a comma.
You’re example specifically stated using zero spaces for expressions though. So that’s what I’m replying to.
I have no issues with parentheses being used to denote an expression. In fact that largely mirrors how my own language works.