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.

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:

NobbZ

NobbZ

We need to ask the author what they actually meant…

An alias does nothing but “renaming” an atom during compile time:

iex(1)> alias Foo, as: Bar
Foo
iex(2)> Bar === Foo
true
iex(3)> Bar
Foo

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement