WHAT IS ELIXIR?
Elixir is a utilitarian, simultaneous, universally useful functional programming language that suddenly spikes in demand for the Erlang virtual machine (BEAM), providing an environment to run distribution systems.
The mixture expands on the head of Erlang and offers similar reflections for building appropriated, flaw open-minded applications.
The solution likewise gives gainful tooling and an extensible structure. The last is upheld by order time metaprogramming with macros and polymorphism using protocols. We have to choose Elixir because of its fun syntax, the vibrant community, and the production-ready tooling.
Organizations utilize Elixir. For example/ PagerDuty, Discord, E-MetroTel, Pinterest, Moz, Cheap seat Report, The Outline, Inverse, Divvy, FarmBot, and for building inserted systems.
- A language that orders to bytecode for the Erlang Virtual Machine (BEAM)
- Erlang capacities can be called from solution without runtime sway, because of assemblage to Erlang bytecode, and the other way around
- Metaprogramming permitting direct control of dynamic punctuation tree (AST)
- Polymorphism utilizing a component called conventions. Like in Clojure, Conventions give a powerful dispatch system. In any case, this isn’t to be mistaken for numerous dispatch as Remedy conventions dispatch on a solitary sort.
- Backing for documentation employing Python-like docstrings in the Markdown designing language
- Mutual nothing simultaneous programming using message passing (Entertainer model)
- Accentuation on recursion and higher-request works rather than reaction-based circling
- Lightweight simultaneousness using Erlang is mechanisms
- Railroad situated programming through the with build
- Worked in tooling for overseeing conditions, code gathering, running tests, designing code, remote investigating and that is only the tip of the iceberg
- Sluggish and async assortments with streams, for example: matching to advance confident code
- Unicode backing and UTF-8 strings.
A programming pattern(paradigm) consists of the rules and design principles of building software. A paradigm change is a serious business. We need to generate multiple tasks and an enormous amount of data quickly and reliably. It means something in how we are building software is not meeting modern demands. The CPU is not getting faster—we can not just write code and hope it will be faster with a new CPU launch.
Installing Elixir: Elixir needs Erlang to run; the Elixir installer introduces Erlang for you. There isn’t a ton to state about the Elixir introducing steps in the event that you follow the official Elixir establishment direct. It covers all that you have to know to introduce Elixir in every one of the working frameworks.
Moving to practical programming: The solution is a powerful programming utilitarian language. The logical linguistic structure of Elixir makes it an available programming language for everybody, in any event, for the individuals who have not educated the practical worldview. It lives in the Erlang environment, which has existed for a long time, conveying programming with nine 9s unwavering quality.
With a utilitarian language like Elixir, We will utilize your CPU multicores, composing shorter and increasingly unequivocal code. In a programming language, when you apply the practical worldview, we will compose code that lives agreeably. Be that as it may, it doesn’t want free. You should comprehend and follow these center standards:
- Unchanging nature.
- Decisive code.
In this section, we will look at these standards in detail and perceive how the useful establishment is more ready for present-day requests.
Working with Immutable/permanent data: Conventional dialects/language use mutating shared qualities that require strings and lock mechanisms to work with simultaneousness and parallelism. In utilitarian programming, all worth you create in your program is immutable.
Look at this Elixir code:
list = [1, 2, 3, 4]
# => 
list ++ 
# => [1, 2, 3, 4, 1]
# => [1, 2, 3, 4]
The value of the list is immutable:
Regardless of the activity we apply to it, it will create new qualities. On the off chance that the rundown is changeless and every activity has a protected worth, the compiler can securely run these three lines in equal without influencing the conclusive outcome.
Unchanging nature is appearing more in regular dialects. Those dialects generally give the permanent instrument by giving you an unchanging datatype elective, or a technique to turn a worth changeless. For instance, in Ruby, you can make unchanging qualities utilizing the freezing technique:
User = Struct.new(:name)
users = [User.new(“Ambika”), User.new(“Vanshika”)].freeze
# => [#<struct User name=”Ambika”>, #<struct User name=”Vanshika”>]
# => can’t modify frozen Array
users.first.name = “Karina”
puts users.inspect # => [#<struct User name=”Karina”, #<struct User name=”Vanshika”>]
In Ruby, when you freeze the array you can not add or remove items, but you still can modify the stored objects. You have seen many developers fall into a trap, thinking that by using freeze they were creating a safe immutable value.
It is easy to make mistakes when a language has mutability by default, and such errors are costly when you are dealing with concurrency.
Although the conventional languages are adopting some functional programming concepts, they do not offer you the full advantage of a functional language ecosystem.
Building Programs with Functions:
In utilitarian(functional) programming, capacities are the essential instruments for building a program. We can not make a valuable program without composing or utilizing a capacity.
They get information, complete some activity, and return a worth. They are generally short and expressive. We consolidate numerous little capacities to make a bigger program. The unpredictability is decreased in programs by utilizing these properties:
- The qualities are permanent.
- This capacity’s outcome is influenced uniquely by the capacity’s contentions.
- This capacity doesn’t produce impacts past the worth it returns.
Capacities that have these properties are called unadulterated capacities.
A simple example is a function that adds 5 to a given number:
add2 = fn (n) -> n + 5 end
# => 7
This function takes a piece of information, forms it, and returns a worth. This is the way how the capacity works.
A couple of capacities will be increasingly perplexing, results capricious, and they are known as tainted capacities/impure functions.
The useful worldview centers around building programming utilizing unadulterated capacities sorted out in a manner that depicts what programming must do, not how it must do it.