Another gem from the past
The developer survey conducted by Stack Overflow is a point of reference for many businesses. It is also one of the most followed surveys by the professionals alike. In 2024 the survey reported Erlang developers are paid higher salary. That said we focus on the language itself in this dispatch.
This language was designed to be used for real time applications. Those with a low latency response. Like many programming languages of those days, Erlang is function oriented. In the modern days popular chatting application WhatsApp is built using Erlang. Similarly, AWS and many Message Queue applications also built using Erlang. Key features that make this language the diamond in the rough are its features of concurrency, code swapping (!), message passing etc. Amongst these the code swapping feature is the most admirable one that we love. In this feature we could swap the system code without a down time! Did that rise your eyebrows? It did for us.
The famous way to kickstart any programming language is with a hello world. Here it goes.
-module(hello). |
-export([greet/0]). |
greet() -> |
io:format(“Hello world!~n”). |
The way to compile this is simple as
c(hello). |
You must do this within the Erlang shell.
Once this finishes successfully, we can invoke the result of compilation as;
hello:greet() |
Where the first word is for the module and the next word is for the function that was exported.
Basics
Unlike the object-oriented compiled languages, most of functional languages are dynamically typed. Thus, there is no vast type system in Erlang. It also plays in benefit of being a fast system. The few that are known in Erlang are –
exampleOfTuple = {“hello”, “again”, 3}. |
exampleOfList = [42, 2005, {“hello”, “again”}]. |
exampleOfMap = #{sender=>”Jack”, messages=> 24} |
Let us look at a another simple yet convoluted type;
-module(conversion). |
-export([convert/2]). |
convert(value, inch) -> |
value/2.54. |
convert(value, centimeters) -> |
value * 2.54. |
The literals inch and centimeters are the types which is used to do some what similar overriding. They are called Atoms in the language.
Next we look at some control having learnt the basics. The corner stone of control is the if condition which is written as
case omega of |
1.52 -> controlMeasure:triggerReserve(); |
2.45 -> controlMeasure:fillReserve(); |
_ -> controllMeasure:releaseDelta(); |
end. |
This is familiar to the swith..case which is an advanced form of if..else. If you have not noticed another similarity with the languages of those days. It is the blend of natural language English into programming. Did you notice the period kept at the end of the line. It is the terminator which in many programming languages is “;”.
That is much about control, we cannot miss out on mentioning about higher order functions, a key tennet of modern-day functional programming languages.
converter = fun(x) -> x*4 end. |
converter(10). |
This can be invoked directly from Erlang shell. We are assigning a container for a higher order function. Remember Erlang shell knows nothing but function. The token “converter” is a function and it trickles down the parameter to its assignment.
This is all one experienced professional will need to get started with Erlang. To build a system there is more than these basics. But they build upon these. Concepts of processes, message passing and error handling are very essential to building a robust system.
As much as the carrot of higher pay may attract talent to Erlang; we wish the real value surfaces up as such long bygone gem of a language is polished by the present generation to solve day-to-day problems. Very much like reliable messaging between two friends (read WhatsApp).
Recent post
Archives
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- October 2023
- June 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- January 2021
- December 2020
- October 2020
- August 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019