

Lovely Week with Elixir
source link: https://www.ramblingcode.dev/posts/lovely_week_with_elixir/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

It’s not often I get excited about programming languages
since meeting Ruby
in 2015.
Way before that, drowning in misery of writing university course works in Java
,
has pushed me away from development. Ruby’s freedom and expressiveness
was what pulled me back, and it’s style has kept me in.
I was on the lookout for another language to expand my tooling, and came across
a few, such as Crystal
, Phyton
, Elixir
. But what’s the point with just another
Object Oriented language I thought.
So, choosing Elixir was a no-brainer, and I will finally taste some of that juicy concurrent abilities with functional code base.
I can say that a week in, I am already happy with my decision. However, the reason is not mostly associated with my understanding of possibilities, but more because how welcoming the language is alongside following best practices.
Starting with Ruby
, all I cared was to get something done in fast and stylish way.
Starting with Elixir
, I took a different approach, not because I chose, but
because I have been instructed.
Let’s go through a few points on how Elixir welcomes newcomers to the language.
Great language documentation and resources
Being a fairly new language, I did not expect that there was such huge amount of quality resources for Elixir. Official documentation itself is gold . This, alongside with Elixir School was all I needed to get going with the language.
Documentation as first class citizen
I can not stress the importance of documenting code base enough. However, in most languages you get a feeling of it being an optional thing, thus mostly ignored, or not followed consistently.
Writing and generating documentation is a breeze in Elixir due to built in tooling. You can even write docs which will be automatically added to your test suite …
Built in code formatter
Not all code bases implement static analyzers on time, and then it just becomes a pain to catch up. (I wrote a little post about how you can bring static code analysis at a later stage to your Ruby projects.)
There are loads of code bases that don’t even know about the existence of consistent formatting.
As trivial as it may seem, it absolutely isn’t. Consistent styling is not optional, and Elixir helps us to avoid that by providing us with built in code formatter.
Type specs, when you need them
Hahaha, I didn’t imagine that one day that I would like to write typespecs again. However, working with mostly financial tools/money, I would rather prefer extra safety when I need it.
For this we can use type specs over function definitions when we need it.
@doc """ Authenticates using OAuth. If succesful, returns {:ok, %Client{}}, else {:error, %ApiError{}}. """ @spec authenticate(String.t(), String.t()) :: {atom, Client.t() | ApiError.t()} def authenticate(grant_type \\ "password", scope \\ "forintegration") do params = %{ grant_type: grant_type, scope: scope, username: Application.get_env(:banco_bs2, :account).user, password: Application.get_env(:banco_bs2, :account).pass } case HTTPoison.post("#{@base_url <> @auth_endpoint}", url_encoded(params), headers()) do {:ok, %Response{status_code: 200, body: body}} -> handle_success(Jason.decode!(body)) {:ok, response} -> handle_error(response) {:error, %Error{reason: reason}} -> {:error, %ApiError{message: "Connection error occured: #{reason}"}} end end
Your code will still compile as Elixir is not a statically type language, however, it will help you to have more clarity when writing code.
You may use Dialyzer or other tools to have it statically checked as well.
Erlang interoperability
It’s great to have access to mature Erlang ecosystem libraries within Elixir, even though it’s use is discouraged.
I am amazed how after a single week, even as a beginner, I can start to write maintainable readable code in a new language and paradigm.
Let’s see where this all goes. In no means, I will be writing less Ruby, but more Elixir alongside it.
See you around on Slack channel !
Recommend
-
80
Color schemes occupy an important part in your life. This talk will explain how to create your lovely color scheme for Vim, and will introduce some useful tools.VimConf 2017 — International Vim Conference:http://vimconf.vim-jp.org/2017/Iceberg —...
-
46
README.md ClockView A lovely clock view. 中文
-
51
My lovely dots ~/.?. Contribute to denysdovhan/dotfiles development by creating an account on GitHub.
-
32
Join GitHub today GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
-
17
Art of Thanks: Lovely Thanksgiving Illustrations Our new illustration set is up to share the atmosphere of love, good wishes, and gratitude this week when lots of families are getting prepared for one of the brightest dinners of...
-
8
An 800ppi iPhone Display (or, why AirPods Max look lovely, but aren’t for me) Matt Birchler | 17 Dec 2020 | 2 min read The original iPhone had a 3.5” display at 480x320px r...
-
9
That lovely smell of burning plastic and rubber Back when I used to work for a school district, I may have supposedly been their Unix sysadmin, but I wound up dealing with a great many other things. One of them was a lot of deskt...
-
15
Lovely summer illustration examples to check out Ready for some summer illustration examples? We have quite a few here.
-
9
static constexpr unsigned long is C+...
-
10
DPlayer Wow, such a lovely HTML5 danmaku video player Introduction DPlayer is a lovely HTML5...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK