Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
Elixir is for programmers (pluralsight.com)
138 points by rohshall on Dec 6, 2013 | hide | past | favorite | 51 comments


I really like Elixir.

Not only does it have a clean, pleasant syntax, macros, but it has all the good parts from Erlang, namely:

* BEAM VM (isolated heaps, very well tuned scheduler, concurrent garbage collection)

* Pattern matching, once you've tried it, it is hard to go back.

* Ability to call Erlang code

BEAM VM is really a secret gem and many didn't get a chance to play with it because they didn't like Erlang's syntax (personally, I do like Erlang's syntax, but I think many don't). Well there is little excuse now.

If you like DSLs and macros (yes, yes, I know it makes many people scared) this you can do neat stuff like these projects:

https://github.com/elixir-lang/ecto -- DSL to query databases


This is what I came here to say. All of the 'raw language' niceties that Geoffrey mentioned in the article are true, but for me one of the greatest things in Elixir is processes. Just, the way the Erlang system operates is so well thought out, I'm more impressed every time I learn something new.

Shameless self-promotion here - I run http://www.elixirsips.com, which is a screencast series that releases 2 new episodes per week covering some topic in Elixir. I started it out as I started learning Elixir, and I've been going for quite a while now (I'm on Episode 33 next, so 16 weeks so far). It's the most fun I've had with a programming language since I first saw Ruby, and I think the BEAM VM is the future (as is Rust/Go/clojure's core.async, other concurrency-oriented programming models, etc).

So yeah, Elixir's amazing and everyone should play with it. I think just looking at these items mentioned in the article aren't even giving it a fair shake - learn about Erlang's concurrency and distribution models, or else you aren't even scratching the surface :)


I'm a subscriber to Elixir Sips, and just wanted to say that the videos are well worth it to anyone looking to get into Elixir. I'm a happy subscriber, and look forward to more videos.

knewter doesn't know me, and I don't know him.


Thank you for this resource.


Thanks for posting this. I am going to subscribe to this. I've been hearing nothing but wonderful things about Elixir but have been struggling with making some mental connections. Your videos look like they'll help me make those connections.


Thanks for the pattern matching tip. Will investigate.

I'm looking for a better way to navigate of graphs. Objects graphs, DOMs, parse trees.

Currently, I rely on iteration and glob style paths. http://en.wikipedia.org/wiki/Glob_(programming)

For instance, excerpt from https://code.google.com/p/lox/source/browse/trunk/test/lox/t...

  InputStream in = new FileInputStream( "./test/lox/test/zooinventory.xml" );
  Document doc = LOXHandler.load( in );
  List<Element> animals = doc.find( "Inventory/Animal" );
  System.out.println( "animals found: " + animals.size() );

  for( Element animal : animals )
  {
    String habitat = animal.findFirstString( "Habitat" );
    String lifestyle = animal.findFirstString( "Lifestyle" );
    ...
  }

  ...

  // Actual example of some globbing
  List<Element> names = doc.find( "Inventory/*/Name" );
  System.out.println( "names found: " + names.size() );
What I really want in a future language is for those glob paths to be first order objects, not magical strings. Then the compiler can do some sanity checking, editor can do autocompletion, etc.

Warning: Lightweight Objects for XML is a personal project, very alpha. https://code.google.com/p/lox/


Ever since I started getting into Clojure, I've been getting interested in these other functional programming languages. Lately I've been checking out Elixir. I don't know what draws me to it (most likely the pretty website and logo :P, and partly because I hate the Java ecosystem). I want to get into it as well, but I just don't see myself using it for anything? I mean for the types of problems I'm capable of solving, Clojure (and Python) seems to be sufficient. To me, it seems Erlang (and thus Elixir) only offers its advantages when building really large distributed systems. Is there any other use case for Erlang/Elixir?

I'm still going to be reading up on Erlang/Elixir for fun and to expand on how I approach problems, but right now I only associate Erlang with large distributed systems and I want to add other stuff to that association.


> Is there any other use case for Erlang/Elixir?

Yes, the use case is usually for highly concurrent system. There just happen to be quite a few of those in recent years. Multiple things happening at the same time colloquially speaking. Now it won't be good for fast concurrent problems, like say multiplying matrices, or computing FFT, you'd use a GPU and Fortran for that perhaps. But think of large game server with multiple worlds, and players trading with each other. Think of a large distributed database (like Riak). Think of the backend of large VOIP systems with multiple calls happening at the same time. Or maybe a large chat system (Ejabberd).

Erlang as a general purpose programming language is also interesting. It forces you to think about problems in a different way. Actually 2 ways: -- functional and using actors.

Also, its primary characteristic and design goal is fault tolerance. That was #1 item on the TODO list when it was designed. It is one of the very few languages and systems that has that as the primary goal. Many of the other features -- concurrency, isolation, run-time code upgrade, immutability of data structures, kind of fall out of that. So that is another general area that you might consider where using it makes sense.

