Stok Footage

Continually experimenting with new ideas and techniques — Reconstructing, Developing, Modernising.

Reasons to be Cheerful, Part 3 — Part 1

Parts one and two of the three reasons are Perl and Ruby, and it’s probably no surprise to anyone who knows me that Elixir is part three!

Over the past few weeks I’ve actually been participating in the Elixir world, and I have been re-energised by that engagement. So much so that I’d rather be learning Elixir and contributing than writing blog posts — so this post will be the first of a series of posts so I can actually get something written…

One of my frustrations with Perl and Ruby is that they let you build strings either using double quotes (if you want to do various kinds of interpolation or escaping) or single quotes (which have a couple of escapes). This means people’s coding style was often based on the idea that “I’ll use single quotes if I don’t need interpolation, double if I do” based on the idea that it’s maybe fractionally faster for the parser to process single quoted strings than double quoted strings. This makes enforcing style more problematic, especially as requirements change and also because I strongly prefer double quotes everywhere whenever possible. In Elixir there is a real difference between single and double quoted strings: the former returns a list, and the latter a binary; there’s a significant difference between the quoting which makes the choice of quotation style more intention revealing.

A similar problem I have with Perl and Ruby is the difference between &&, ||, and ! and and, or, and not. In Perl and Ruby there’s a difference in precedence, but they do the same thing, so if someone has a preference for using not rather than ! then they can cause problems when they change one to the other without considering the precedence and possible need for parentheses to keep the logical meaning unaltered. In Elixir and, or, and not expect to operate strictly on :true or :false, but &&, ||, and ! operate on “truthy” values where :nil and :false are considered false and everything else is considered true. Once again I find Elixir to be much more intention revealing.

These are just a couple of ways in which I think José Valim’s choices show him to be a great language designer.

As for the title of the post, see this Wikipedia article.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *