Live data from Hacker News

Why am I interested in Elixir?

underjord.io

81–90 of 183 posts

Re: Why am I interested in Elixir?

#81
post #60
post #50

Earlier quoted context omitted.

Are we doing semantics now? Java is also compiled into bytecode, executed by the JVM. Do you consider Java an interpreted language also?

I think most people consider Java to be an interpreted language, it's interpreted by JVM. It's obviously somewhere in between, in the same way that JIT languages are, but it's still not native.

Not sure about the BEAM, but Java isn't considered an interpreted language at all.

First, discerning the compilation step to IR is relevant, which is why for example, Python can be compiled or interpreted. That distinction matters. Even though it is compiled to intermediate representation, it is still compiled.

Now, with regards to the intermediate representation, Java Byte Code is also not interpreted. Java Byte Code is compiled to native machine code either Just in Time by the JVM, or Ahead of Time by the SubstrateVM. Both of these make it a compiled language.

An interpreted language never gets translated into native machine code, it gets executed by a native interpreter, and that's very different. It is more akin to using a language where you read and parse texts, and based on the text, you might execute one or more things. Now if that parsing to execution branching is powerful enough to allow Turing complete behavior, you have yourself a full blown interpreted computer language. This is not what happens in the JVM. The JVM translates Java Byte Code to native machine code Just in Time, and then the native code is run.

Re: Why am I interested in Elixir?

#82
post #61

My experience with Elixir has been great but one area of improvement is debugging. Maybe it's because I'm so used to using something like Chrome's developer tools, but I wish there was something as easy to use for setting breakpoints and inspecting the environment. Would love to know how others are debugging currently!

I'm surprised there are so many comments surrounding debugging in this thread. Did you use `require IEx; IEx.pry()` in your code at all? This gives you almost the exact same experience as calling `debugger;` within javascript. If so what was lacking with that experience?

Re: Why am I interested in Elixir?

#83
post #60
post #50

Earlier quoted context omitted.

Are we doing semantics now? Java is also compiled into bytecode, executed by the JVM. Do you consider Java an interpreted language also?

I think most people consider Java to be an interpreted language, it's interpreted by JVM. It's obviously somewhere in between, in the same way that JIT languages are, but it's still not native.

[deleted]

Re: Why am I interested in Elixir?

#84
post #64

We are building a sales automation app using Elixir and Vue. Our dev team seem really happy with this tech stack. Productivity is awesome - we are four months in and already have similar functionality to a (sort of) competitor that has spent several years on their dev. This is the first dev project I have experienced where we are ahead of our planned milestones. Got to find some more features to quickly add! My origi…

> Only (small) gripe is that Elixir is not a fast language.

Which is interesting because Elixir isn't well known for being super fast when it comes to CPU bound tasks, but for a lot of semi-CPU intensive things you'd end up doing in a web app, it's still very very efficient.

For example I wanted to generate 5,000x 19 random character discount codes and my first attempt took 730ms to generate the codes while being a complete newbie to the language and cobbling together Enum.reduce / Enum.random while concatenating strings. Within an hour of asking if someone had a better way of doing it, I got multiple solutions from community members that were able to produce the same results in 25ms while still having very readable code (arguably more readable than my original implementation), and even one person came up with a solution to do it in 3ms.

It's almost hard to imagine being in a position in a web app where 3ms would be considered too slow to generate 5,000 unique discount codes with a custom character set.

Re: Why am I interested in Elixir?

#85

Where are people getting their documentation for Phoenix? The stuff on the website is awful for grasping the bigger picture and how the parts of Phoenix combine. It gave me the impression of being an immature version of Rails when I tried it recently which doesn’t gel with the attitude people seem to have of it.

For the bigger picture I would say grab the Programming Phoenix 1.4 book. It was written by the authors of Elixir and Phoenix.

It focuses on building a web app and shows how everything fits together while solving real issues, which is a much better learning experience than the documentation IMO. If you come at it with a Rails background you'll probably walk away with a completely different impression.

