Hacker News new | ask | show | jobs
by gprasanth 2246 days ago
I've been writing code for close to 10 years now and I see this and feel like what a beginner would feel trying to understand assembly code. Or someone hearing a similar but new language.

Looks to me hours of work and learning got abstracted as under the hood "magic".

It's like saying: Oh, so I've been weight training for the last 17 years and I should tell you Olympic silver is not too hard, see?

Am I right in my thinking? or is learning to be this proficient with the framework not as time taking for a novice developer as I think it to be?

3 comments

There's no magic. It's functionality that's made possible by the BEAM. It's just one of those things that came out of realizing how powerful the runtime was for handling certain types of problems.

When you combine a couple of those bits together, you end up with this.

The only modern web problem that Elixir isn't ideally suited for is heavy number crunching. Otherwise it gives this amazing balance of efficiency, scalability, reliability, maintainability and capability that can't be replicated in any language that has a shared memory model.

> The only modern web problem that Elixir isn't ideally suited for is heavy number crunching.

I would caveat that in a couple of ways.

First, suppose you have a web app where some requests involve heavy number crunching and others don't. In web frameworks where 1 request ties up 1 OS thread, a burst of heavy requests could gobble up all your available connections. Phoenix would use one cheap BEAM process per request, and the BEAM's preemptive scheduler would ensure that other requests are answered in a timely way and that all the heavy ones continue to make steady progress. So although the heavy requests might be completed more slowly than in another language, the overall system would remain more responsive.

Second, if you have need for heavy computation or data structures that work better with mutability, it's possible to (eg) use Rustler (https://github.com/rusterlium/rustler) to implement that part in Rust. See https://github.com/rusterlium/rustler for a story about doing this.

I'm of a similar view to them, this felt like lots of magic or at least lots of gotchas I can see myself hitting. I saw two function definition types (def and defp), pattern matching input then requiring a caret for the variable name (?), passing in "assigns" but then referring directly to other variable names, pipes, etc. There's a lot there compared to when I've worked in Erlang.
Gotchas, probably some of those. Both in Elixir and Phoenix. It is an entire language plus an entire web framework.

A lot of people find Elixir more approachable than Erlang. But I wouldn't be surprised if Erlang is technically simpler and as such potentially easier to learn. The syntax is quite foreign to most people coming from more conventional languages while Elixir reads and writes fairly conventionally.

Now Phoenix LiveView does a lot for you, so I wouldn't dismiss the claim of having some magic in there. But once someone starts to get familiar with the stateful approach the model is fairly simple and the "magic" is less mystical. A lot of the things you don't need to pay attention to would be optimizations in markup and templates and how the JS does its job. That's where a bit of magic happens.

Most of the things you mention sound like things about the language. Which I found to be very approachable and the onboarding documentation to be great.

def and defp are probably the least magical of those. def is for public functions (can be called from other modules) and defp is for private functions (cannot be called from other modules).
Are you familiar with Ruby on Rails? Phoenix was built as a simpler equivalent, to leverage websockets, and to leverage the BEAM to be performant with high concurrency (i.e., what you generally want in a web server).

Is it encompassing a lot of magic? Yes. But the quick growth in mindshare that Ruby on Rails attained back in 2005-2010 (part of which it still retains) was due to how easy it was for a novice developer to pick it up and build something useful. Pick it up and understand all the pieces, no. Phoenix is less Express/Martini in nature, more Spring/Rails (but more pleasant than either of those to work with, I would contend, but again, that's opinion).

I think the biggest hurdle would be the Functional Programming aspects. Elixir was quite easy for me to approach coming from mostly PHP, Node.js and Python (preferred Python before Elixir).

Phoenix has a sprinkling of magic or syntactic sugar through macros and stuff but the step between Phoenix and LiveView is not that mystical to me.

I have taught a novice developer, not yet out of 2-year school for web dev, to use Elixir and the Phoenix Framework. I really should interview him about that. Write something up.

I would say that Django does more stuff under the hood than Phoenix. But they are fairly different vehicles.