Fl4m3Ph03n1x

Fl4m3Ph03n1x

Does using alias improve runtime speed on structs?

Background

I am reading “Functional Web Development with Elixir, OTP and Phoenix” and in the book the author makes a surprising statement:

(…) In order to shorten that runtime check on an %Island{} struct, let’s add an alias at the top of the module file:
alias IslandsEngine.Island
(…)

WHat?

Perhaps I am miss interpreting this, but what I understand is that by adding the alias of a struct to a module, we actually improve runtime speed on checks that use that struct.

I find this makes no sense at all. Using an alias only affects how the file is compiled, not how fast it runs on my machine.
Can someone explain this to me?

Marked As Solved

lance

lance

Author of Functional Web Development with Elixir, OTP, and Phoenix

Hi Everybody, :wave: :slight_smile:

Some of you have accurately interpreted the line already. To be extra clear, what I meant by “shorten” is “decrease the number of characters” and not “speed up”. Sorry for the confusion!

10
Post #8

Also Liked

LostKobrakai

LostKobrakai

I’d imagine by runtime check the author might have meant something like def function(%Island{} = island), where the alias quite literally shortens what you have to write in the parameter of the function.

easco

easco

The author is Lance Halvorsen @lance. He means that he is going to shorten the number of characters you have to type to write the code that happens to be a runtime check.

gregvaughn

gregvaughn

He’s not particularly active here, but he’s replied to you personally before Jan 18

My interpretation of the quoted statement is “runtime check” means pattern matching and “shorten” means typing fewer characters.

Last Post!

lance

lance

Author of Functional Web Development with Elixir, OTP, and Phoenix

I probably should actually be more active here. I need more hours in the day, I guess. :slight_smile:

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement