Elixir is for programmers(blog.pluralsight.com) |
Elixir is for programmers(blog.pluralsight.com) |
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
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 :)
knewter doesn't know me, and I don't know him.
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/
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.
- - -
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.
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.
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.
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.
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.
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?> 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.
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.
Is the purpose of implementing upcase this way to make it more easily parallelizeable in the map/reduce sense?
Is this type inferencing language?
https://groups.google.com/forum/#!topic/elixir-lang-core/HzU...
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...
Has a cool Leiningen (clojure) inspired build/dependency tool.
* AST-level macros with quote/unquote
* Reducers (efficient list processing)
* Protocols (which are like inside-out interfaces)
Reducers aren't really intended for processing lists, they're best for processing vectors and trees.
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.
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
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>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.
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.