r/elm • • Jul 11 '21

Elm should be the first programming language taught at universities and colleges.

8 Upvotes

47 comments sorted by

13

u/mrunkreativ98 Jul 11 '21

Ok. Why?

5

u/Voxelman Jul 11 '21

In my opinion Elm teaches good programming practice and it does not allow bad practice (like null reference, mutability, side effects...). The friendly compiler helps you a lot to learn that good programming practice.

Also, many programming languages were developed when CPUs still had one core and the Internet did not yet exist. The requirements have changed. Nevertheless, old techniques and languages are often taught in university courses that are simply no longer up to date.

And even older imperative languages like Java and C# add more and more features from functional programming languages. So you can apply things like list comprehensions or other abstractions to many languages.

You can use this knowledge if you learn other languages like Python or JavaScript to write more robust code, even if they allow "bad code".

I often read that C/C++ developers say they became better C/C++ programmers after learning Rust. I think Elm has the same effect, but is going one step further.

In my opinion you should learn Elm first and then Rust. From there you can learn other languages. The only problem might be that you will hate to learn C++, Java(Script), Python and so on ;-).

6

u/no_spoon Jul 11 '21 edited Jul 11 '21

JavaScript and python are wayyyy more friendly IMO. Compiled languages are nice for avoiding bug introductions, but there is basically only one way to write elm and it does not leave much to the imagination. That would be a huge turnoff if I started with elm and thought that that was programming. With more loose languages like js, php, or python, it allows you to design systems in your head with no opinions. And if you screw up the console will let you know.

3

u/Voxelman Jul 11 '21

Both languages are loosely typed, imperative languages that support null references. Might be easy to learn, but hard to master. Just look at bug reports from JavaScript projects and count the undefined bugs.

With these languages you learn the bad habits of programming.

And I my opinion it doesn't matter if you start learning imperative or functional first. Both look alien if you have no basic programming knowledge. Most people just prefere languages like Python because imperative style is much more common.

I'm currently learning Elm myself. I come from imperative languages like C, Python and Lua. But already I see the benefits and wish I had learned this much earlier. especially the concepts of immutability, pure functions and things like the Maybe type can be useful in imperative languages.

On the other hand imperative style is pretty useless in functional programming languages.

4

u/no_spoon Jul 11 '21

All I can say is that elm is very verbose, and takes longer to accomplish the same things with imperative languages. More secure, but not expedient. Why do you think Redux is no longer the standard in the react community? Because the realization is that while it is basically introducing procedural, it is just such a pain to maintain. And in the real world, that shit matters

4

u/Voxelman Jul 11 '21

The real world is, that code is full of bugs. And these bugs cost real money. Companies don't learn their lessons. They want to release as fast as possible and fix bugs later.

I see this every day in the company I'm working. We are using machines that are running 15 year old horrible Delphi code. The support guys have to fix bugs almost every day. The machines can't produce, the support guys have no time for more important stuff. This costs money, every day, every year, every decade.

If you do it right the first time, the initial costs might be a bit higher, but over the lifetime you will save a lot of time and money.

A lesson I have learned is, that it might take a bit longer to write code in Rust or Elm, especially if you are new, but the phrase "if it compiles, it will run" is almost true for both languages. I didn't touch a debugger for a Rust project. That saves a lot of time.

If you are used to Rust or Elm you are much more productive than in C++, JavaScript or Python because the code just works. No need to find and fix tons of bugs.

2

u/StoneColdJane Jul 12 '21

The exactly 💯 the same experience in Europe with the multiple companies I worked for, some of those multi bilion revenue.

I share the same line of thought about using better languages to counter business philosophy you mention because that will not change, and cannot change.

2

u/[deleted] Jul 11 '21

All I can say is that elm is very verbose, and takes longer to accomplish the same things with imperative languages

wtf lmao

1

u/no_spoon Jul 11 '21

Compared to*

1

u/[deleted] Jul 11 '21

No, I got what you meant

1

u/Voxelman Jul 11 '21

It doesn't matter if a language is compiled or interpreted. It is the style you are writing code. Imperative, object oriented or functional, that is important.

If you are totally new to programming, a "more loose" language" will teach you all the bad stuff.

C++ is a relatively loose language, known for "shoot yourself in the foot" and responsible for 70% of all security issues in the Chrome Browser and Windows. I heard from a lot of C++ programmers, that they become better C++ programmers after they learned Rust.

Why not learn the right way first in a strict and limited language and avoid the pitfalls of "loose" languages?

3

u/zsombro Jul 12 '21

Why not learn the right way first in a strict and limited language and avoid the pitfalls of "loose" languages?

I get this sentiment, but to me it sounds like you never really tried teaching people who have never written code before and you overestimate how quickly the average person understands programming concepts.

