Elixir: The language every OOP person should taste

Elixir: The language every OOP person should taste

2019, Jan 17    

Like every other programmer out there who can’t stop talking about the Object Oriented Programming paradigm, I must say, that was me. Well, things have changed, atleast for me. I surely know it will for you all too, as I believe this language is here to stay. So, as you all might have guesed, am talking about Elixir.

I know some of you might be thinking,

  1. Why Elixir, why not GoLang?
  2. Isn’t GoLang the hot language these days?
  3. Aren’t many companies using GoLang?

Let’ see what are the possibilities.

  1. Well, for one, both are entirely different type of approach, and we are talking about Functional Programming here. Secondly, I have laid my hands on GoLang too, but kind of felt ugly for me to digest easily. Its the syntax that threw me off, and not the concept and idea behind how GoLang works and solves the problems of Concurrency, Garbage collection etc. But with any language we adapt to in programming world, there obviously will be a trade off. I leave that to you to comment. Let’s battle it out in the comments.

  2. YES! I know many NodeJS people are like, Nah, we cool here. But hey, GoLang is from Google and the core team are legends in Programming and the whole of Compute ecosystem. So you might wanna respect the work bro and chill! Usually, whatever Google comes out with, most of us blindly take it up and say its the best! Whatever.

  3. Ermm, Yes and No? Ofcourse, as in (2), GoLang coming out from Google does carry a lot of weight and morale, which a company could add to their profile, and look cooler? I mean, let’s think of it this way, not all products out there in the ecosystem needs GoLang. Similarly not all of them need Elixir, or Python, or NodeJS. Everything boils down to what suits the problem we are solving. This is why I find it hard to believe, why many startups tend to show off GoLang in their stack or job descriptions, even though when you look at the product they have might not need it or might not benefit much comparing the trade off.

Well, that’s a lot of GoLang, but our topic isn’t GoLang. Silly me, got carried away there. But this does point to where am getting at.

See, my laziness towards picking myself up from the comfort zone of being a Python Developer, was one of the main reason why I haven’t learned a new language in the past 2 years. Python is a brilliant simple and elegant language one can live dearly with, and for that same reason, it becomes so hard to let go off it. For one, the learning curve is so smooth and simple. Secondly, its so Object Oriented and hence helps solve most of the problems quite easily!

But hey, I just left that comfort zone approximately 25 days ago, where I told myself, enough is enough, get your ass up and let’s do this!

What made me choose Elixir?

A friend of mine, well my college junior to be exact, happens to be an Elixir/Ruby dev now. There isn’t a single month, back when he was doing a project in Phoenix Framework (a massive Web Framework written in Elixir), where he stopped saying stuff about Elixir, how recursion was all important, how the way of doing things was masively different from what a normal OOP guy is used to and so on. I would be like, ya man, good for you, blah blah. Note, this is that lazy me here! That was my first major exposure to Elixir, although Clojure and Elixir where topics in our peer discussions on a weekly basis.

As soon as I started watching some of the tutorials for Elixir, I kind of liked how the syntax was derived from Ruby (oh, and also, Elixir was written by a Ruby dev. So! Prr!)

The pattern matching is brutal stuff, I can’t do this

to

This thing is so lit, what a beautiful way to do numerous stuff with one single line of code!

You see, I should not be judging the language by its syntax, but hey, that’s what you see at first. The implementation strategies and solutions it arrives at ,comes after a deeper thought process. A good problem solver should have the right kind of tools up his sleeve, when required. For that, it is always better to have that one extra tool, which you might never use, but will always have your back. I wouldn’t say Elixir would be such a language, which I would never use and so. Infact, I have a lot planned with Elixir for 2019!

Another thing that blew me away was the Reponse time Phoenix framework produces for HTTP Requests! Bloodyyy hell? I mean, come on, MICRO SECONDS?

Here I was writing Web Apps with Python/Flask for 2 whole years and I constantly see response times of the order of tens of milli seconds, and then Phoenix boots and delivers 5us. Jeez! There, I love you!

A new language? A new barrier?

Learning any new language , be it spoken, be it programming, is exciting for some, and rather daunting for some others. To me, I was sure that learning Elixir or GoLang or Clojure would not be much of an issue, because I belive I was born to code! I understand what the languages try to speak.

Having said that, jumping from one paradigm to another is quite unrealistic and is not a pleasant journey for most people. This is what kind of threw me off at the beginning, like every other Elixir learning person out there I believe.
Why?
Elixir have absolutely no concepts of objects and classes. There is only Modules and functions. You have a basic data, you pass it a function, pipe it to another, and another and then another and you have a final data which is your result. There are no instances, no behaviourial methods or attributes, there is no inheritance from Classes. Everything revolves around pure and simple functions! Having said that, I believe this is a right place to plug in one of Anjana Vakil’s YouTube video I recently watched, where she explain what took her to do Functional in JS. Almost all the concepts remain the same, but in a more functional environment, as in JS you can go OOP way as well.

Well, objects and classes where the majority share holders of my programming life journey, and all of a suddent, a language comes in and takes all of them away. I must say I enjoyed the ride so far, and challenge was quite fruitful.

Elixir, and Erlang!

Not sure how many know where/how these two connects. Elixir is a language made on top of Erlang Virtual Machine, and hence you guessed it, we could call Erlang functions inside Elixir! Wait, what’s Erlang?

Well, Erlang is another ancient language, people! Oh boy, here we go again! Erlang was built at Ericsson [Ericsson Language (shameless plug I must say!)] to solve the huge telecommunication problem: Call drops!

Yes, imagine the telecommunication network, and how bad computers are hit with concurrent requests! The computer had to be quick, process all of them, and be safe and less faulty! Concurrency, Distributed, Fault Tolerance, Asynchronous, throw more into the problem space, and we have a huge pile of mess to sort out! Luckily though, these guys have done it, and its pretty much brilliant. But Erlang as a language, being old school, isn’t something many of us can digest easily. And hence Elixir was born!

Phew, that is a lot to digest.

What I love about Elixir/Erlang ecosystem

  1. Cool syntax bro! Ruby nods happily!
  2. Pattern Matching is heaven
  3. Pipelining of functions. YES! Procedural+Functional Programming!
  4. Code modularity and purity of functions
  5. Phoenix Framework - response time, blimey! A separate topic for blog! Actually, I might do it, sometime after!
  6. Doctest. Seriously, how cool of a feature is this. Write docs with examples, which can also then act as Test cases for you modules! WHAATT! SWEET!
  7. Official documentation is pure gold, full of examples and convention reminders, with exceptions here and there!

What I hate about Elixir

I might not be the right person to say this at the moment, as I know there is a lot to be learned, and what I think is bad might turn out super useful for the ecosystem. I will come back to this post say after having worked with production level applications on Elixir/Phoenix.

Giving up on Python?

Hell no! Python is favorite language and will always have a strong high place within me. Python is cool and sweet, Elixir is hot and new in town! Also this blog post here is a great way to transition from Python

Let’s keep things calm here! Bye!