3 ms·
That’s not really the opposite opinion… the opposite is not allowing trailing commas (like JSON) so if you remove the last item from a list, you need to adjust
by mcphage 3y ago
That’s not really the opposite opinion… the opposite is not allowing trailing commas (like JSON) so if you remove the last item from a list, you need to adjust the line above as well. And when you add something to a list, you need to know if something will come after it, even though you don’t necessarily know.
Commas as separator is pretty much orthogonal, and… well, better overall.
- hnlmorg 3y agoI got what they were saying. My point is that if you have a line feed then a comma is an entirely redundant piece of syntax. Commas should only be needed if you are placing multiple statements on a single line. Just like how several programming languages treat semi-colons (eg Go, bash, JavaScript, etc). So mandating them is the opposite of that modern languages should be insisting upon. 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.
- OJFord 3y agoIt's only redundant in languages that make it redundant, like you mentioned C at the end - it's the new line that's redundant there (or only for readability), it's the semicolon with the 'end' semantics.
- unilynx 3y agoIn this specific case it's not redundant in C - without the commas, the strings would be merged together.
- OJFord 3y agoExactly, that's what I said? 'In this specific case' though? It would be news to me (not that I've used it since university!) that they're ever non-semantic?
- hnlmorg 3y ago> It's only redundant in languages that make it redundant 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.
- teo_zero 3y agoWould your language also accept this? list = %[ chair, table ] And this? list = %[ chair, table, ]
- hnlmorg 3y agoYes it would: » %[ 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.
- teo_zero 3y agoSo, accepting the spurious comma at the end of the list and not requiring commas when there's a newline can coexist. I would say they are tho orthogonal properties. You can support the latter without opposing the former.
- D-Coder 3y agoClearly, whether the language considers commas necessary or optional should be in a config file.
- hnlmorg 3y agoSure, but that’s not what the linked article discusses. It specifically states that commas are mandatory on each line. Not that the rule for commas is relaxed. And what I’m arguing is that requiring commas on each line is pushing the syntax in the wrong direction.