caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Coding style: mixing tabs and spaces in indentation
@ 2016-01-05  9:12 Sébastien Hinderer
  2016-01-05  9:18 ` Francois Berenger
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Sébastien Hinderer @ 2016-01-05  9:12 UTC (permalink / raw)
  To: caml-list

Dear all,

I am wondering whether there are some guidelines that have been proposed
regarding the way OCaml code should be presented?

More specifically: am I correct that it is considered not such a good
practise to mix tabs and spaces in code indentation? And if so, are
there objective reasons for that?

It seems Emacs is configured to do that (mixing tabs and spaces) by
default, can anybody confirm?

Thanks a lot for any hint!

Sébastien.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
@ 2016-01-05  9:18 ` Francois Berenger
  2016-01-05  9:34 ` David MENTRE
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Francois Berenger @ 2016-01-05  9:18 UTC (permalink / raw)
  To: caml-list

On 01/05/2016 10:12 AM, Sébastien Hinderer wrote:
> Dear all,
>
> I am wondering whether there are some guidelines that have been proposed
> regarding the way OCaml code should be presented?
>
> More specifically: am I correct that it is considered not such a good
> practise to mix tabs and spaces in code indentation? And if so, are
> there objective reasons for that?

There are famous hackers who promote the spaces only indentation technique:

https://www.jwz.org/doc/tabs-vs-spaces.html

> It seems Emacs is configured to do that (mixing tabs and spaces) by
> default, can anybody confirm?
>
> Thanks a lot for any hint!
>
> Sébastien.

-- 
Regards,
Francois.
"When in doubt, use more types"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
  2016-01-05  9:18 ` Francois Berenger
@ 2016-01-05  9:34 ` David MENTRE
  2016-01-05  9:55 ` Raphaël Proust
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: David MENTRE @ 2016-01-05  9:34 UTC (permalink / raw)
  To: caml-list

Hello,

Le 05/01/2016 10:12, Sébastien Hinderer a écrit :
> I am wondering whether there are some guidelines that have been proposed
> regarding the way OCaml code should be presented?

Here is an old documentation but a good starting point:
  http://caml.inria.fr/resources/doc/guides/guidelines.en.html

> More specifically: am I correct that it is considered not such a good
> practise to mix tabs and spaces in code indentation?

Yes (and not only for OCaml).

> And if so, are
> there objective reasons for that?

Depending on user, tab size configuration is different (from 2 to 8 or 
more spaces). So another user editing a code is going to see a different 
code layout and break the previous layout when editing it.

Tab should probably be avoided in all coding environment except for very 
specific required cases like Makefiles.

Best regards,
david


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
  2016-01-05  9:18 ` Francois Berenger
  2016-01-05  9:34 ` David MENTRE
@ 2016-01-05  9:55 ` Raphaël Proust
  2016-01-05 13:46 ` Christophe Troestler
  2016-01-05 21:25 ` Hendrik Boom
  4 siblings, 0 replies; 8+ messages in thread
From: Raphaël Proust @ 2016-01-05  9:55 UTC (permalink / raw)
  To: Sébastien Hinderer; +Cc: caml-list

On 5 January 2016 at 09:12, Sébastien Hinderer
<Sebastien.Hinderer@inria.fr> wrote:
> I am wondering whether there are some guidelines that have been proposed
> regarding the way OCaml code should be presented?
>
> More specifically: am I correct that it is considered not such a good
> practise to mix tabs and spaces in code indentation? And if so, are
> there objective reasons for that?

A sane guidelines for mixing both is to use tabs for indentation only
(i.e., indicating how deep in the syntax tree you are) and spaces for
alignment only (i.e., to make the code pretty if you have to break
line in the middle of something). You can find a discussion about it
on http://blog.codinghorror.com/death-to-the-space-infidels/ and some
editor specific hints for emacs
http://www.emacswiki.org/emacs/SmartTabs and vim
http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_spaces (and
more general, search the web for "tab space indent align".)

Basically it gives code like
let numpad =
<tab >[1;2;3;
<tab > 4;5;6;
<tab > 7;8;9;
<tab >   0;
<tab >]

where the tab indicates you are inside the let binding and the spaces
align the numbers in the list so that they look pretty. The code looks
nice for any tabstop value (i.e., any number of space you use to
represent them).


If you ever have to interact with code in a non-monospace environment,
alignment is useless and actually annoying. I used to align my code a
lot, to the point of writing things like

type t = {
       x: int  ;
       y: int  ;
   width: int  ;
  height: int  ;
   color: color;
}

but I don't anymore. I just indent and focus on readability more than
prettiness.


One thing to keep in mind is that merlin uses indentation as a hint
for recovering from parsing errors. The more "correct" your
indentation is, the easiest it will be for merlin to recover.


Cheers,
-- 
______________
Raphaël Proust

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
                   ` (2 preceding siblings ...)
  2016-01-05  9:55 ` Raphaël Proust
@ 2016-01-05 13:46 ` Christophe Troestler
  2016-01-05 15:36   ` Drup
  2016-01-05 21:25 ` Hendrik Boom
  4 siblings, 1 reply; 8+ messages in thread
From: Christophe Troestler @ 2016-01-05 13:46 UTC (permalink / raw)
  To: OCaml Mailing List; +Cc: Sebastien.Hinderer

On Tue, 5 Jan 2016 10:12:24 +0100, Sébastien Hinderer wrote:
> 
> Dear all,
> 
> I am wondering whether there are some guidelines that have been proposed
> regarding the way OCaml code should be presented?
> 
> More specifically: am I correct that it is considered not such a good
> practise to mix tabs and spaces in code indentation? And if so, are
> there objective reasons for that?
> 
> It seems Emacs is configured to do that (mixing tabs and spaces) by
> default, can anybody confirm?

