News for hackers. Stuff that matters.
Re:Programming Rules and Conventions by peteretep on Monday February 04, 2013 @11:28AM (#5164960)
Although the examples are in Erlang, none of this seems particularly Erlang-specific
Re:Programming Rules and Conventions by banachtarski on Monday February 04, 2013 @01:28PM (#5165983)
This isn't true.

For example:

3.13 Do not program "defensively" suggests that the programmer should allow functions to crash if given unhandled input types. This does not work in most other programming languages to create a fault tolerant application.

A number of advice points about process/module organization also do not apply to most languages.

Tagging messages? Makes sense in lisp (and a few others), but again, not in most languages

Not to trap exits, again Erlang specific.

I could go on and on. Did you even read this?

Re:Programming Rules and Conventions by tbe on Wednesday February 06, 2013 @02:07AM (#5175267)
> 3.13 Do not program "defensively" suggests that the programmer should allow functions to crash if given unhandled input types. This does not work in most other programming languages to create a fault tolerant application.

Incidentally, this applies to languages with exceptions as well. The hardest to catch bugs are when bad behaviour is hidden inside a too general try/catch.

> Not to trap exits, again Erlang specific.

Yes.

Re:Programming Rules and Conventions by jlouis on Monday February 04, 2013 @10:33AM (#5164580)
This reference is full of sound advice for the new Erlang programmer. If you break it, you need to have a good reason to do so.

Also the seasoned Erlang programmer will find it useful.

Re:Programming Rules and Conventions by jweir on Monday February 04, 2013 @10:25AM (#5164527)
Don't allow private data structure to "leak" out of a module offers a great example in module, type, or even class design.
Re:Programming Rules and Conventions by adrianmsmith on Monday February 04, 2013 @03:43PM (#5166975)
I saw this, and was reminded that OO languages have language constructs to enforce this, i.e. the "private" keyword.

If you want to make something private (e.g. your internal implementation) it's better to make it private (resulting in an error if someone accesses it) than to make it public, and write a rule in section 3.11 of a convention document and hope everyone using your code has read it and obeys it.

Re:Programming Rules and Conventions by qu4z-2 on Monday February 04, 2013 @06:17PM (#5167915)
Except that the rule there is equally applicable to OO languages, and is more about what you should and shouldn't expose in your interface.
Re:Programming Rules and Conventions by loup-vaillant on Monday February 04, 2013 @06:53PM (#5168098)
3.1 Export as few functions as possible from a module — 3.2 Try to reduce intermodule dependencies

At last a coding convention guide that deals with something other than syntax. And at the very beginning to boot. If I ever have a say to such things at work, I'm going to take some inspiration from that.

Re:Programming Rules and Conventions by informatimago on Monday February 04, 2013 @01:44PM (#5166094)
How good can a programming language with such a long and complex programming rules and conventions book be?
Re:Programming Rules and Conventions by vemv on Monday February 04, 2013 @01:59PM (#5166211)
In fact many of the listed practices are common to all programming languages.
Re:Programming Rules and Conventions by vemv on Monday February 04, 2013 @01:29PM (#5165986)
Why not program defensively?
Re:Programming Rules and Conventions by banachtarski on Monday February 04, 2013 @01:31PM (#5166002)
This is a basic tenet of erlang. The philosophy is that if the inputs are bad, don't try to handle it. Crash the process to isolate the issue from the rest of the system (and god forbid, your database). Erlang's supervisor trees will restart the process for you.
Re:Programming Rules and Conventions by vemv on Monday February 04, 2013 @01:51PM (#5166145)
Well that was unexpected! It makes me curious about the Erlang way. Thanks for the reply.
Re:Programming Rules and Conventions by banachtarski on Monday February 04, 2013 @04:42PM (#5167345)
One of the other comments mentions validating user inputs which makes sense and is an exception to my comment above.

For the most part though, my comment stands, and it is, indeed one of the more unique and charming aspects of erlang.

Re:Programming Rules and Conventions by rcirka on Monday February 04, 2013 @01:54PM (#5166163)
It depends on the scenario. Web services or user interfaces accepting user input should be validated. However, in deeper code, it is better to let the system throw an exception and let the client handle it. Otherwise, how would the client know the method failed? Also, it is easier to debug behavior if a system throws an exception, rather than hiding the error.
Re:Programming Rules and Conventions by koenigdavidmj on Monday February 04, 2013 @02:52PM (#5166624)
You should...at the inputs to your system. Check the data when it enters your control. After it enters your code it's almost always possible to statically ensure that the data meets your invariants (hopefully they're well documented). Thus, programming defensively at this point doesn't do anything but slow the system down by adding redundant checks.