mkellyxp

mkellyxp

Im an “old school” PHP developer working in the traditional LAMP stack for years now. I’m ready for something new and have projects that need to scale. So naturally I’ve landed here.

I’ve purchased some elixir / Phoenix books and have the boot camp course on Udemy and about to really dive in.

But I have to admit, my brain is having a really hard time with the syntax! The functional programming part is fine grasping. But all the bizzare symbols everywhere just totally looses me. I don’t find it readable at all.

I know most of this is because it’s new, but even so, it looks so cryptic. Any tips on getting comfortable or understanding these basics. Sure I can copy and paste from a book or course, but I really want to understand what on earth I’m looking at.

I’ve heard amazing things about this community and excited to be here!

Showing Posts 1 to 10

axelson

axelson

Scenic Core Team

Welcome to Elixir and the forum :wave:!

Hmm, since the books seem like they aren’t working to well for you right now I’d recommend some more practical practice. I really like Exercism for that Elixir on Exercism because they’re nice little self-contained projects so they will help to get you familiar with reading and writing some elixir code.

If you haven’t already done it I would also recommend the official Getting Started guide: https://elixir-lang.org/getting-started/introduction.html

trarbr

trarbr

If you haven’t already done it I would also recommend the official Getting Started guide: Introduction - The Elixir programming language

I would also recommend the Getting Started guide. I also struggled with the syntax in the beginning, and I learned it by going through that guide. You should not just read it though - if you force yourself to type it all into IEx / .exs-files, your brain will eventually grok it.

When you’re done with the Getting Started guide I suggest also going through the Mix and OTP guide, just to get some experience with Mix.

mindok

mindok

A lot of developers learn most efficiently by doing, preferably with something useful at the end of doing, so if you have a small personal project to work on that can be a great platform for learning.

Feel free to ask questions on here. I think it’s fair to say that there’s a high proportion of enthusiasts who love the language, libraries and runtime after earning too many grey hairs from other platforms, and are more than happy to help beginners get going providing they are making some effort to self-learn along the way.

In terms of weird symbols etc, here are a couple of pointers to things that I found to be very different in the early days:

|> - pipe the output of one function into another as the first argument - pretty much like unix-style command line pipes.
:an_atom - this got me at first becomes I didn’t come from the school of Ruby - it’s basically a constant, but there are a few little tricks - you can google these. Here’s a starting point: https://stackoverflow.com/questions/32261500/why-is-useful-to-have-a-atom-type-like-in-elixir-erlang
~s(something or other) - a sigil - basically the contents within the brackets are processed in a special way depending on which sigil is used. Well documented in the language guide: https://elixir-lang.org/getting-started/sigils.html
<- and -> are just part of syntax in case & for - you’re just going to have to practise with those

There’s some really tight syntax for in-line defined functions can be super-confusing at first. For example (from https://elixir-lang.org/getting-started/enumerables-and-streams.html):

1..100_000 |> Enum.map(&(&1 * 3))

This means, for each value between 1 and 100,000, multiple by 3.
The .. between 1 and 100_000 indicate the generation of a range. That range is passed in to Enum.map as the first argument by the |>, and an in-line function is passed in as the second argument.
&(&1 * 3) is the in-line function defined in place rather than being defined elsewhere and referenced. The & at the beginning indicates the start of the function definition and the &1 indicates the first (and only) variable passed into the function. There’s a little bit of discussion of this syntax here: https://elixir-lang.org/getting-started/modules-and-functions.html#function-capturing

While it seems overly terse at first, it turns out to be really useful as a way to define a simple transformation to apply to a list of data.

Finally, the whole pattern-matching thing is confusing if you haven’t come across it before. I tried to understand it by reading about it, but in the end I got my head around it by playing in the interactive shell. It’s like a combination of equality-checking and assignment depending on what elements of a match expression are able to be assigned to. Once you do grok it, pattern-matching is one of the language features that makes Elixir super-readable.

Again, feel free to ask about specific things…

hauleth

hauleth

Funny thing to hear from PHP developer.

mindok

mindok

:rofl:

But you have to admit 1..10 |> Enum.map(&(&1 + 2)) is a bit special when you first see it.

derek-zhou

derek-zhou

You don’t have to use all of them. Find a subset that you are comfortable with, and stick with it for a while. I’ve been writing elixir for a year and I still steer clear from with or list comprehension.

Exadra37

Exadra37

I also come from PHP, and the only thing that clicked to me was this book:

or if you prefer the equivalent video course:

The hardest thing for me is to always understand what is compiled time, boot-time, and runtime, especially when it comes to configuration and to some macros and functions that are only called at compile time, and for us coming form languages like PHP keeps biting us over and over, but I am more aware now… with time you get better at spotting them :wink:

Another thing that is hard to grasp is the Dyalizer type specs, and this may be the symbols that you are complaining about, because they also puzzled me in the begin, but nowadays I learned to “ignore” them, and I just use the Domo library that hides their complexity from being everywhere in my code.

mkellyxp

mkellyxp OP

Thanks so much! I actually just discovered Exercism and joined the Elixir and Rust tracks, and will likely be a PHP mentor there as well! So this is a great tip.

To be fair, I wouldn’t say the books aren’t workign.. i’m positive I can get things working by following the books. It was more wishing there was some kind of cheat sheet for the syntax. But perhaps i’m putting the cart before the horse here. I got a Phoenix / Elixir book. Maybe I need to dive into elixir itself first

mkellyxp

mkellyxp OP

I was going through some basic Phoenix examples last night and saw this:

def register_user(attrs \\ %{}) do
 	  %User{}
 	  |> User.registration_changeset(attrs)
 	  |> Repo.insert()
 end

Most of that isn’t words at all. What on earth is \ and %{}? Thats the stuff i’m talking about. A similar function in my php app is:

public function add( $p_asPayload ) {
     $p_asPayload['client_id'] = DB_CLIENT_ID;
     $this->db->insert( 'lessons', $p_asPayload );
     return $this->db->insert_id();
}

Short of the $ symbol.. it’s all humanly readable. Trust me, i’m not saying PHP is better.. but I do feel like it’s less cryptic, even if that means it’s less functional.

mkellyxp

mkellyxp OP

Thanks! I actually had a demo of this book, but then picked up the Pragmatic Programmers Programming Phoenix > 1.4 book. And i’m starting to see that, this is the issue. I might have to spend some more time in elixir itself before diving into phoenix, plugs and web routing.

Thanks for the reminder about this book!

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews