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

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement