Let's jump right in, shall we? Elixir syntax can be familiar and weird at the same time, especially if you're coming from Ruby. To prepare for this section, let's clear our minds - let go of familiar syntax cues and "the way it's done" in the languages you already know.
Elixir does things differently.
For instance: while Elixir has an if
keyword (and also unless
) - use of these is frowned upon by Elixirists and is considered a bit of a "code smell". You can, indeed, write loops but hard core Elixirists favor recursion.
We'll get into all of this, and you'll understand why very soon. But let's dip our toe into the purple Elixir sea and decide if we want to swim...
The Simplest Things
Let's have a look at some code. You won't understand all of it, but it's important to get your eye used to seeing Elixir so, at this point, let it wash over you:
# this is a commenttitle = "a string"price = 12.00quantity = 1:yellow
No semicolons. No braces. Elixir is a clean language which, like Ruby, drives expressiveness and clarity.