There are reasons for all these, the first two are both to optimize for VCS changes, since adding something to your first to examples would now only generate a minimum diff[0]. That, and considering Elms roots in Haskell, this is the common style for things there.
The last one is because all html in Elm are just regular Elm functions. This means no special syntax to manipulate html, and you have the power of all of Elm at your fingertips, without shoehorning it into a new syntax. [1]
What if you want to change the first item of a list? If you're going for smallest diff (which I'm not even convinced is a worthwhile consideration in language design), then allover's example is clearly superior to Elm's current convention.
The comma first is not with language design, it's a convention from FP langs (at least Haskell).
>What if you want to change the first item of a list?
Html.program
{ view = view
, update = update
}
to
Html.program
{ view = newView
, update = update
}
Leading comma vs allow a non-terminating comma both leads to the same diff of just the one line.
I mean, there are quite a bunch of languages that don't support non-terminating commas, which is really a bit of parsing that hides intent.
Other than that, bashing a language for having the convention (that is not forced by the language but by... convention) is quite ridiculous. The HTML comment is a valid point to raise, but there is quite a good reason for having it be native Elm, which brings a ton more benefits than having JSX'esgue syntax.
I meant what if you wanted to add a new item to the front of a list or change the order of items in the list.
[ 1
, 2
, 3
]
to
[ 0
, 1
, 2
, 3
]
diff
- [ 1
+ [ 0
+ , 1
, 2
, 3
]
> Other than that, bashing a language for having the convention (that is not forced by the language but by... convention) is quite ridiculous.
It is forced slightly by the language as trailing commas are currently invalid syntax (though this is on the roadmap to be fixed). It's also more than just a convention, as it is explicitly recommended in the official Elm docs.
The last one is because all html in Elm are just regular Elm functions. This means no special syntax to manipulate html, and you have the power of all of Elm at your fingertips, without shoehorning it into a new syntax. [1]
Honestly some quite silly arguments...
[0] You can read some of the benefits on the style here https://github.com/avh4/elm-format/blob/master/README.md
[1] Explained a bit down the page https://guide.elm-lang.org/architecture/user_input/buttons.h...