DEV Community

Discussion on: Elm: the jerk that took away my for-loops.

Collapse
 
drbearhands profile image
DrBearhands

At the risk of earning myself a major woosh:

JS is a language of actions. It does things: "allocating" a variable and changing its value are the building blocks of a for loop.

Elm is a language of definitions. One list (of html elements) is a transformation of another list (in this case the function was constructed using map).

The compiler turns Elm's declarations into commands that can actually be executed.

So JS's map function is not the same as Elm's map function. It is just a more specific form of a for loop with some restrictions.

Collapse
 
ryan-haskell profile image
Ryan Haskell

That's a really interesting perspective, thanks for sharing it!

I never thought about it that way 😀

Collapse
 
drbearhands profile image
DrBearhands

If you want to understand more about it, Bartosz Milewski has a great series about the underlying theory. First two chapters should give you a pretty good idea of what's going on.

Collapse
 
1hko profile image
1hko • Edited

I disagree with this. JS is a multi-paradigm language where multiple disciplines can be used. JavaScript includes first-class functions, destructuring assignment, and other features which enable great support for functional style. You can avoid many object-oriented or imperative-style features of the language and skip all the headaches that come with them.

Collapse
 
drbearhands profile image
DrBearhands

I never said anything about functional style so I'm not sure what you're trying to disagree with here...

Thread Thread
 
1hko profile image
1hko

JS is a language of actions. It does things: "allocating" a variable and changing its value are the building blocks of a for loop.

I politely disagree with your summary of what JS is, that's all.

Thread Thread
 
ryan-haskell profile image
Ryan Haskell

Oh sorry, that wasn't my quote 😅

Thought this was a direct reply to my article haha

Thread Thread
 
drbearhands profile image
DrBearhands

"Functional style", ill-defined as it is, does not equate to not having effects / actions.

Collapse
 
ryan-haskell profile image
Ryan Haskell

I totally agree with you!

The point of the post was not to say "JavaScript doesn't support functional programming"

It was just about my experience with a language that only supported functional things.

When I first got started with JS, I naturally used for loops because of my background with Java and imperative languages.

Elm forced me to try something different, and now that's the style I prefer using in JS too 😃

Thanks for your reply, sorry about causing the confusion!