Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  Indentation Standard

Mazen
Posted: Thu Jul 20, 2006 4:55 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Maybe considered something less important, but atleast I like standards so that indentation between different editors becomes readable... Question is: Is there any documented "standard" for indentation in Erlang? if not, what about the other functional languages, do they have it?
View user's profile Send private message
francesco
Posted: Fri Jul 21, 2006 11:49 am Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
The defacto standard is defined by how Emacs indents Erlang. The majority of erlang programmers use Emacs, so it makes sense to go that route.

On a curios side issue.. AxD301 guidelines state that you may use any editor you like, but indentation has to be emacs one. So the few survivors hack in vim/vi, load their code in emacs to indent it, and then check it in Very Happy .

Francesco
View user's profile Send private message Visit poster's website
garazdawi
Posted: Mon Jul 24, 2006 5:14 pm Reply with quote
User Joined: 10 Jul 2006 Posts: 20
The problem with the Emacs indentation as I see it is that it uses "halftabs" i.e. when you make the first indentation it uses four spaces and then the next indent it uses a proper tab.

function() ->
(space)(space)(space)(space)case ok of
(tab)error ->
(tab)(space)(space)(space)(space){error,error}
(space)(space)(space)(space)end.


I have never been able to understand why they don't just set the tab size to 4 spaces and use tabs everywhere instead of working with the "halftabs". The only reasons which I can think of is lazyness or that they want to force you to use Emacs. Anyone know the real reason?

_________________
Erlang Training & Consulting
View user's profile Send private message
oscarh
Posted: Wed Jul 26, 2006 7:56 am Reply with quote
User Joined: 20 Jul 2006 Posts: 22
what emacs will use for tabs can be configured by the user, and thus not really a good standard instrument Razz
View user's profile Send private message
michal
Posted: Wed Jul 26, 2006 5:01 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 44 Location: London
garazdawi wrote:
I have never been able to understand why they don't just set the tab size to 4 spaces and use tabs everywhere instead of working with the "halftabs". The only reasons which I can think of is lazyness or that they want to force you to use Emacs. Anyone know the real reason?


I don't know the reason, but I would rather stay with the tab 8 spaces wide. Otherwise reading through OTP code is much harder...

It is nice to work in the editor that automatically indents the code every time when you press the tab key, but I think it should use only spaces not halftabs.

Does vim have any automatic indentation policy?
View user's profile Send private message
oscarh
Posted: Thu Jul 27, 2006 8:54 am Reply with quote
User Joined: 20 Jul 2006 Posts: 22
michal wrote:
Does vim have any automatic indentation policy?



In vim you set either the option expandtabs or noexpandtabs. With expandtabs, spaces will be inserted instead, using as many as indicated by the variable shiftwidth. If noexpandtabs is set, a tab key will result in a tab character. However, if you do indentation, it is up to the plugin (or user) to make sure that no "halftabs" are inserted, since the indentation level is given in ammount of spaces (calculated from shiftwidth usually).
View user's profile Send private message
martin
Posted: Sun Aug 06, 2006 11:53 am Reply with quote
User Joined: 06 Aug 2006 Posts: 11
michal wrote:
It is nice to work in the editor that automatically indents the code every time when you press the tab key, but I think it should use only spaces not halftabs.


Well you can always insert (setq-default indent-tabs-mode nil) in your .emacs file Smile
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum