Elixir notes part III


  • OTP is what makes Elixir so efficient. “OTP (Open Telecom Platform) is a set of libraries that ships with Erlang. Erlang developers use OTP to build robust, fault-tolerant applications. In this chapter we will explore how many aspects from OTP integrate with Elixir, including supervision trees, event managers and more;” — Excerpt From: elixir-lang.org. “Mix and OTP Guide”.
  • All documentation about Elixir internals are available online via https://hexdocs.pm/elixir/Kernel.htm
  • GenServer is the most famous and important library part of OTP. “A behaviour module for implementing the server of a client-server relation. A GenServer is a process like any other Elixir process and it can be used to keep state, execute code asynchronously and so on. The advantage of using a generic server process (GenServer) implemented using this module is that it will have a standard set of interface functions and include functionality for tracing and error reporting. It will also fit into a supervision tree.” — Excerpt From: hexdocs.pmGenServer Documentation”.
  • In Elixir, all code runs inside processes. Processes are isolated from each other, run concurrent to one another and communicate via message passing. And this is quite different comparing many popular programming languages including NodeJs.
  • Elixir allows you to drop the parentheses when invoking named functions with at least one argument. This makes the code cleaner. Instead of div(10,2) you can use div 10,2
  • Functions in Elixir are identified by both their name and their arity. The arity of a function describes the number of arguments that the function takes.
  • Inside iex documentation can be accessed via h function. All functions in the Kernel module are automatically imported into our namespace. So you can just type h trunc/1 (1 is the arity) to get documentation about trunc function. You may need to include the module name like h Kernel.trunc/1 . You can also get documentations about the operators too, like + operator: h Kernel.+/2 or h Kernel.+/1
  • Elixir has the basic types of integer, float, boolean, string, list, tuple and atom. An atom is a constant whose value is its own name. Atoms are like enums. Atoms are defined with : . There are also aliases to alias modules. They are also considered as atoms but they are used without : . is_atom(AnythingStartsWithCapitalCaseIsAnAlias) returns true.
  • There are many different cases for atoms. Like boolean types are already atoms true == :true and is_atom(true)will return true. But is_boolean(true) will also return true. Boolean types are both boolean and atoms. So atoms are constants whose values are their own name. IO.puts will write :ok to the output device after printing /putting the data successfully. Here the :ok is an atom.
  • Lists are stored to memory as linked lists. There is a concept of proper and improper lists. Read more : https://dorgan.netlify.app/posts/2021/03/making-sense-of-elixir-(improper)-lists/
  • Elixir uses UTF-8 by default. Strings in Elixir are UTF-8 encoded binaries. is_binary("test") will return true. byte_size("test") will return 4.
  • Single quoted and double quoted strings are handled different. Documentation states clearly https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html.
  • Single quoted string, is actually a charlist, aka a list of chars. If you want to concatenate them, you need to use list concatenation operator ‘++’. 'test' ++ ' ' ++ '1234'
  • Double quoted string, is a UTF-8 encoded ‘binary’, aka a series of bytes. Their concatenation is done via ‘<>’. "test" <> " " <> "1234" . Or can be mixed like "test" <> " " ++ '1234'
  • Strings docs must read : https://hexdocs.pm/elixir/1.12/String.html




GCloud, AWS, Security, NodeJs, Berlin — This blog is mostly technical and multilingual. Be aware of possible and multiple typos!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

MySQL Database with .NET Core 6 and Entity Framework

Resource Sharer: How to Share Sync Resources in an Asyncio Environment

How to deploy your first local Kubernetes cluster in 20 minutes.

Why Use a Managed DNS Provider?

Lock it carefully!

Entity Framework Core With the Code First Approach in .Net Core Project

Change is Okay — Life is not Hard Coded

Computer screen with code

How Abstract improves collaboration in our team

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hasan Tayyar Beşik

Hasan Tayyar Beşik

GCloud, AWS, Security, NodeJs, Berlin — This blog is mostly technical and multilingual. Be aware of possible and multiple typos!

More from Medium

Ranked data with Ecto window Queries

Elixir OTP and CockroachDB

Goodbye Elixir (for now)

The only constant is a change or how The Explicit Architecture can save the day (Part I)