[erlang-questions] Trying to learn the Erlang Way
Fri Feb 7 16:35:54 CET 2014
On Fri, Feb 7, 2014 at 8:47 AM, kraythe . <kraythe@REDACTED> wrote:
> Man I feel silly. but then I am fighting a chest cold. I guess this happens
> easier when you don't have completion or highlighting that I am used to in
> an IDE.
But seriously, every programmer knows the feeling of at once being
certain something's wrong with the compiler/VM and then realizing the
obviousness of his or her mistake. You'll pick up quickly where to
look for the common sources of these.
Fred's comments on function naming are spot on - lower camel case is
almost never ever seen in Erlang and really stands out in a bad and
distracting way. I know this sounds religious, and it is, but it's the
True Religion, so it's fine.
Having very, very focused functions helps a lot both in writing a
program (it forces the programmer to make things obvious in code,
which is very hard to do but an excellent way to prove you understand
exactly what problems you're solving) and to debug a program (it's
hard for problems to lurk in obvious code).
This blog post says what I mean:
It's also True Religion, so it's fine. 
In cases where you really need to step through code (I think these are
rare, especially if you follow the obviousness rule) the function
tracing tools in Erlang are fantastic. Reid Draper happened to have
just presented a great tracing tool called redbug at the Chicago
Erlang User Group this Wednesday:
I've historically used e2's e2_debug module:
I'll might switch to redbug because it stops tracing automatically
after a period of time or number of traces, which is super great for
use in production systems. e2_debug is fine for local dev however --
and it's output is IMO much easier to read.
While you can use the Erlang visual debugger to step through code, I
personally find this time consuming and awkward and prefer to trace.
Problems in Erlang often come down to unexpected patterns that sneak
into a call chain, which are easy to spot through tracing.
Best of luck!
 There is one stylistic change that I would recommend, vis-a-vis
that blog post, which is to *selectively* use variables to pull
important, side effecty operations out of nested function calls so
that they appear earlier in the function (western style top-down,
left-right reading) and get named results (via variable binding). So,
FirstResult = do_something_first()
God names are essential - these are terrible names, but you get the idea.
Do this only when it makes the code more obvious.
Richard O'Keefe pointed this out to me originally and, of course, he's right.
More information about the erlang-questions