3 ms·
commas 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] u
by nextaccountic 3y ago
commas 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.