On types -- many criticize Erlang for not having a static type system. Not all is lost. Erlang has a way to analyze its types using dialyzer. It is a success typing system. http://erlang.org/doc/reference_manual/typespec.html . The more you annotate the code the better it gets. Dialyzer will not catch all the errors BUT when it complains, it is guaranteed to be an error.

To go hand in hand with that. It has very neat (3rd) party testing tools available. One of the most interesting ones are for Property Tests. These allow you to specify model constraint on your code and it will automatically generate tests to try to find failing use cases that break the constraint.

Anyway, hopefully this gives a bit more of an idea.

To go hand in hand with that, on the testing side it has


Your message got cut off.


he forgot to trap exit.


Here is a write up about Elixir by Joe Armstrong (he had a little something to do with Erlang)

http://joearms.github.io/2013/05/31/a-week-with-elixir.html


Parts of it are almost readable!


yeah. nothing like light gray on light gray to make my day...


It's interesting to see Elixir mentioned more and more. I don't _quite_ see the use-case for it, but I'm so content with Erlang I'm almost surely not the audience the language targets. Will be fun to see if Elixir builds its own community or if Elixir folks slowly filter into the Erlang community as a whole.

- - -

EDIT

It occurs to me that the HN crowd might like Lisp Flavored Erlang: http://lfe.github.io/ It's a lisp-2 written by Robert Virding, co-creator of Erlang, and is backed by a great group of folks.


Erlang is awesome, but the syntax is just so out there that it's hard to get used to it when you're usually hacking with Ruby/Python/PHP etc.

If I would be working with a functional language for 8 hours a day, perhaps Erlang wouldn't seem so alien, but I'm not so it is.

Elixir for this reason is truly a godsend, and perhaps with time I can see myself sipping more and more Erlang because of it.


usually hacking with Ruby/Python/PHP etc

Erlang is designed to create solid production systems. If someone is obsessed with quick hacks and fad-of-the-week programming, they will feel uncomfortable in a real development environment.


This seems... harsh to me.

Yeah, so Erlang's syntax is prolog inspired and can seem a little peculiar if you're using Algol inspired languages a lot. I _vaguely_ recall a feeling unfamiliar in Erlang land because of syntax but now, six years in, I hardly care about the syntax of _any_ language. It's just the thing you get used to, like speaking in foreign languages. It's just the water in which you swim.


i don't know from your high horse, but from down here, erlang satisfies my needs for badly written hacks just fine.

more so that all implementations have a in memory DB so i don't even have to bother with that as i would have with php... so yeah, installing yaws and writting <h1>hello world</h1><erl>...</erl> is as PHPish as it gets for quick web prototypes.


the above said, the easy of use of yaws is what makes me reticent to even start to play with elixir. i'd be very pissed it i like it but had to go back to plain erl for web prototypes.



I am not sure if it targets me either but one thing I like is the pretty website and docs... AND that is important to me when I am playing with something new.


Agreed. Docs are fantastically important.


If you liked the nice simple assert, you can get an imitation in Python tests using py.test: http://pytest.org/latest/assert.html

Source code:

    def test_function():
         assert f() == 4
Output:

        def test_function():
    >       assert f() == 4
    E       assert 3 == 4
    E        +  where 3 = f()
Here's how it works: http://pytest.org/latest/assert.html#assert-details -- when importing the test module, all simple asserts are rewritten (which has some limitations if side effects are involved).

No more verbose self.assertTheItemIsInThisList(item, list) at least.


The problems with side effects have been fixed for a while: http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests...


I recently started programming in Elixir. I chose to rewrite the customized Hubot instance I'm running at my company from the ground up in it - it's been a great way to learn the language, and especially OTP.

OTP is really what makes Elixir (and Erlang for that matter) so impressive. Supervised, lightweight processes just seems so obvious as a solution to fault tolerance and concurrency - coming from C#, where doing multi-threaded programming is error-prone at best, Elixir/OTP is a dream. I do miss the type system from C# or Scala, but type specifications help to mitigate the loss.

The one other feature that has been really pleasing to work with is pattern matching. Scala is the only other language I've used with some form of it, and after using Elixir/Erlang's pattern matching, Scala's seems deficient in comparison. It's an insanely powerful construct, I wish more languages had it.


A couple months ago I got into Project Euler and decided to tackle all of the problems with Elixir. It was a great way to learn syntax and performance nuances. Definitely a tool that I enjoy using and will be keeping up with.


    if(condition, do: a, else: b)
looks like a function, but that implies Elixir does lazy evaluation so that only one of a or b gets evaluated. Or is something else going on?


if is a macro.


Edit: The below is actually wrong

> For years I’ve wanted to be able to write my own control flow structures, such as an each...else that runs an else block if the each is empty (Handlebars templates have this).

