3 ms·
> It’s 2024, so RCL has some features that you might expect from a “modern” language: trailing commas I have the opposite opinion here. Commas should be like s
by hnlmorg 3y ago
> It’s 2024, so RCL has some features that you might expect from a “modern” language: trailing commas
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 explicit
- mcphage 3y agoThat’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.
- eviks 3y agoWhy do you need a comma on a single line in 2024, you already have 2+1 extra symbols/value to separate: quotes and space
- hnlmorg 3y agoWell in my own language commas are entirely optional. They actually only exist for JSON compatibility (ie pasting JSON blobs into the language rather than transcribing the data). But I will concede that having a comma separated list on a single line does at least improve readability for some people. In that particular scenario we are drifting into the laws of diminishing returns and thus things become a lot more subjective. 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.
- eviks 3y agoI don't mind some people thinking 1 is more readable than 2 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 comparable
- nextaccountic 3y agocommas are only really required if there are binary operators: [1, 2 + 3, 4] otherwise 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
- eviks 3y agoit's needed if you use space within, otherwise [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 rule Redundancy 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