3 ms·
I picked up on erlang during august this year after reading an article by Joe Armstrong on it. I was new to functional programming and there were two things tha
by brickcap 13y ago
I picked up on erlang during august this year after reading an article by Joe Armstrong on it. I was new to functional programming and there were two things that I found really interesting.
First was the use of atoms. I am not too proud to say it, but when I as a beginner I used lots of "magic strings" in my code. I found them a lot more easier to understand.Stuff like
if(a="run")
//some piece of code here
was common in my code. Of course the best practice was to use a bool run, but I had to train myself to stop using magic strings when I found out that it was bad practice.
In erlang however it is very common to use literal values which are known as atoms. So for instance an atom "blue" is blue. It does not have anything associated with it(well internally it is represented as an integer). You can't perform any operations on it, you can't change it etc. And it immediately clicked with me
The second thing was pattern matching
You have got to use pattern matching to see how awesome it is. It allows you to make your programes much more readable by dividing your function into a group of clauses. A clause will be executed only if a corresponding pattern matches to it. If you use it well you can grasp the flow of your program in a single reading.
There was other really cool stuff about erlang like otp, concurrency etc but when I started with it the only things that I cared for were atoms and pattern matching.They got me started with erlang. Now that I have used erlang a bit more I find things like gen_events and gen_fsm behaviors invaluable for the stuff that I am trying to do.