Closed iskeld closed 7 years ago
Great question!
No. 3 seems to be the preferred style (i.e., brackets on the same line as the first and last list items). Just look at any mix.exs
file in the official repos.
I'd be interested in seeing counter-examples. I also didn't search for instances where a binding is involved (as in your examples).
@iskeld Does #146 solve this issue for you?
The generator in mix new
uses 1. The reason the official repos use 3. is because they haven't been changed and also because it's not an important change.
Thanks for the note @ericmj. Here's the example of style 1 in mix new
for those who hadn't seen it. Will this go out in 1.5?
I've been getting some good feedback on this issue. Basically, you should use either style 1 or 3 for assignment. If it's not an assignment, 1 and 2 are indistinguishable.
The takeaway is to be consistent about the brackets: if you open a list with [
on its own line, you must close with ]
on its own line. You should also put the square brackets on their own line if you have a long list and, especially, if each element is on its own line.
Thank you @christopheradams - you're doing a great job! :) I'll stick with 1 then, since it has also an extra benefit (comparing to 3) on lesser changes while adding new items (from version control point of view).
@iskeld What do you think of this?
When assigning a list that spans multiple lines, start the list on a newline, with proper indentation.
# not preferred - no indentation
list = [:first_item, :second_item, :next_item,
:last_item]
# better, but not preferred - with indentation
list = [:first_item, :second_item, :next_item,
:last_item]
# preferred - list starts on its own line
# good for shorter, more compact lists
list =
[:first_item, :second_item, :next_item,
:last_item]
# also preferred - when each element is on its own line
# good for long lists, lists with long elements, or lists with comments
list = [
:first_item,
:second_item,
:next_item,
# comment
:many_items,
:last_item
]
Ok, something like this for mutli-line lists is merged in now. Thanks for the feedback!
What is the preferred way of placing brackets for the lists which span multiple lines: 1.
2.
3.