Indeed.  You have to put

    (setq-default indent-tabs-mode nil)

in your ~/.emacs.d/init.el file.

Best,
C.


P.S. If there is a consensus on this list that TABs shouldn't be used for OCaml code, I can enable this for OCaml files in Tuareg.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05 13:46 ` Christophe Troestler
@ 2016-01-05 15:36   ` Drup
  2016-01-05 15:42     ` Simon Cruanes
  0 siblings, 1 reply; 8+ messages in thread
From: Drup @ 2016-01-05 15:36 UTC (permalink / raw)
  To: Christophe Troestler, OCaml Mailing List; +Cc: Sebastien.Hinderer

Well, there is an implicit consensus, it's called ocp-indent ....

Le 05/01/2016 14:46, Christophe Troestler a écrit :
> On Tue, 5 Jan 2016 10:12:24 +0100, Sébastien Hinderer wrote:
>> Dear all,
>>
>> I am wondering whether there are some guidelines that have been proposed
>> regarding the way OCaml code should be presented?
>>
>> More specifically: am I correct that it is considered not such a good
>> practise to mix tabs and spaces in code indentation? And if so, are
>> there objective reasons for that?
>>
>> It seems Emacs is configured to do that (mixing tabs and spaces) by
>> default, can anybody confirm?
> Indeed.  You have to put
>
>      (setq-default indent-tabs-mode nil)
>
> in your ~/.emacs.d/init.el file.
>
> Best,
> C.
>
>
> P.S. If there is a consensus on this list that TABs shouldn't be used for OCaml code, I can enable this for OCaml files in Tuareg.
>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05 15:36   ` Drup
@ 2016-01-05 15:42     ` Simon Cruanes
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Cruanes @ 2016-01-05 15:42 UTC (permalink / raw)
  To: Drup; +Cc: Christophe Troestler, OCaml Mailing List, Sebastien.Hinderer

[-- Attachment #1: Type: text/plain, Size: 1570 bytes --]

Anecdotally, this was recently on hacker news:

http://ukupat.github.io/tabs-or-spaces/

the OCaml part shows that most OCaml repos on github use 2 spaces, some
use 4 spaces, and very few use tabs.

Le Tue, 05 Jan 2016, Drup a écrit :

> Well, there is an implicit consensus, it's called ocp-indent ....
> 
> Le 05/01/2016 14:46, Christophe Troestler a écrit :
> >On Tue, 5 Jan 2016 10:12:24 +0100, Sébastien Hinderer wrote:
> >>Dear all,
> >>
> >>I am wondering whether there are some guidelines that have been proposed
> >>regarding the way OCaml code should be presented?
> >>
> >>More specifically: am I correct that it is considered not such a good
> >>practise to mix tabs and spaces in code indentation? And if so, are
> >>there objective reasons for that?
> >>
> >>It seems Emacs is configured to do that (mixing tabs and spaces) by
> >>default, can anybody confirm?
> >Indeed.  You have to put
> >
> >     (setq-default indent-tabs-mode nil)
> >
> >in your ~/.emacs.d/init.el file.
> >
> >Best,
> >C.
> >
> >
> >P.S. If there is a consensus on this list that TABs shouldn't be used for OCaml code, I can enable this for OCaml files in Tuareg.
> >
> 
> 
> 
> -- 
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


-- 
Simon Cruanes

http://weusepgp.info/
key 49AA62B6, fingerprint 949F EB87 8F06 59C6 D7D3  7D8D 4AC0 1D08 49AA 62B6

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
  2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
                   ` (3 preceding siblings ...)
  2016-01-05 13:46 ` Christophe Troestler
@ 2016-01-05 21:25 ` Hendrik Boom
  4 siblings, 0 replies; 8+ messages in thread
From: Hendrik Boom @ 2016-01-05 21:25 UTC (permalink / raw)
  To: caml-list

On Tue, Jan 05, 2016 at 10:12:24AM +0100, Sébastien Hinderer wrote:
> Dear all,
> 
> I am wondering whether there are some guidelines that have been proposed
> regarding the way OCaml code should be presented?
> 
> More specifically: am I correct that it is considered not such a good
> practise to mix tabs and spaces in code indentation? And if so, are
> there objective reasons for that?
> 
> It seems Emacs is configured to do that (mixing tabs and spaces) by
> default, can anybody confirm?

It used to be (I'm talking 1960's and 70's here) that the standard was 
for a tab to be  equivalent to eight spaces.

No problem mixing tabs and spaces then.

But when people started programming a lot in C instead of assembler, 
the problem arose.  The recommended style was to use tabs for 
indentation.  The result was functions with very short lines of actual 
code when control structure was significantly nested.  Of course the 
style gurus would say that you had to break functions up at that point 
and that this wasa a useful indication that your indentation was too 
deep.  But many thought differently about style and started to indent 
less aggressively, perhaps two, four or even three spaces for each 
indent.  And to make that easy, they would set tab stops accordingly.

The result was that if tabs and only tabs were used for indentation, it 
would format nicely whatever your tab stop settings, and if spaces and 
only sppaces were used, it would also format nicely.  But if they were 
mixed, you would get a total mess if the tab width in the display were 
diffferent for that used when coding.

-- hendrik


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-05 21:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05  9:12 [Caml-list] Coding style: mixing tabs and spaces in indentation Sébastien Hinderer
2016-01-05  9:18 ` Francois Berenger
2016-01-05  9:34 ` David MENTRE
2016-01-05  9:55 ` Raphaël Proust
2016-01-05 13:46 ` Christophe Troestler
2016-01-05 15:36   ` Drup
2016-01-05 15:42     ` Simon Cruanes
2016-01-05 21:25 ` Hendrik Boom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).