Since you're already familiar with the topic, a lot of it feels trivial to you, but in my experience, there is nothing intuitive about most of programming to the average layman, so if their introduction already contains very foreign concepts like type correctness, interfaces, etc. it's going to be alienating.

A scripting language is nice, because you can just open an an empty text editor, type in a few simple lines and see results quickly. Also, experiencing those mistakes first hand makes it easier to understand why the more complicated safeguards are helpful.

1

u/Voxelman Jul 12 '21

I'm not really familiar with this topic. I started learning Rust a while ago, but I struggled. My first impression was "why are all variables immutable by default. I have to write 'mut' everywhere".

Then I got the tip to learn Elm. And this confuses me even more the first time. It takes a while to understand the general concept.

I'm still an Elm beginner, but even at this point I wish that I learned this concept earlier.

I have experience in languages like Python, Lua, C, Delphi and even Assemler and some other languages. I'm able to get the code running. But I'm sure that if I had learned FP much earlier, I would have had less pain while writing the code.

A colleague at work did not study but trained as a technician. Computer science was only a minor subject and only OOP and Java was taught. That there is something like functional programming you do not learn there at all. And there is no reason for him to learn languages like Elm because he don't need it at work. "I can't get a job? Why should I learn it?"

I don't agree with the scripting language argument. You can make your first baby steps in Elm with the online playground. Just start with the hello world example and add some output. No need to install anything and get immediate response. You even don't need to know HTML. You can add this step by step.

My point from personal experience is, that it is hard to go from imperative to functional style if you only have imperative or OOP experience.

1

u/Voxelman Jul 12 '21

To make a long story short, I think it is much easier to go from functional style to OO or imperative than vice versa.

1

u/ElectricalUnion Jul 12 '21

In my opinion Elm teaches good programming practice and it does not allow bad practice (like null reference, mutability, side effects...).

Shooting yourself on the foot might not be pretty but has it's educational value.

Also, many programming languages were developed when CPUs still had one core

Elm doesn't use more that one core?

2

u/Voxelman Jul 12 '21

FP in General scales better on multiple cores.

And shooting yourself in the foot is only good if you learn how to do it better. Most times they learn OOP.

9

u/Kurren123 Jul 11 '21

We learnt Haskell as our first language in uni

2

u/Voxelman Jul 11 '21

Do you think that it was good to learn a strongly typed functional programming language first?

8

u/Kurren123 Jul 11 '21

I think the benefit of learning it first is that you don’t need to unlearn a bunch of OOP which can get in the way

1

u/Voxelman Jul 11 '21

What languages are you using now?

4

u/Kurren123 Jul 11 '21

At work it’s elm for front end and C#/F# for backend

5

u/salinasjournal Jul 11 '21

I wish I had learned a functional language first because the different way of thinking necessary to code in this way is useful for other languages. I can see an argument that it is harder to get functional code to work, which may be frustrating for a beginner, but when you do get it to run it is more likely to run without bugs. The discipline of using immutable variables certainly helped me improve my code in other languages by using constants more often.

3

u/Voxelman Jul 11 '21

That's what I mean

7

u/tripack45 Jul 14 '21

Elm as in its current state contains various semantics inconsistencies that makes it not suitable as an exemplary language.

The compiler also makes certain arbitrary restrictions (e.g. at most 3 elements for a tuple, and the removal of support for custom operators) based essentially personal preferences, setting a bad example for students.

The lack of language specification also makes program semantics whatever the compiler do, which is bad because 1) lecture content could be invalidated at any time by a change in compiler behavior 2) no authoritative source for what the language should behave.

2

u/Voxelman Jul 14 '21

Best answer until now. In that case I agree that Elm might not be the best choice. Thanks

10

u/[deleted] Jul 11 '21

Elm is great for what is great for: browser apps. It is not a general purpose language.

PureScript would already be a better fit in that regards.

I don't know if I'd start m off with a typed language. Maybe a lisp with SICP would be my choice. Then a strongly typed language as second.

1

u/Voxelman Jul 11 '21

Maybe you can switch to Haskell after the basic concept is solidified. Or you can even directly start with Haskell, at least at Universities.

I just think Java(Script), C/C++ or Python are not the best choice to begin with.

1

u/[deleted] Jul 12 '21

I agree that the last languages you mention are terrible beginner languages (C being the least bad). That’s the crux for me. As with others here, I think an ideal sequence would start with Scheme. For MLs, I think SML is probably the best teaching language.

2

u/Voxelman Jul 12 '21

I think it depends on the age of the students/children. For university students, Elm is perhaps too much of a toy language.

1

u/[deleted] Jul 11 '21

I just think Java(Script), C/C++ or Python are not the best choice to begin with.

Totally agree. Maybe Python. But otherwise I think we have better to offer for leaning the baiscs.

2

u/deanporterteamusa Jul 12 '21

Came here to say this (more or less). Scheme + SICP.

