3 ms·
Why do you need a comma on a single line in 2024, you already have 2+1 extra symbols/value to separate: quotes and space
by eviks 3y ago
Why 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
- hnlmorg 3y agoThat example syntax has so many potential footguns though. 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.
- eviks 3y agoIn the case of non-trailing commas it's exactly the same - something you need to remember to add. And remember to (re)move when you move arguments around, that's also buggy cognitive overhead. Expressions don't require zero spaces, use (), this was just an illustration that there is no need for a comma.
- hnlmorg 3y ago> In the case of non-trailing commas it's exactly the same - something you need to remember to add. And remember to (re)move when you move arguments around, that's also buggy cognitive overhead. 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.