[erlang-questions] A style question

Joe Armstrong erlang@REDACTED
Mon Feb 15 12:05:20 CET 2010


On Fri, Feb 12, 2010 at 4:02 PM, David Mercer <dmercer@REDACTED> wrote:
>> But is this just prejudice on my part, or is there a reason why inserting
>> an opaque name like "F" is a good idea?
>
> I might assign a value to a variable for documentation purposes.  In this
> specific example, though, the name "F" seems to fail as a description of
> purpose, so it probably doesn't fall into that category.  Suppose, however,
> that it were something like
>
>        UpdateTheFebblebrokker = fun() -> ...
>        Mnesia:transaction(UpdateTheFeeblebrokker)

Oh no not another
HorrendouslyLongVariableNameThatCluttersUpTheCodeSoCantSeeTheCode

I started programming when punched cards had 80 columns. Long variable
names would
have made the cards lighter, by might need more cards, making it more
difficult to
transport the program from the punched card machines to the computer room.

<< then a mere four hour wait to see if your program compiled >>

It was written in the scrolls, by the old ones, possible by the great
Daniel D.McCracken himself,
that I,J,K,N were always integers, R was real and so on.

Having written about 100K lines of FORTRAN (blessed be it's memory)
these rules are
firmly etched into the base of my spine, wherefrom the control of my
fingers eminates.

In Erlang this is still true but F is always a function H and T are
alway the head and tail of a list.
and L something is always a list. T is not a tuple (of course, because
it's the tail of a list, silly)

I hate long variable name because they clutter up the code.
So I use "abbreviated camel variables + comments"

  %% UTF = UpdateTheFebblerokker
   UTF = fun() -> ...
   Mnesia:transaction(UTF)

  "UpdateTheFebblerokker" has 21 characters. So the first version uses
2*21 (42) characters to communicate the
name.

  The second version uses 21 + 3 * 3 (30) characters to communicate the name.
  So my version is 12/42 (29%) more abstract).

The amount of work my brain has to do to understand this is 29% less.
If you reused the name
twice then the gain would be 3*21 :: 21 + 4*3 = 63::33 (48% more abstract)

You'd also need a comment explain what a Febblerokker is. I think it's
some kind of
DoppleKlonkerSubWogiLuple but this is from memory, it's a long time
since I worked with this kind of
stuff.

Cheers

/Joe

>
> Then it might server as a form documentation, written with the optimistic
> assumption that the compiler will optimize the assignment away.
>
>> The indentation style I would use here just takes 4 columns, not 12.
>
> I would love to hear about different indentation styles, and specifically
> yours.  I find properly indenting Erlang to be the most difficult part of
> the language.
>
> Cheers,
>
> David
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list