June 2025
Intermediate to advanced
152 pages
3h 15m
English
| Practice 26 | Dangle That Comma |
Talking about lists of things, here’s a tip that can lead to some pretty serious arguments.
When you write a list of things, you separate each element with a delimiter character (often a comma):
| | [ 1, 2, 3 ] |
Some languages (C, C#, C++, JavaScript, Python, and Ruby, to name a few) allow a delimiter after the last element of a list:
| | [ 1, 2, 3, ] # still just three elements |
Why does that little comma help make code easy to change? Let’s imagine a list of the five largest lakes, ordered by size, starting with the largest:
| | BIG_LAKES = [ |
| | "Caspian", |
| | "Superior", |
| | "Victoria", |
| | "Huron", |
| | "Michigan" |
| | ] |
The customer changes their mind and wants the list in alphabetic order. No problem—you use your editor’s ...
Read now
Unlock full access