3 ms·
Do you have a good reason for enforcing trailing commas vs leading?
by klysm 4y ago
Do you have a good reason for enforcing trailing commas vs leading?
- masklinn 4y agoLeading is necessary to minimize diffs when you don't support trailing commas: Prelude> [1,] <interactive>:4:4: error: parse error on input ‘]’ Prelude> [1] [1] This means if you go multiline in the "usual" style: [ 1, 2, 3 ] any time you need to append a new item, you need to modify the existing last line as well: [ 1, 2, - 3 + 3, + 4 ] Meanwhile: [ 1 , 2 , 3 +, 4 ] If you support trailing commas, you can just use one on the last line for the same effect: [ 1, 2, 3, + 4, ] Incidentally, some crazy people put the closing symbol on the last line: [ 1 , 2 , 3 ] That completely defeats the point: [ 1 , 2 -, 3 ] +, 3 +, 4 ]
- asplake 4y agoDo many/most feel this way? I always felt this argument was the diff tail wagging the code readability dog, so to speak
- davidjfelix 4y agoI did prefix my opinion with "IMHO". But no. Leading commas are, in my opinion, less common in life and a distracting, surprising style for the sake of fixing a syntactic language mistake. "Enforce" might have been an overly demanding word. Enforcing when there's a newline is probably more apt or simply allowing it to prevent giving leading comma folks ammunition. something like `[hello, world]` should probably be allowed since `[hello, world,]` feels extraneous.