3 ms·
Likely because it's inconsistent with all other parts of the language where trailing commas are not allowed
by dtech 3y ago
Likely because it's inconsistent with all other parts of the language where trailing commas are not allowed
- e3bc54b2 3y agohey now, Enum allows trailing comma before semicolon, and ever since discovering that, I've been putting extra comma at the end of last Enum value and semicolon on new line. Why? Because whenever there's a new value added, git diff shows single line change :)
- nayuki 3y agoIndeed. Whereas JavaScript and Python even allow a trailing comma in function parameters: function foo(x,) {} def foo(x,): pass Before anyone questions why anyone would do this, it's for putting arguments (or array elements) on separate lines: function foo( a, b, c, ) {}
- CobrastanJorji 3y agoAlthough be careful with that in Python because there are other situations where (x) and (x,) are both legal but mean very different things.
- devonkim 3y agoIn Python the comma acts as a tuple creation operator inside parentheses with no other context like function invocation. Also, last I remember in JS a trailing comma meant the creation of an extra array element that’s null so I became conditioned to only use trailing commas for separators in languages where it’s consistent and specified very explicitly like in HCL
- n2d4 3y agoTrailing commas in JS don't do that, but having more commas than values does. (eg. [1,,].length === 2)
- nayuki 3y agoTuple creation and destructuring does not require parentheses in Python. w = 0, # w == (0,) (x) = (0,) # x == (0,) y, = 0, # y == 0 (z,) = (0,) # z == 0 Though in Rust, parentheses are required for tuple creation and destructuring.