I am really glad I went through SICP before writing Haskell, Idris, Erlang, Elixir, etc. I don’t know if I would’ve appreciated those languages and/or the functional paradigm if it weren’t for SICP or scheme. I still write scheme these days (write as in write with pencil and paper when I’m working out some recursive function).

0

u/Voxelman Jul 11 '21

Purescript is in my opinion a horrible choice. In that case I would prefer Haskell.

But you don't need a general purpose language to learn programming. Elm would be perfectly fine to learn programming concepts.

2

u/[deleted] Jul 11 '21

So we disagree.

To why not Haskell: to many functions in prelude are not total.

-2

u/Voxelman Jul 11 '21

Well, if I Google for videos about "elm tutorial" I have about 162000 hits, if I do the same for Purescript I just get 7440. Even if I search for "elm language tutorial I have 33600 hits.

Purescript doesn't seem to be very popular and you won't find much learning material.

A reason might be that Elm has batteries included and is much easier to use, but I'm not sure.

2

u/[deleted] Jul 11 '21

My pick was not based on langs popularity.

I know this is basically all fringe langs.

3

u/britishmutt Jul 11 '21

McMaster University uses Elm to teach kids to program: http://outreach.mcmaster.ca/. Start em' young!

2

u/Voxelman Jul 11 '21

I think, porting "the nature of code" to Elm would be a good learning material.

1

u/britishmutt Jul 12 '21

I haven’t read that, but in general it would be good to see more books that use Elm rather than ones that are about Elm.

2

u/deanporterteamusa Jul 12 '21

So… playing devil’s advocate here: could it be that your excitement about Elm is (in part) due to having programmed in a different language before Elm?

Elm solves a particular set of problems, but like other languages it’s no panacea.

After writing C and C++ (novice to intermediate) and then writing a lot of Rust I thought (hoped, really) I’d have no reason to to write C or C++. However, for me, this was just some ignorance on my part. I didn’t have enough real world experience to know about or benefit from the tradeoffs each language (including it’s ecosystem, paradigm, etc.) represents.

I get your enthusiasm though! I feel similarly about Scheme (or Lisp, Racket, etc).

Hmmm, what would be cool is a language trade off course where different systems are written in different languages/paradigms and are compared/contrasted in a way that demonstrates limitations/capabilities.

2

u/jimmux Jul 12 '21

I feel the same. These days I have no wish to write in C, but I'm glad it was one of the first languages I was taught because it's closer to metal and you have to respect what the machine will do with your code. When I had a choice of languages for uni projects I would usually use C because it made me understand the algorithms being taught better.

At the same time, I wish I was also taught something like Elm so I could see how nice things can be in a purpose built language. The mathematical concepts around pure functional languages are pretty fascinating too.

We did have a course that covered different paradigms, but it wasn't enough to just have a single lesson in an ML language where the benefits weren't obvious, then move right on to a concatenative, language, then something else.

1

u/Voxelman Jul 12 '21

I didn't say learn only FP, I say learn FP first. You should also learn assembler and OOP.

Many schools that only minor in computer science only teach OOP.

1

u/[deleted] Jul 11 '21

I don't think pure functional languages are good introductions to programming. They are too far removed from actual computers. You might as well teach lambda calculus in CS101.

2

u/Voxelman Jul 11 '21

Seriously? Modern computers have 4, 8 or even 16 cores/threads. Imperative languages are known for data race problems. One reason for the increasing popularity of functional programming are multi-core CPUs.

Languages like Rust are a good example. Rust uses functional features to eliminate data race issues.

So the opposite is the case. Functional programming works much better on actual computers.

3

u/[deleted] Jul 11 '21

Rust has functional elements, but it is not functional. You are very much encouraged to mutate and iterate rather than shadow and recurse. Actually, Rust would be a much better language to learn than haskell or Elm. Especially with how it's tooling is so easy to use. Cough, cough, Elm lsp that uses folder called elm-stuff for its cache and absolutely refuses to run with no comprehensible errors if you happen to call your project folder for learning elm elm-stuff.

1

u/Voxelman Jul 11 '21

I know that Rust is multi paradigm. But it uses lot ideas from FP. Even the borrow checker has it roots in FP if you think about it carefully.

Someone on YouTube commented recently about Rust: "The Scala and Haskell folks I showed it to immediately get it. Java and C# devs aren't as used to..."

2

u/salinasjournal Jul 11 '21

I don't think that is necessarily a bad thing. We don't teach hex, then assembler, then C/C++, then Java. The ability to get things done (and done right) is more valuable to me than speed or similarity to computer architecture.

2

u/Auslegung Jul 11 '21

Absolutely agreed. I've mentored several people over the past 3 years who are getting into software careers and I always recommend they learn Elm, for the very reasons you've listed (and defended) throughout this post.