unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] STYLE: Initial draft of coding style document
@ 2012-01-27 23:46 David Bremner
  2012-01-30 14:38 ` Tomi Ollila
  0 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2012-01-27 23:46 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@debian.org>

This was edited by (at least) Austin, Tomi, and myself.
---
 devel/STYLE |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 devel/STYLE

diff --git a/devel/STYLE b/devel/STYLE
new file mode 100644
index 0000000..7ef3209
--- /dev/null
+++ b/devel/STYLE
@@ -0,0 +1,87 @@
+C/C++ coding style
+==================
+
+Tools
+-----
+
+There is a file uncrustify.cfg in this directory that can be used to
+approximate the prevailing code style. You can run it with e.g.
+
+   uncrustify --replace -c devel/uncrustify.cfg foo.c
+
+You still have to use your judgement about accepting or rejecting the
+changes uncrustify makes. With a nice git frontend, you can add the
+lines you agree with and reject the rest.
+
+For Emacs users, the file .dir-locals.el in the top level source
+directory will configure c-mode to automatically meet most of the
+basic layout rules.  I
+
+Indentation, Whitespace, and Layout
+-----------------------------------
+
+The following nonsense code demonstrates many aspects of the style:
+
+static some_type
+function (param_type param, param_type param)
+{
+   int i;
+
+   for (i = 0; i < 10; i++) {
+       int j;
+
+       j = i + 10;
+
+       some_other_func (j, i);
+   }
+}
+
+* Indent is 4 spaces with mixed tabs/spaces and a tab width of 8.
+  Tabs should be only at the beginning of the line.
+
+* Use copious whitespace.  In particular
+   - there is a space between the function name and the open paren in a call.
+   - likewise, there is a space following keywords such as if and while
+   - every binary operator should have space on either side.
+
+* No trailing whitespace. Please enable the standard pre-commit hook
+  in git (or an equivalent hook).
+
+* The name in a function prototype should start at the beginning of a line.
+
+* Opening braces "cuddle" (they are on the same line as the
+  if/for/while test) and are preceded by a space. The opening brace of
+  functions is the exception, and starts on a new line.
+
+* Comments are always C-style /* */ block comments.  They should start
+  with a capital letter and generally be written in complete
+  sentences.  Public library functions are documented immediately
+  before their prototype in lib/notmuch.h.  Internal functions are
+  typically documented immediately before their definition.
+
+* Code lines should be less than 80 columns and comments should be
+  wrapped at 70 columns.
+
+Naming
+------
+
+* Use lowercase_with_underscores for function, variable, and type
+  names.
+
+* All structs should be typedef'd to a name ending with _t.  If the
+  struct has a tag, it should be the same as the typedef name, minus
+  the trailing _t.
+
+libnotmuch conventions
+----------------------------------
+
+* Functions starting with notmuch_ in lib/notmuch.h are public and are
+  automatically exported from the shared library.  Private library
+  functions should generally either be static or, if they are shared
+  between compilation units, start with _notmuch.
+
+* Functions in libnotmuch must not access user configuration files
+  (i.e. .notmuch-config)
+
+* Code which needs to be accessed from both the CLI and from
+  libnotmuch should be factored out into libutil (under util/).
-- 
1.7.8.3

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-01-27 23:46 [PATCH] STYLE: Initial draft of coding style document David Bremner
@ 2012-01-30 14:38 ` Tomi Ollila
  2012-01-30 16:01   ` Jani Nikula
  0 siblings, 1 reply; 7+ messages in thread
From: Tomi Ollila @ 2012-01-30 14:38 UTC (permalink / raw)
  To: David Bremner, notmuch; +Cc: David Bremner

On Fri, 27 Jan 2012 19:46:58 -0400, David Bremner <david@tethera.net> wrote:
> From: David Bremner <bremner@debian.org>

[ ... ]

> +
> +* Indent is 4 spaces with mixed tabs/spaces and a tab width of 8.
> +  Tabs should be only at the beginning of the line.

So, after initial indentation (with tabs) there should not be further
tabs? We'll be using the former instead of the latter in these 2 below?

/* excerpt from command-line-arguments.h -- indentation without tabs */

enum notmuch_opt_type {
    NOTMUCH_OPT_END = 0,
    NOTMUCH_OPT_BOOLEAN,        /* --verbose              */
    NOTMUCH_OPT_INT,            /* --frob=8               */
    NOTMUCH_OPT_KEYWORD,        /* --format=raw|json|text */
    NOTMUCH_OPT_STRING,         /* --file=/tmp/gnarf.txt  */
    NOTMUCH_OPT_POSITION        /* notmuch dump pos_arg   */
};

/* excerpt from command-line-arguments.h -- indentation with tabs */

enum notmuch_opt_type {
    NOTMUCH_OPT_END = 0,
    NOTMUCH_OPT_BOOLEAN,	/* --verbose              */
    NOTMUCH_OPT_INT,		/* --frob=8               */
    NOTMUCH_OPT_KEYWORD,	/* --format=raw|json|text */
    NOTMUCH_OPT_STRING,		/* --file=/tmp/gnarf.txt  */
    NOTMUCH_OPT_POSITION	/* notmuch dump pos_arg   */
};


[ ... ]


Tomi

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-01-30 14:38 ` Tomi Ollila
@ 2012-01-30 16:01   ` Jani Nikula
  2012-02-04  0:50     ` David Bremner
  0 siblings, 1 reply; 7+ messages in thread
From: Jani Nikula @ 2012-01-30 16:01 UTC (permalink / raw)
  To: Tomi Ollila; +Cc: notmuch, David Bremner

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

On Jan 30, 2012 4:38 PM, "Tomi Ollila" <tomi.ollila@iki.fi> wrote:
>
> On Fri, 27 Jan 2012 19:46:58 -0400, David Bremner <david@tethera.net>
wrote:
> > From: David Bremner <bremner@debian.org>
>
> [ ... ]
>
> > +
> > +* Indent is 4 spaces with mixed tabs/spaces and a tab width of 8.
> > +  Tabs should be only at the beginning of the line.
>
> So, after initial indentation (with tabs) there should not be further
> tabs? We'll be using the former instead of the latter in these 2 below?

I'd prefer tabs for aligning comments at the end of lines.

>
> /* excerpt from command-line-arguments.h -- indentation without tabs */
>
> enum notmuch_opt_type {
>    NOTMUCH_OPT_END = 0,
>    NOTMUCH_OPT_BOOLEAN,        /* --verbose              */
>    NOTMUCH_OPT_INT,            /* --frob=8               */
>    NOTMUCH_OPT_KEYWORD,        /* --format=raw|json|text */
>    NOTMUCH_OPT_STRING,         /* --file=/tmp/gnarf.txt  */
>    NOTMUCH_OPT_POSITION        /* notmuch dump pos_arg   */
> };
>
> /* excerpt from command-line-arguments.h -- indentation with tabs */
>
> enum notmuch_opt_type {
>    NOTMUCH_OPT_END = 0,
>    NOTMUCH_OPT_BOOLEAN,        /* --verbose              */
>    NOTMUCH_OPT_INT,            /* --frob=8               */
>    NOTMUCH_OPT_KEYWORD,        /* --format=raw|json|text */
>    NOTMUCH_OPT_STRING,         /* --file=/tmp/gnarf.txt  */
>    NOTMUCH_OPT_POSITION        /* notmuch dump pos_arg   */
> };
>
>
> [ ... ]
>
>
> Tomi
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

[-- Attachment #2: Type: text/html, Size: 2367 bytes --]

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-01-30 16:01   ` Jani Nikula
@ 2012-02-04  0:50     ` David Bremner
  2012-02-06  4:42       ` Austin Clements
  0 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2012-02-04  0:50 UTC (permalink / raw)
  To: Jani Nikula, Tomi Ollila; +Cc: notmuch

On Mon, 30 Jan 2012 18:01:15 +0200, Jani Nikula <jani@nikula.org> wrote:
> On Jan 30, 2012 4:38 PM, "Tomi Ollila" <tomi.ollila@iki.fi> wrote:
> >
> > > +
> > > +* Indent is 4 spaces with mixed tabs/spaces and a tab width of 8.
> > > +  Tabs should be only at the beginning of the line.
> >
> > So, after initial indentation (with tabs) there should not be further
> > tabs? We'll be using the former instead of the latter in these 2 below?

Ah, I only meant to explain what whitespace-mode complains about, namely

<space><space><space><space><tab>x=1;

as opposed to 

<tab<space><space><space><space><tab>x=1;

I'm not sure it's that important, but apparently if it stays in the
style guide it needs rewording.

d

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-02-04  0:50     ` David Bremner
@ 2012-02-06  4:42       ` Austin Clements
  2012-02-13  1:42         ` David Bremner
  0 siblings, 1 reply; 7+ messages in thread
From: Austin Clements @ 2012-02-06  4:42 UTC (permalink / raw)
  To: David Bremner; +Cc: Tomi Ollila, notmuch

Quoth David Bremner on Feb 03 at  8:50 pm:
> On Mon, 30 Jan 2012 18:01:15 +0200, Jani Nikula <jani@nikula.org> wrote:
> > On Jan 30, 2012 4:38 PM, "Tomi Ollila" <tomi.ollila@iki.fi> wrote:
> > >
> > > > +
> > > > +* Indent is 4 spaces with mixed tabs/spaces and a tab width of 8.
> > > > +  Tabs should be only at the beginning of the line.
> > >
> > > So, after initial indentation (with tabs) there should not be further
> > > tabs? We'll be using the former instead of the latter in these 2 below?
> 
> Ah, I only meant to explain what whitespace-mode complains about, namely
> 
> <space><space><space><space><tab>x=1;
> 
> as opposed to 
> 
> <tab<space><space><space><space><tab>x=1;
> 
> I'm not sure it's that important, but apparently if it stays in the
> style guide it needs rewording.

Any indentation style this difficult to explain can't be a good idea.
How about,

* Indent is 4 spaces with mixed tab/spaces and a tab width of 8.
  (Specifically, a line should begin with zero or more tabs followed
  by fewer than eight spaces.)

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-02-06  4:42       ` Austin Clements
@ 2012-02-13  1:42         ` David Bremner
  2012-02-19 20:54           ` Pieter Praet
  0 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2012-02-13  1:42 UTC (permalink / raw)
  To: Austin Clements; +Cc: Tomi Ollila, notmuch

On Sun, 5 Feb 2012 23:42:05 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
> 
> Any indentation style this difficult to explain can't be a good idea.
> How about,
> 
> * Indent is 4 spaces with mixed tab/spaces and a tab width of 8.
>   (Specifically, a line should begin with zero or more tabs followed
>   by fewer than eight spaces.)

Oh, I pushed the style guide, with Austin's suggested wording.

d

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

* Re: [PATCH] STYLE: Initial draft of coding style document
  2012-02-13  1:42         ` David Bremner
@ 2012-02-19 20:54           ` Pieter Praet
  0 siblings, 0 replies; 7+ messages in thread
From: Pieter Praet @ 2012-02-19 20:54 UTC (permalink / raw)
  To: David Bremner, Austin Clements; +Cc: Tomi Ollila, notmuch

On Sun, 12 Feb 2012 21:42:49 -0400, David Bremner <bremner@debian.org> wrote:
> On Sun, 5 Feb 2012 23:42:05 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
> > 
> > Any indentation style this difficult to explain can't be a good idea.
> > How about,
> > 
> > * Indent is 4 spaces with mixed tab/spaces and a tab width of 8.
> >   (Specifically, a line should begin with zero or more tabs followed
> >   by fewer than eight spaces.)
> 
> Oh, I pushed the style guide, with Austin's suggested wording.
>

We could also borrow from the Cairo coding style guidelines [1].

Or perhaps we should get rid of the mixed tabs/spaces deal altogether?
Carl once mentioned he planned to convert to using mod-8 tabs only [2].
Linus agrees [3] :)

> d
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


Peace

-- 
Pieter

[1] http://cgit.freedesktop.org/cairo/tree/CODING_STYLE
[2] id:"87ocmwok2w.fsf@yoom.home.cworth.org"
    http://mid.gmane.org/87ocmwok2w.fsf@yoom.home.cworth.org
[3] http://www.kernel.org/doc/Documentation/CodingStyle

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

end of thread, other threads:[~2012-02-19 20:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 23:46 [PATCH] STYLE: Initial draft of coding style document David Bremner
2012-01-30 14:38 ` Tomi Ollila
2012-01-30 16:01   ` Jani Nikula
2012-02-04  0:50     ` David Bremner
2012-02-06  4:42       ` Austin Clements
2012-02-13  1:42         ` David Bremner
2012-02-19 20:54           ` Pieter Praet

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).