Re:On Erlang's Syntax
by chops on Thursday December 22, 2011 @01:25PM
(#3382626)
Note that while I generally like the Erlang syntax, there's one main issue where syntax quirks come back to bite me: the combination of Erlang records with a missed line ending. This topic comes up on occasion on the mailing list and apparently it's a side effect of a change that was made to make Erlang records a little easier to work with.
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.
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:
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.
Re:On Erlang's Syntax
by gurraman on Thursday December 22, 2011 @10:33AM
(#3381809)
I used to dislike the use of different punctuation characters as they make it "difficult" to re-arrange code. I've, however, grown to love them as they are very explicit and gives the reader a good indication on what will happen next (f. ex. an alternate function clause).
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.
Re:On Erlang's Syntax
by waffle_ss on Thursday December 22, 2011 @09:26AM
(#3381580)
Coming from Ruby, I was pretty excited to see Elixir[0] (and before that, Reia[1]), a language that runs on the Erlang VM but is more approachable for me syntactically and that adds some interesting features. I think it's worth checking out for anyone who wants to 'learn them some Erlang' over winter break.
Re:On Erlang's Syntax
by davidw on Thursday December 22, 2011 @10:31AM
(#3381796)
Disagree completely: the language is there to make programming the computer easier for me, the human. If I have to parse it in my head, it has failed at that, at least for 'everyday use'.
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.
Re:On Erlang's Syntax
by tlack on Thursday December 22, 2011 @01:20PM
(#3382611)
Honest question: do you find yourself really thinking about a languages syntax after you've spent 40-50 hours coding in it? To me it kind of fades into the background, becomes hard wired in my brain. (I'm not suggesting I'm an awesome coder or anything of course)
Re:On Erlang's Syntax
by davidw on Thursday December 22, 2011 @04:40PM
(#3383411)
Mostly, yes, but the line endings in Erlang fail the "don't make me think" test. They make you stop and look and make sure everything is in the right place.
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.
Re:On Erlang's Syntax
by waffle_ss on Thursday December 22, 2011 @01:57PM
(#3382744)
Well according to the Elixir docs it does make a bit of difference in terms of homoiconicity[0] (that famous Lisp property of code=data, data=code), which makes meta-programming easier.
Also, would you rather code brainfuck or C using pointers (both being semantically identical)? ;)
Re:On Erlang's Syntax
by sausagefeet on Thursday December 22, 2011 @02:20PM
(#3382857)
Erlang syntax might look weird at first, if coming from Ruby/Python, but I think you're giving up too early. Yes, Erlang looks different, but after an hour of playing with it you come to realize one important thing: the syntax is weird but there is an incredibly small amount. Relative to languages like Python and Java, Erlang has a small syntactic footprint. Relative to C++ you need a logarithmic graph.
Re:On Erlang's Syntax
by cpeterso on Thursday December 22, 2011 @11:08AM
(#3381952)
This syntax isn't any less weird than C's &&, ||, and ; operators. :)
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.
Re:On Erlang's Syntax
by sausagefeet on Thursday December 22, 2011 @02:21PM
(#3382862)
I've been writing C/C++ before and thought it would be nice to use those forms of the operators, but having never ever seen C++ code that does I wonder if I'm setting myself to be made fun of.
Re:On Erlang's Syntax
by cpeterso on Thursday December 22, 2011 @10:43PM
(#3384529)
I guess it's a slippery slope. If people #define and && then someone else will #define then { and #define endif }. Everyone will have their own silly dialect. In fact, that is not unlike the current state of C++ usage..
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.
That statement would mysteriously return a list with a single element: And all because of the missed comma after the first #myrecord { }.What's happening can be visualized by the (sort of) equivalent version here:
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:
Which is an OOP language's equivalent of something like: This previously used to be required to be written like this (correct me if I'm wrong, this syntax is before my time): Which removed ambiguity. Errors like my first example then would be caught by the runtime if records were written in the "old" style: 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.
Also, would you rather code brainfuck or C using pointers (both being semantically identical)? ;)
[0]: http://en.wikipedia.org/wiki/Homoiconic
syntax is a language's UI, thoughtful, clean and consistent design matters...
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.