Re: Why am I interested in Elixir?

#86

Earlier quoted context omitted.

Not sure I understand completely your problem and I apologize if this is a stupid question, but can’t you just pattern match the errors in with’s else block?

this depends on errors being unique to the line they come from. if any of your errors overlap then it doesn't work. for example what if you have a bunch of functions that return {error, :notfound} and you want to handle each differently. also you don't have access to any previous values instantiated in the else block. if you could have an else block for each <- that short-circuited and had access to previously <- ass…

One technique I use to solve this is to name each stage of a complex pipeline with tuple pairs. Then I can pattern match on a specific error. I've found that I haven't ever written crazy error handling and so this has worked well for me

Re: Why am I interested in Elixir?

#87
post #35
post #27

Earlier quoted context omitted.

.... and no vectors/arrays.

You've got: • http://erlang.org/doc/man/atomics.html and http://erlang.org/doc/man/counters.html for cheap, mutable uint64 arrays; • The http://erlang.org/doc/man/array.html module for a functional persistent vector abstraction (similar to the one in Clojure); • ETS ordered_set tables, for mutable AVL trees (for when you want to cheaply apply a sequence of random mutations to a collection of terms without building a…

Thanks! Didn't know about some of those.

Re: Why am I interested in Elixir?

#89

My startup uses Phoenix, along with a Vue front-end. The combo is an absolute joy to use. The benefit that has had the most business impact for us so far is developer productivity. A couple of months ago we met with a prospective client to discuss their use cases and conduct requirements gathering. They really liked what we showed them, but the CFO wanted a dashboard that displayed the data in the app in a specific w…

Great story, and best of luck! BTW, if you haven't tried it yet, the new Phoenix Live View makes those one-off dashboards a joy to make in my mind. Vue is fantastic but it still ends up with two layers which need data piping.

Re: Why am I interested in Elixir?

#90
post #73

Earlier quoted context omitted.

Are there no bad parts?

- deployment is terrible like really bad - average performance ( like 10x slower than Java even worse for CPU intensive tasks ) - dynamic language ( this is the worst part ), working on large code base means problems ahead - lot of features from BEAM / OTP that are not that useful and done better on modern cloud platforms ( Kubernetes for instance does a lot of similar things but better and more flexible, apply to an…

> - dynamic language ( this is the worst part ), working on large code base means problems ahead

IMO, I the fact that Elixir is a dynamic language is not that much a problem thanks to pattern matching.

Elixir's pattern matching is really powerful, allowing for things like:

    def move(_state, _x, _y, kind) when kind not in ~w(forward backwards) do
      {:error, :invalid_move_kind}
    end

    def move(state, x, y, kind) do
      get(state, x, y)
      |> do_move(state, x, y, kind)
    end
In this case, I am asserting that "kind" is either string "forward" or "backwards". If not, I return the an error :invalid_move_kind. I don't need to check if pos is nil or not string, since I can assert using pattern matching that everything with my inputs are right.

Also, there are things like structs:

    defmodule RobotVsDinosaurs.Robot do
      alias RobotVsDinosaurs.Robot

      @enforce_keys [:pos]
      defstruct name: nil, pos: nil

      def set(state, x, y, robot = %Robot{}) do
        case Matrix.elem(state, x, y) do
          %Robot{} -> {:ok, Matrix.set(state, x, y, robot)}
          _ -> {:error, :invalid_type}
        end
      end
    end
What I am saying in the code above is that %Robot{} must have a :name and a :pos entries, and by default they're nil. However, to create a new %Robot{}, :pos must be different them nil. And of course, I can pattern match if my input is actually a %Robot{} and not a simply dict.

You can also do crazy things like pattern matching if a byte array have some specific characteristics, like a magic number.

So while I think it would be nice for Elixir to have types (there is Dialyzer however it is kinda a PITA to use), it is less necessary than Python/Ruby/Javascript thanks to the above.

Post reply on HN