Actually, python does have a (little-known) `for...else` structure that does what you want.

http://psung.blogspot.ca/2007/12/for-else-in-python.html


python's for/else doesn't do what the grandparent post asked for -- that post asked for the else clause to execute if the container that was being iterated over is empty, and in python's for/else (as your link notes) the else clause executes whenever the for clause terminates normally (that is, other than by a break statement). These are very different constructs.


So it does. I wonder what language I was thinking of then.


This is a long shot, but could you be thinking of the Django template language?

https://docs.djangoproject.com/en/dev/ref/templates/builtins...

    <ul>
    {% for athlete in athlete_list %}
        <li>{{ athlete.name }}</li>
    {% empty %}
        <li>Sorry, no athletes in this list.</li>
    {% endfor %}
    </ul>


Pot, meet kettle. Or whatever the positive version of that is. http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptab...


Someone should probably point out that it's homoiconic too.


I think it's interesting the extent to which lisp is slowly but steadily insinuating itself into people's brains and into new languages.

There are the modern, obvious lisps like Racket and Clojure.

Then there are things like Honu, Pyret, Elixir, and more, which sidestep many people's "parenoia" [sic]. They do the homoiconic, macro thing without any supposedly frightening s-expressions.

Because, as I read this post, I'm thinking, well hell, all of these features [1] are syntactic sugar that already exist in e.g. Racket, and if they didn't, could be added by anyone. Especially anything like "I always wanted this control structure in Python/Ruby/whatever", well, you can just do it. This is really liberating.

Sure you can argue that people will do dumb things with this capability, or that you "don't really need X", and so on. But being able to do it when you need/want is really awesome.

[1] I'm referring to the points in the post, not everything that Elixir and/or Erlang can do.


I'm very interested in Elixir but I'm having trouble understanding the benefit of the 'upcase' example at the end of the article. Compared to a single function with a conversion table, a function per character seems like a tremendous amount of overhead.

Is the purpose of implementing upcase this way to make it more easily parallelizeable in the map/reduce sense?


It's pretty cool.. read the "Okay, but just how metaprogrammable are we talking?" section in this article: http://devintorr.es/blog/2013/06/11/elixir-its-not-about-syn...


How Elixir offer type check - compile time parameter validity check on each specialized types - or similar feature?

Is this type inferencing language?


I suspect it's actually done at runtime. Erlang for instance is dynamically typed, but also has pattern matching. I suspect Elixir is similar.


Learning me some Elixir now and I like it. I wish anonymous functions didn't have different call syntax though.



FWIW, Groovy also has those smart asserts. They're nice. Not a big enough deal that i'd start a feature list with them, but nice.


Groovy seems like such a... Forgotten language, sometimes. For what it's worth, I've always really liked it. And I hate Java with the fire of one thousand suns.


7 months ago, Groovy wasn't even in Tiobe's top 50. Two months ago (Oct 2013), it had reached #18. This month, it's back down to #46. The person who pulled off that trick didn't forget Groovy, and in fact utilized the feedback effect to keep the afterglow going. Just type "Groovy Programming" into Google and see some of the links...

5. www.infoworld.com Groovy breaks into top 20 list of programming languages

8. www.eweek.com Groovy Programming Language Sees Major Boost in Popularity

22. cacm.acm.org Groovy Programming Language Sees Major Boost in Popularity

24. jaxenter.com Groovy makes debut entry into programming language top twenty

30. glaforge.appspot.com Interview about Groovy's popularity boost -- Guillaume Laforge's Blog

But Groovy's "surge in popularity" was probably timed to coincide with a due diligence investigation on Pivotal Inc, or someone there selling a consulting contract.

"After a long discussion with one of the Tiobe index readers, it turned out that the data that is produced by one of the Chinese sites that we track is interpreted incorrectly by our algorithms. So this was a bug," Janssen said. "After we had fixed this bug, Groovy lost much of its ratings." http://www.infoworld.com/t/application-development/c-pulls-a...


Too bad the lists aren't counting lists and are dumb cons cells. :(

Has a cool Leiningen (clojure) inspired build/dependency tool.


There are many things in Elixir that seem to be inspired by Clojure and/or lisp in general (which I think is great, by the way):

* AST-level macros with quote/unquote

* Reducers (efficient list processing)

* Protocols (which are like inside-out interfaces)


The Elixir macros aren't built on homoiconicity though.

Reducers aren't really intended for processing lists, they're best for processing vectors and trees.


Lists are meant to be linked.


That doesn't mean they can't be counted linked lists.


Wow, that center-aligned text is hard to read!


I tried to like Erlang, but the syntax turned me off.

Elixir was just what I needed. Makes the power of Erlang accessible. I like Elixir's docs, tooling, and syntax, and look forward to seeing it progress.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: