Hacker News new | ask | show | jobs
by kenko 4105 days ago
How did you arrive at any of those conclusions?

That doesn't strike me as a very straightforward interpretation of the offhand reference to the syntax's being natural, made without any further comment. Nor do I see why "def" being a macro makes the syntax "natural in its representation" (or even what you mean by that).

Just as a test: if that is what he meant by the syntax's being natural, he should be willing to claim that the syntax of Scheme is at least as natural.

1 comments

Usually, when people talk about Elixir's syntax being natural, they go on to contrast it against either Erlang, which is known for having some odd syntax quirks such as having to end lines with different punctuation marks depending on context (something that can make changing or refactoring code difficult -- although, tbf, Erlangers have tooling that does help with this), or Lisps like Clojure, from which Elixir takes many ideas (it's macro system and the idea of the AST being normal language data types, it's protocols, etc). In fact, I've seen "natural syntax" defined as something like: functions are called like this: `my_function(arg1, arg2)`, and with operators so that numbers are used naturally, as in mathematics, like: `1 + 2` in contrast with lisps where function calls are like `(my_function arg1 arg2)` and math becomes `(+ 1 2)`. I do not know if this is any kind of technical definition, or just one that's been internalized by the Elixir community to some extent (I've seen it repeated in at least two or three places) but that's my guess as to what the author meant.

While Elixir may appear similar to Ruby syntactically, because of it's `do, end` blocks, that similarity is actually somewhat superficial. In reality, a Rubyist will only feel slightly more comfortable with Elixir's syntax than someone coming from another imperative language, for a couple reasons. One, Elixir's usage of do/end is far more regular than in Ruby, where `do/end` have a very specific meaning, and two, the differences from Ruby syntax (defmodule, defstruct, fn -> end, |>, calling anonymous functions) are actually greater than the similarities. But I think both the Rubyist and the (Javascript, C, Go, Python) programmer will find Elixir's syntax more natural than they would find the syntax of many other functional languages.

Of course, at the end of the day, our intuitions and feelings about syntax are quite subjective, and syntax is a very tricky thing because of this.

I can't say for sure what the author meant by natural syntax of course, but this would be my guess, based on how I've seen the term used in other descriptions of the language.

I'm curious what language background you come from, and whether there are particular things about elixir's syntax you found unnatural, difficult or uncomfortable?