Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang coding standards and good practices [closed]

My team is learning some Erlang in my new job. Right now we have some code made, but the code is beginning to get a little messy and not consistent.

I'd like to know if there are coding standards that are followed by the Erlang community and can be used as a baseline. Things like how to indent, naming of variables and functions, how to structure modules, etc.

Also, is there any tool that will check those parameters? I am thinking in PEP8 or PyFlakes in the Python world. I use vim and it will detect syntax errors, which is nice, but I'd like to take it a little further and try to keep a good, consistent style that we can share and make the code more readable.

UPDATE: About the comment by Kemal, I must say that is very interesting (and we'll make good use of it) but does not cover completely the subject. My problem is to convince a team to use a consistent code style, as consistent as possible. A good way of convince everyone is to use a coding style that is recommended by the Erlang community. Maybe it doesn't exist, but I'd like to try as simple things, like choosing CameCase over Underscored_words can greatly help to give the code a consistent look and helps readability.

like image 363
Khelben Avatar asked Apr 26 '12 13:04

Khelben


2 Answers

Well, there is this http://www.erlang.se/doc/programming_rules.shtml. It's pretty comprehensive.

like image 197
Kemal Fadillah Avatar answered Nov 11 '22 06:11

Kemal Fadillah


I don't know of one. Which is more readable to you? This:

init([]) ->
   AChild = {'AName',{'AModule',start_link,[]},
         permanent,2000,worker,['AModule']},
   {ok,{{one_for_all,0,1}, [AChild]}}.

or this:

init([]) ->
   AChild = {
      'AName',
      {'AModule', start_link, []},
      permanent,
      2000,
      worker,
      ['AModule']
   },
   {
      ok, 
      {
         {one_for_all,0,1}, 
         [AChild]
      }
   }.

or this:

init([]) ->
   AChild = { 'AName'
            , {'AModule', start_link, []}
            , permanent
            , 2000
            , worker
            , ['AModule'] }
   { ok, 
      { {one_for_all,0,1}
      , [AChild] } }.

I like the last one, but consistency is most important. So I suggest defining a standard that works for you.

like image 43
dsmith Avatar answered Nov 11 '22 06:11

dsmith