Skip to content

Optional commas for objects and arrays #23

Closed
@am

Description

@am

We are through a debate about the optional commas when defining an array or object, see the examples in the coffeecript docs:

song = ["do", "re", "mi", "fa", "so"]

singers = {Jagger: "Rock", Elvis: "Roll"}

bitlist = [
  1, 0, 1
  0, 0, 1
  1, 1, 0
]

kids =
  brother:
    name: "Max"
    age:  11
  sister:
    name: "Ida"
    age:  9

The documentation explicitly says the commas are optional, and here resides our doubt. We would like to hear some community opinions, is there any rules, thumbs up that you apply to your code? Should this be added to the style-guide in some way?

Regarding the code we can see from coffeescript whenever there is a new line the comma is omitted.

Here we have both opinions:

  1. When each property is listed on its own line there is no need for commas as the indentation provide enough readability.
  2. The commas are an enforcement to understand the continuation, even when there is a new line. Besides commas are not optional in ruby or python, since coffeescript is heavily based on those it makes sense to maintain this as a style "rule".

We would love to know your opinion regarding this.
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions