caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Raphaël Proust" <raphlalou@gmail.com>
To: "Sébastien Hinderer" <Sebastien.Hinderer@inria.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Coding style: mixing tabs and spaces in indentation
Date: Tue, 5 Jan 2016 09:55:26 +0000	[thread overview]
Message-ID: <CAAmHUAmpjz+tEE6x11VdZXv9e-ZxQ4Rhjy5VK1PLVc=3GH=6kw@mail.gmail.com> (raw)
In-Reply-To: <20160105091224.GA10087@pl-59055.rocqadm.inria.fr>

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

  parent reply	other threads:[~2016-01-05  9:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-05  9:12 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAmHUAmpjz+tEE6x11VdZXv9e-ZxQ4Rhjy5VK1PLVc=3GH=6kw@mail.gmail.com' \
    --to=raphlalou@gmail.com \
    --cc=Sebastien.Hinderer@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).