Wed Dec 17 01:02:57 CET 2003
From: "Bengt Kleberg" <Bengt.Kleberg@REDACTED>
> Robert Virding wrote:
> > 2. As Dr. Joe (again congratulations Joe) points out "a+42" IS LEGAL ERLANG! Sorry for shouting but the point must be stressed. How can any one seriously suggest that the compiler disallow legal code? You are actually changing the semantics of the language when you do this. Are you aware of this fact?
> i did not know ''a+42'' was legal. i thought it generated an error.
It is a perfectly legal expression but when evaluated it generates an error. As errors are a part of Erlangs semantics you can't go and just eliminate any expression which might generate one. If you do that then you are changing the semantics of the language. Also doing it in an ad hoc way in the compiler by catching expressions which just happen to be easy to detect would be very confusing. I mean why flag a+42 and not A=a,A+42 which is also very simple and just as likely to cause an error. A compiler should disallow illegal code, do its best with legal code and try to be helpful by warning about legal, but potentially confusing or with misleading results, code or constructions.
That is why the compiler's warnings should stay as warnings and never become errors.
> presumably you do not suggest putting a+42, without any explanation,
> into the source?
Well, it's pretty obvious that if you write something like a+42 in your code then you're intending it to fail. I mean there are limits. :-) I usually document code which is not plainly obvious and which I feel I might have difficulty remembering what it did at a later date, or does something tricky and smart. This and a comment at the beginning of the function usually suffices. I am of the opinion that having to many comments tends to make everything difficult to read. Also having a comment standard helps to keep comments short. Read through the compiler and parts of the libraries (the more basic ones) to see how I code.
More information about the erlang-questions