On Erlang's Syntax
ferd.ca
ferd.ca
In short, if you've got two records in a list, and forget to end the first one with the comma line ending, the behavior becomes a bit unpredictable.
[
#myrecord{
field1="whatever",
field2=123
}
#myrecord{
field1="booyah",
field3=3.14
}
].
That statement would mysteriously return a list with a single element: [ #myrecord{field1="booyah", field2=123, field3=3.14 } ]
And all because of the missed comma after the first #myrecord { }.What's happening can be visualized by the (sort of) equivalent version here:
R1 = #myrecord{
field1="whatever",
field2=123
},
[
R1
#myrecord{
field1="booyah",
field2=3.14
}
].
So you can see that the second #myrecord is overwriting the values in R1, since you can do syntax like R1#myrecord{ ... } to take the values of R1, and overwrite them with whatever you need to.The reason that happens is due to a compiler change a while back to make record syntax no longer require being wrapped in parens. This is due to having records with values in them being records, and it makes it easier to access those records.
For example:
Mybook#book.author#author.name
Which is an OOP language's equivalent of something like: Mybook.author.name
This previously used to be required to be written like this (correct me if I'm wrong, this syntax is before my time): ((Mybook#book.author)#author.name).
Which removed ambiguity. Errors like my first example then would be caught by the runtime if records were written in the "old" style: [
(#myrecord{
field1="whatever",
field2=123
})
(#myrecord{
field1="booyah",
field3=3.14
})
].
Will generate an invalid function error (still not a great error, but it makes sense in this regard.My hope is that this class of error caused by the syntax will be somewhat minimized if Ericcson decides to merge the erlson[1] project into an official release of Erlang, replacing the somewhat clunky record syntax with something a little more "modern".
[1] https://github.com/alavrik/erlson - An object notation for Erlang, but which in order to be a decent record replacement will need to support pattern matching.
All in all, I pretty much love Erlang's syntax. It's the perfect mix of readability, terseness and structure; and it has that cozy nerd-air about it, the one that makes you want to sit up all night dishing out code.
[0]: https://github.com/josevalim/elixir
[1]: http://reia-lang.org/ (abandoned; author points user to Elixir now)
Semantics is important.
If you think about a piece of code you should have AST's in your mind anyway -- not strings of characters.
In particular, one place where Erlang gets in your way is if you swap two lines of code, there's a good chance you'll have to check the "ant turd token" at the end of the line, and change it.
It's certainly not an insurmountable difficulty, but it is an annoyance.
It's not that big a deal, and the language has lots of other great qualities, so I wouldn't get too hung up on it, but it's not fair to say it's not irritating.
syntax is a language's UI, thoughtful, clean and consistent design matters...
Also, would you rather code brainfuck or C using pointers (both being semantically identical)? ;)
I really struggle just reading Ruby now - and it was my main language for a couple of years.
Writing Ruby - nae chance...
Do any C/C++ developers #include<iso646.h> so they can use and, or, and not as friendly operator names? This seems like a simple step for prettier C code, but I have never seen it in practice.