Learning Elixir a Functional Language
So, I have a weird fascination with checking out new languages. I'm a Ruby developer by trade. But, that's not enough for me. So, I often find myself dabbling in other languages to see what they have to offer. Nothing against Ruby either, I love it.
My latest forays have been into Crystal (which is nearly identical to Ruby, but compiled), and Elixir. I wanted to give Elixir a shot because the syntax is kinda-sorta similar to Ruby in some ways, and it is a purely functional language which is something I have yet to really dive into.
What is Elixir?
José Valim is the creator of the Elixir programming language, a research and development project of Plataformatec. His goals were to enable higher extensibility and productivity in the Erlang VM while keeping compatibility with Erlang's ecosystem.
José Valim aimed to create a programming language for large-scale sites and apps. Being a Ruby developer, he used features of Ruby, Erlang, and Clojure to develop a high-concurrency and low-latency language. Elixir was designed to handle large data volumes. Its speed and capabilities spread Elixir in telecommunication, eCommerce, and finance industries.
Elixir was first introduced in 2012. It is a general-purpose, functional language designed for building scalable and maintainable applications.
The language complies with the bytecode seen on the Erlang VM (also known as BEAM). Its syntax is often compared to the ever popular Ruby on Rails development framework, and it arguably exceeds it, given that the productivity Elixir allows for is not counterbalanced by lagging performance, as it is with Rails. But, other than syntax, it's a pretty different world as it is a functional language.
- Good syntax (just my opinion)
- The API is pretty stable now and I believe the core language is pretty much complete. Because of, upgrading is fairly easy.
- Community is friendly and inclusive.
- Scales well and a great fit for real time web.
- The main ecosystem (Phoenix, Ecto, etc) are excellent.
- Great macros support.
The main downsides for me are:
- There aren't as many third party libraries compared to PHP/Ruby, so development tends to take longer.
- Deployment is better than before, but not as simple as PHP.
- No static types.
My experience with the language thus far is pretty minimal. I have made a CLI number guessing game and I have played around with the Phoenix Framework a bit, which is very interesting.
Here is my simple guessing game if you want to see how Elixir looks:
# Guess between range of numbers.
# Tell user guess.
def start do
range = IO.gets("What range is your number in(ex. 1-100)? \n")
|> String.trim
|> String.split("-")
low = List.first(range)
high = List.last(range)
guess(String.to_integer(low), String.to_integer(high))
end
def guess(low, high) do
answer = IO.gets("Is your number #{mid(low, high)}? \n")
case String.trim(answer) do
"bigger" -> bigger(low, high)
"smaller" -> smaller(low, high)
"yes" -> "I'm always right!"
_ -> IO.puts ~s(Please type "bigger", "smaller", or "yes".)
guess(low, high)
end
end
def mid(low, high) do
div(high + low, 2)
end
def bigger(low, high) do
new_low = min(high, mid(low, high) + 1)
guess(new_low, high)
end
def smaller(low, high) do
new_high = max(low, mid(low, high) - 1)
guess(low, new_high)
end
end
GuessingGame.start
I'm planning to keep on exploring and improving in this language. The functional approach to programming is quite different from what I'm used to with Ruby. No objects or state to deal with. Just functions and more functions.
Anyone else here have experience with Elixir or functional programming? If so, what do you find as the up and down sides of it?
Leave Learning Elixir a Functional Language to:
Read more #programming posts
Best Posts From nolyoi
We have not curated any of nolyoi's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From nolyoi
- I'm back! And what I've been up to (getting married, working on a skincare app).
- ## I am accumulating! With prices headed down, it's always the best ti ...
- Tezos weekly chart looks amazing, and other Tezos tokens! Don't sleep on them!
- End of season rewards + some quest rewards
- ShapeShift FOX airdrop $150-$7000 worth of FOX!
- How I've made hundreds in Bitcoin doing almost nothing with these apps
- 2 months of DeFi on Tezos
- Splinterlands haul: A LEGENDARY Robo Dragon Knight!
- Plenty - The new DeFi yield farm on Tezos (XTZ)!
- Earning Bitcoin (BTC) from purchases you already make!
- Some photos from my trip to Florida
- VOTE $BANANO! $BAN https://twitter.com/KuCoinItalia/status/1391850381 ...
- My experience building with Flutter and finally coming close to app completion.
- My Top 5 Altcoin HODLs
- Finally got around to farming some CUB!
- File structure visualization of a Flutter mobile app I'm working on. ...
- Why I'm buying up Bitcoin Cash and Monero.
- Now if only $OXEN would pick itself up and get in the top 200. Another ...
- Been stacking up KCS for awhile now because you get almost 13% APR in ...
- How I'm funding my open-source project, and supporting open source software too! If you have any change to spare, doate and get HIVE on tio!