224 points · by bpierre · 9y ago · 84 comments
Elm made me enjoy frontend development again. Can't recommend it enough.
"All content created with Ellie is released in the public domain (CC0)."
Are they claiming that any program written with Ellie is in the public domain?
(edit) I've emailed to ask their intent. I'll post an update if I get a reply.
I let him know that those terms would make me very reluctant to use Ellie for anything, even open source code, since the ability to apply an open source license requires that I have a copyright. I suggested that they putting a very visible statement of what they're doing on the page.
But I found the documentation to be of a really low quality, and I believe good docs are the most important thing for any language aiming for developers' adoption.
At least the docs on elm-lang.org weren't any good - maybe there's some alternative projects out there?
let rant_ = [
I just wanted to have a thin non-breakable space (U+202F) and haven't found anything about actual syntax in the "syntax" document, nor anywhere around that. Syntax docs is just a bunch of examples with a short notes - a quick cheatsheet at best.
Then I wanted to browse Html package contents and see what's the difference between beginnerProgram and program and what else do they have in stock (with Haskell I always had good idea of module's contents by reading docs on Hackage), but the docstrings were nearly meaningless, not even listing the arguments. "Read about The Elm Architecture", really? I just came from that document (and they only cover beginnerProgram basics), hoping a module docs would give me better idea.
] in sorryAbout rant_ -- I had eventually figured it all out, but was quite disappointed.
Spacemacs + elm layer + elm-hot-reload. If you have two screens (or enough resolution) you can have something similar to this app with all the power of a great editor. (Sure it could be emacs + evil or Vi(m) instead)
Format seems to be in Alpha, doesn't limit line length?
It's tricky with Elm because it's written in Haskell, so compilation etc. takes long time in the browser, but this is quite nice. Should definitely push to replace /try with this.
im a huge fan of the Elm broswer. and have been using Elm with atom along with elm reactor. That has worked adequately. Most difficulties are ironed out by making sure the Elm code compiles. Then at least all the parts are fitting together.
But maybe I have written code that compiles, but doesn't express what I am wanting.
It's a bit much in the morning.
.components_header_Header {
background-color: #000080;
}It's a shame that all that hits me in the face with Elm code examples lately is awkward style conventions. Why do they have to be so user hostile?
Trailing brace on the next line even for this?
type alias Model =
{ counter : Int
}
Instead of: type alias Model = { counter: Int }
Comma first, when trailing comma is so much more intuitive, why this? Html.program
{ view = view
, update = update
, subscriptions = \_ -> Sub.none
, init = ( model, Cmd.none )
}
instead of: Html.program {
view = view,
update = update,
subscriptions = \_ -> Sub.none,
init = ( model, Cmd.none ),
}
(... which makes for better diffs too). And weird bracket soup for DOM: div []
[ div [] [ button [ onClick Increment ] [ text "+" ] ]
, div [] [ text <| toString model.counter ]
, div [] [ button [ onClick Decrement ] [ text "-" ] ]
]
... when it's going to be translated to DOM anyway, why not? <div>
<div><button onClick={increment}>+</button></div>
<div>{toString model.counter}</div>
<div><button onClick={decrement}>-</button></div>
</div>
This is needlessly distracting from all the things that are nice about Elm.The HTML functions in Elm tend to take two parameters: a list of attribute values and a list of child DOM nodes. Again, this is all code. The list values you specify are again just functions that get evaluated.
It's a little less obvious because of the syntax style of Elm, but it does let you write the function calls out in such a way that they express that tree structure.
It bears repeating: your Elm div example, at the top level, is a single function call with the first parameter '[]' being an empty list (because you aren't assigning the node any attributes like a DOM id or CSS class) and the second parameter being a list that'll be made up of the DOM nodes that result from each of the function calls within it.
This was one of the biggest mental roadblocks I had to get past when learning Elm. Just forget the idea of HTML and think instead of DOM tree-of-nodes and a lot falls into place. The 'view' function you write will return a DOM tree data structure which is then taken and applied to the browser document. You pass in your model as a parameter to that function and then other functions you call within this DOM-generating code you've written will use that data to return different DOM contents depending on it.
That is why I used JSX as a counterexample. Basically I'm questioning Elm's choice to stick with the raw dom-creation-function-style vs adopting a JSX equivalent.
Elm is a functional language, and you build the desired DOM structure with functions. Why should it be any other way?
JSx looks sort of like HTML, but HTML isn't even the target here, just DOM nodes.
Html.program {
view = view,
update = update,
subscriptions = \_ -> Sub.none,
init = ( model, Cmd.none ),
}
Because the parse would expect something to come after that last comma. And thus you would have the last line being special and different.Also, it is much easier to look at this
Html.program
{ view = view
, update = update
, subscriptions = \_ -> Sub.none
, init = ( model, Cmd.none )
}
And see if all of the commas are actually present ;)> Also, it is much easier to look at this [...] and see if all the commas are actually present.
ESLint can trivially lint that you haven't missed a comma (including the final trailing comma). The style guide/ESLint config I use (Airbnb's) enforces trailing commas. If ESLint can do it, Elm should be able to.
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Well, Elm is not trying to be JS, it's trying to be better, and there's really no reason to need trailing commas. I'd even argue that it argue it leaves a message of mixed intent "did the author want to continue the list?" and needlessly enables duplicate styles for the same one thing.
Which languages are you referring to? Almost every language I'm aware of allows trailing commas.
C, C++, Java, Python, C#, Javascript (somewhat), Ruby, Objective-C, Perl, PHP, Elixir, Rust, and Go all allow trailing commas.
Except you've now traded the last line being special for the first line being special.
The main difference is that the Elm "bracket soup" is just a composition of functions and is subject to some type checking by the compiler. Elm view code as such can easily be restructured and refactored using the simple laws of function composition, which are very powerful, especially in combination with a strict type system.
Also there are some things about Elm's DOM style in particular that are especially awkward, compared to other function-style dom creation syntax [0], like the [ ] everywhere.
> The main difference is that the Elm "bracket soup" is just a composition of functions
So is the JSX counterexample I gave, (it de-sugars to function calls), which is why elmx [1] can exist, and seems like an improvement to me.
[0] https://github.com/hyperhype/hyperscript [1] https://github.com/pzavolinsky/elmx
The result won't be understood by elm-format. Compiler errors will exist at the level of Elm, not elmx. It's something extra that has to be learned by any other developer trying to work on the code -- and they'll still have to understand the pure Elm code that the elmx compiles to as well. Plus it has limitations like not being able to nest code interpolations.
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...
>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.
Regarding HTML, you may want to look at elmx [0]. It accomplishes exactly what you described.
In a similar vein...
https://marketplace.visualstudio.com/items?itemName=Rubymani...
Really I think it's just the stage of adoption that the language is in. It really is cutting-edge in that way and everyone is figuring out the best way to do things. It's early, early days.
In my current project, I've used templating to solve this. I ended up with a huge Elm main program that was 90% case-statements to call the appropriate update, view or other functions (eg- passing JSON data from the back-end server to the appropriate places). I got cranky enough with it that I made a templates version of it using the doT.js library and a script.
Now I can specify the subscreens I want in my application in a JSON file and have a script take that and my Elm code template and spit out a perfectly readable main.elm file which then gets compiled as normal. It's actually turned out really well for my purposes.
I am sure one gets used to it after some time, but prepending lines with comma, just because it makes it easier to add new lines is so so ugly and takes away from the main intent for newcomers.
This is akin to starting each sentence in English with a dot!
Else every language would be annoying to write, especially a lisp.
People can live with different tab lengths. I'm not so sure every project needs to be bike-shedding about it, though.
Indents let the reader know the current line is a continuation.
Comma-first also creates worse diffs than (enforced) trailing comma.