Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
coding style
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Yuval Levy  
View profile  
 More options Aug 5 2009, 12:48 am
From: Yuval Levy <goo...@levy.ch>
Date: Wed, 05 Aug 2009 00:48:56 -0400
Local: Wed, Aug 5 2009 12:48 am
Subject: coding style
* if you're not interested in Hugin's development, you can stop reading now*

Hello Hugin developers,

I've been looking at our source code and I find that it can use some
consistency / clean up. The current status is historically grown - I am
not sure every contributor has seen Pablo's notes [0] and I think our
coding style belongs on the web, maybe on a wiki page?

I would like to reach a consensus amongst the developers of what coding
style we want. The consensus coding style should become a very strong
recommendation for new code (I don't feel like policing volunteers /
mandating it, but if we start to see unreadable code in commits we'll
have to discuss it because this is critical for the project's long term
viability); and when developers go over existing code, they can
optionally make it more readable for themselves and for those coming
after them.

Do we want a loose coding style guideline like [1]? or a strict one like
[2]? I tend for a loose - define a necessary minimum and let the good
common sense of each individual contributor prevail.

Below are different points for discussion. If I have forgot one that you
deem important in coding style, please add it. For every point there are
a few alternatives. I have surely missed on alternatives and variations,
so if you think that more should be added, do it.

I kindly ask you to express your opinion to each and every single point
as a contribution to the discussion. After most committers have
expressed their opinion I will summarize the choices and propose a
coding style for adoption.

1. NAMING CONVENTIONS

1.1. PRIVATE VARIABLES

all private variables should have a prefix. Many (but not all) private
variables are currently prefixed with m_ and I suggest to retain this
style consistently across the codebase.

1.2. VARIABLE NAMES

some variables are named with the CamelCase convention - capitalizing
the beginning of the word. Other use the word_separated_by_underscore
convention. Are there other conventions? Which one do you favor?

variable names should be clear and descriptive. no contractions, maybe
with a few listed exception, e.g. Pano instead of Panorama. Any more
exceptions?

1.3. FUNCTION NAMES

should functions follow the same conventions as variables? or a
different one?

function names should be descriptive. no contractions, maybe with a few
listed exception, e.g. Pano instead of Panorama. Any more exceptions?

2. COMMENTS

2.1. DOCUMENTATION (copied verbatim from Pablo)

document your code (or the code you are reading and understanding) with
doxygen (http://www.doxygen.org). Doxygen is a useful tool and can also
be used to create other documentation that just class interface
descriptions. It works by prefixing the function prototypes with a
special comment. Pablo usually puts the documentation in the header files.

       The basic usage is very javadoc like:

       /** One sentence class description
        *
        *  more detailed description
        *
        *  @todo pet the cat more often
        *  @bug  might scratch if annoyed
        */
       class Cat
       {
       public:
           /** hunt food
            *
            *  @param prey type of animals that we should hunt
            *  @return true if the cat is sated
            */
           bool HuntFood(Prey prey);

       }

2.2. WORK IN PROGRESS

if something needs work, put a // FIXME or // TODO comment so that a
grep will reveal places that needs attention. Gedit automatically
highlights TODO and FIXME.

3. SPACING AND INDENTATION

3.1. BRACES

there are many different indent styles [3]. I am personally used to 1TBS
[4] (like the Linux Kernel), but I recently heard good arguments to
adopt Allman style [5], which puts the brace associated with a control
statement or a function on the next line, indented to the same level as
the control statement. I am ready to go Allman. Or maybe you want to
suggest other alternatives? Which one do you prefer?

3.2. TABULATORS

use spaces instead of tabulators (to maintain consistency across
editors). use four spaces for one indentation. or are there other
preferences?

3.3. SPACES

I would not go into that much detail. or maybe we should adopt/adapt a
strict coding guide like [2]?

3.4. LINE ENDS

Unix/Linux line ending (Windows and OSX users have to adapt)

4. COMMITTS

It is tempting to clean up old code while fixing bugs or adding new
code. Please don't - it makes the committ (diff!) much more difficult to
read / understand.

Keep style clean up committs separated and mention them as such in the
log message.

I think that's about it, but I may be missing something. time to hit the
pillow.

Yuv

[0]
<http://hugin.svn.sourceforge.net/viewvc/hugin/hugin/trunk/src/dox/mai...>
[1]
<http://developer.gnome.org/doc/guides/programming-guidelines/code-sty...>
[2]
<http://www.blender.org/documentation/intranet/conventions/codingstyle...>
[3] <http://en.wikipedia.org/wiki/Indent_style>
[4] <http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS>
[5]
<http://en.wikipedia.org/wiki/Indent_style#Allman_style_.28bsd_in_Emac...>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marcus Bointon  
View profile  
 More options Aug 5 2009, 4:03 am
From: Marcus Bointon <marcus.boin...@gmail.com>
Date: Wed, 5 Aug 2009 10:03:31 +0200
Local: Wed, Aug 5 2009 4:03 am
Subject: Re: [hugin-ptx] coding style
On 5 Aug 2009, at 06:48, Yuval Levy wrote:

> Unix/Linux line ending (Windows and OSX users have to adapt)

OSX has used Unix line breaks natively from the start. There are  
almost no apps that use old-style MacOS line breaks any more, aside  
from holdouts like Filemaker Pro. Since Windows and source  
distributions generally never meet, I wouldn't be too worried about  
them.

Marcus


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bruno Postle  
View profile  
 More options Aug 5 2009, 6:02 am
From: Bruno Postle <br...@postle.net>
Date: Wed, 5 Aug 2009 11:02:24 +0100
Local: Wed, Aug 5 2009 6:02 am
Subject: Re: [hugin-ptx] coding style
On Wed 05-Aug-2009 at 00:48 -0400, Yuval Levy wrote:

>3. SPACING AND INDENTATION

I'm not particularly concerned about whichever style gets used, but
it is important that nobody goes around changing existing code to
suit without thinking about it first - We have several branches
waiting to be merged, changing the amount of whitespace makes that
difficult, and splitting or joining lines of code makes it
enormously more so.

Comments and inline-documentation are always welcome, please give
them lines of their own and don't append them to existing code:

    exit(); do_stuff(); //Don't do this

--
Bruno


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuval Levy  
View profile  
 More options Aug 5 2009, 11:20 pm
From: Yuval Levy <goo...@levy.ch>
Date: Wed, 05 Aug 2009 23:20:22 -0400
Local: Wed, Aug 5 2009 11:20 pm
Subject: Re: [hugin-ptx] Re: coding style

Bruno Postle wrote:
> We have several branches
> waiting to be merged, changing the amount of whitespace makes that
> difficult, and splitting or joining lines of code makes it
> enormously more so.

good point. I don't expect to have a consensus on coding style before
the autumn - many developers are on holiday now, and the GSoC students
are busy.

if it ends up like last year, we'll have integration around
October/November and December would be a good time for some clean up.

> Comments and inline-documentation are always welcome, please give
> them lines of their own and don't append them to existing code:

>     exit(); do_stuff(); //Don't do this

will add this.

Yuv


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Legg  
View profile  
 More options Aug 6 2009, 2:06 pm
From: James Legg <lankyle...@gmail.com>
Date: Thu, 06 Aug 2009 19:06:17 +0100
Local: Thurs, Aug 6 2009 2:06 pm
Subject: Re: [hugin-ptx] coding style

I think the first letter of a name should be capitalised only for
classes, structs, and typedefs. Variables and functions should not have
an initial capital.
This is especially useful when you want to declare a variable with the
same name as its class, as you don't need to name your variable
ThePanorama or MyPanorama or similar.
I favour the_underscore_convention but since most of the names in Hugin
use camelCase it is probably best we stick with that.

> variable names should be clear and descriptive. no contractions, maybe
> with a few listed exception, e.g. Pano instead of Panorama. Any more
> exceptions?

If we allow exceptions, the contracted form of the exceptions should
always be used, otherwise the rule doesn't help very much.

> 2.2. WORK IN PROGRESS

> if something needs work, put a // FIXME or // TODO comment so that a
> grep will reveal places that needs attention. Gedit automatically
> highlights TODO and FIXME.

gedit does highlight them, which is useful. It also highlights doxygen
commands. The @todo and @bug sections in doxygen comments are listed
here:
http://hugin.sourceforge.net/docs/html/todo.shtml
http://hugin.sourceforge.net/docs/html/bug.shtml
as well as inside the relevant documentation. This is arguably more
useful, especially when using a different editor.

> 3. SPACING AND INDENTATION

> 3.1. BRACES

> there are many different indent styles [3].
<snip>
>  Which one do you prefer?

I prefer Allman style too.

> 3.2. TABULATORS

> use spaces instead of tabulators (to maintain consistency across
> editors). use four spaces for one indentation. or are there other
> preferences?

This is fine.

I'll repeat Bruno's comment as it is important:

Don't start changing existing code until all the branches we are working
on have been merged with the trunk.

James


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Sleevi  
View profile  
 More options Aug 6 2009, 11:48 pm
From: "Ryan Sleevi" <ryan+hu...@sleevi.com>
Date: Thu, 6 Aug 2009 23:48:15 -0400
Local: Thurs, Aug 6 2009 11:48 pm
Subject: RE: [hugin-ptx] coding style
Granted, I'm not committing (yet?), but that doesn't keep me from voicing an
opinion, right? :)

> 1.2. VARIABLE NAMES

> some variables are named with the CamelCase convention - capitalizing
> the beginning of the word. Other use the word_separated_by_underscore
> convention. Are there other conventions? Which one do you favor?

> variable names should be clear and descriptive. no contractions, maybe
> with a few listed exception, e.g. Pano instead of Panorama. Any more
> exceptions?

Support James' comments re: LeadingCaps for classes/structures/typedefs, and
favoring mixedCase for variables. For functions, I always like the visual
distinction between public and private methods, if only to save a
consultation to intellisense or the header file. Using LeadingCaps for
public functions, mixedCase for private/protected/internal seems to offer
some visual distinction, but that's more a personal preference thing :)

I'm a fan of mixedCase over underscore_insertions_for_words myself, if only
to save the keyboard extension to the underscore. Readability wise I think
they're fairly equal. The only question comes when using acronyms (eg:
sqlVar vs SQLVar vs sQLVar), but I don't know how much of a problem that is.
I haven't seen many variables that have that problem in the codebase, and it
doesn't seem like it'd need to be hammered out now...

> 1.3. FUNCTION NAMES

> should functions follow the same conventions as variables? or a
> different one?

> function names should be descriptive. no contractions, maybe with a few
> listed exception, e.g. Pano instead of Panorama. Any more exceptions?

Agree with James' comment that whatever contractions are acceptable, they be
used exclusively.

> 3. SPACING AND INDENTATION

> 3.1. BRACES

> there are many different indent styles [3]. I am personally used to
> 1TBS
> [4] (like the Linux Kernel), but I recently heard good arguments to
> adopt Allman style [5], which puts the brace associated with a control
> statement or a function on the next line, indented to the same level as
> the control statement. I am ready to go Allman. Or maybe you want to
> suggest other alternatives? Which one do you prefer?

I always find 1TBS to be readable. The most helpful thing is the requirement
that single-line conditionals always include braces. Had too many bugs
working in teams where one dev would use a short construct, and either
between merging or sloppy devs, a second statement would be added that
screws up the code.

eg:

if (condition)
        doSomething();

becoming

if (condition)
        doSomething();
        doSomeOtherThing();

instead of

if (condition) {
        doSomething();
        doSomeOtherThing();

}

The problem I have with Allman is that I've seen too many bugs where the
code ends up like

if (condition);
{
        doSomething();

}

See the error? The extra ; accepted by all the compilers I've ever used,
ends up causing the { } to always be executed. It can be a real pain to
trace through those in complex systems to find out who added the extra ;
when typing

> 3.2. TABULATORS

> use spaces instead of tabulators (to maintain consistency across
> editors). use four spaces for one indentation. or are there other
> preferences?

Spaces, tabs, it's all the same to me. Visual Studio can be a pain when
adjusting between the two, but it's doable. My own preference is "Tabs are
used for logical columns, spaces are used for alignment", but that's not
exactly easy to enforce :) (Of course, a diff usually reveals right away if
things are off). It's only really an issue if column width is also being
fixed - since artificial wrapping is often necessary in those cases.

void foo()
{
<tab>if (someLongCondition
<tab>    && otherLongCondition
<tab>    || someOptionalCondition) {
<tab><tab>doSomething();
<tab><tab>if (didSomething) {
<tab><tab><tab>doSomethingElse();
<tab><tab>}
<tab>}

}

> 3.3. SPACES

> I would not go into that much detail. or maybe we should adopt/adapt a
> strict coding guide like [2]?

Personally find it readable to use spaces before the parenthesis after
control statements, but not to use spaces before the parenthesis after
functions.

eg:

fn(foo, bar) / x(y) / y(z)
if (condition) / while (condition) / else (something else)

and use spaces after commas

fn(foo, bar, baz)

I find it less readable when the extreme is taken

fn( foo, bar, baz ) or worse fn( foo , bar , baz ), which I've seen both in
projects.

> 3.4. LINE ENDS

> Unix/Linux line ending (Windows and OSX users have to adapt)

Um, is there any reason we're not just using

svn propset svn:eol-style native?

Seems like it solves the problem right there and everybody wins :) I've used
it on all my projects in the past, multiple platforms, and it always works
out. Also handles cygwin in Windows fine (uses LF, like you'd expect from a
posix layer, not CRLF, like Windows)

http://svnbook.red-bean.com/en/1.1/ch07s02.html

> 4. COMMITTS

> It is tempting to clean up old code while fixing bugs or adding new
> code. Please don't - it makes the committ (diff!) much more difficult
> to
> read / understand.

> Keep style clean up committs separated and mention them as such in the
> log message.

Seconded!

Any comments on the use of goto / case labels? It seems like that would be
one of the religious things to hammer out - Is goto considered harmful? Is
considering goto harmful harmful? Is considering goto harmful being
considered harmful harmful? (http://en.wikipedia.org/wiki/Considered_harmful
)

Personally, I'm also a big fan of warning-less code. I'm not talking about
MSFT's annoying _CRT_SECURE_NO_WARNINGS crap, but the warnings that get
emitted when you end up casting int -> size_t and the like, trying to keep
track of all that mess. It's not that bad now, but might help for new code
:)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lukáš Jirkovský  
View profile  
 More options Aug 7 2009, 3:43 am
From: Lukáš Jirkovský <l.jirkov...@gmail.com>
Date: Fri, 7 Aug 2009 09:43:23 +0200
Local: Fri, Aug 7 2009 3:43 am
Subject: Re: [hugin-ptx] coding style
2009/8/5 Yuval Levy <goo...@levy.ch>:

I like more loose coding style. Spending a day learning what to do and
what not to do is IMO boring.

I don't know what to say about this. I'll be OK with it if it become a
part of coding guideline either doesn't.

> 1.2. VARIABLE NAMES

> some variables are named with the CamelCase convention - capitalizing
> the beginning of the word. Other use the word_separated_by_underscore
> convention. Are there other conventions? Which one do you favor?

> variable names should be clear and descriptive. no contractions, maybe
> with a few listed exception, e.g. Pano instead of Panorama. Any more
> exceptions?

I prefer camel case. But as I'm thinking about it I like convention
where classes and structures are with capitalized first word and
variables and functions are with small first word. For constants I'm
not really decisive but all caps may be a bit better because it's more
visible that it's a constant.

> 1.3. FUNCTION NAMES

> should functions follow the same conventions as variables? or a
> different one?

> function names should be descriptive. no contractions, maybe with a few
> listed exception, e.g. Pano instead of Panorama. Any more exceptions?

dtto.

I'm already using that and IMO it's very useful. Quite a lot of IDEs
have some facility to search for TODO's and FIXME's.

> 3. SPACING AND INDENTATION

> 3.1. BRACES

> there are many different indent styles [3]. I am personally used to 1TBS
> [4] (like the Linux Kernel), but I recently heard good arguments to
> adopt Allman style [5], which puts the brace associated with a control
> statement or a function on the next line, indented to the same level as
> the control statement. I am ready to go Allman. Or maybe you want to
> suggest other alternatives? Which one do you prefer?

1TBS. It's very compact.

> 3.2. TABULATORS

> use spaces instead of tabulators (to maintain consistency across
> editors). use four spaces for one indentation. or are there other
> preferences?

Certainly spaces.

> 3.3. SPACES

> I would not go into that much detail. or maybe we should adopt/adapt a
> strict coding guide like [2]?

> 3.4. LINE ENDS

> Unix/Linux line ending (Windows and OSX users have to adapt)

No problem for me ;-)

> 4. COMMITTS

> It is tempting to clean up old code while fixing bugs or adding new
> code. Please don't - it makes the committ (diff!) much more difficult to
> read / understand.

> Keep style clean up committs separated and mention them as such in the
> log message.

Yep, this is good. I think everyone sane already uses this ;-)
Searching for a mistake int patch with mixed bug fixes and new code is
horrifying.

I'd like to also mention that I'm against changes to the code style
now, because it would make merging GSoC branches from even harder.

Lukas

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuval Levy  
View profile  
 More options Aug 8 2009, 9:31 am
From: Yuval Levy <goo...@levy.ch>
Date: Sat, 08 Aug 2009 09:31:11 -0400
Local: Sat, Aug 8 2009 9:31 am
Subject: Re: [hugin-ptx] Re: coding style

Ryan Sleevi wrote:
> Granted, I'm not committing (yet?)

if you want access, let me know your sf handle. I've committed your
patches to build in 64bit Windows as support for 64bit Windows is
overdue (and it would be nice if you would contribute a 64bit SDK).

> but that doesn't keep me from voicing an
> opinion, right? :)

no, opinions are always welcome, and opinions are always all right in
their scope/context :)

>> 3.4. LINE ENDS

>> Unix/Linux line ending (Windows and OSX users have to adapt)

> Um, is there any reason we're not just using

> svn propset svn:eol-style native?

it would make us more dependent on SVN than I really would like to be.
At the moment there is enough dust flying and I don't want to add more,
but one must be blind not to see a major trend of many open source
projects toward distributed version control systems. Enblend is already
on its way to Mercurial, and is also available on Launchpad using
Bazaar. I also made some experiences with Git (VideoLAN and
antipasto-arduino). Those next generation tools have matured. But this
is not the right time to have this kind of discussion, so forget what I
wrote :)

all of your other feedback is being religiously collected and will be
considered for the draft.

Yuv


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuval Levy  
View profile  
 More options Aug 8 2009, 9:47 am
From: Yuval Levy <goo...@levy.ch>
Date: Sat, 08 Aug 2009 09:47:41 -0400
Local: Sat, Aug 8 2009 9:47 am
Subject: Re: [hugin-ptx] Re: coding style
Hi Lukáš

Lukáš Jirkovský wrote:
> I like more loose coding style. Spending a day learning what to do and
> what not to do is IMO boring.

I see where you are coming from, and me too I prefer loose. I don't feel
like policing contributors. But then I see where I am coming from and I
think I need and want guidance before I damage the project.

I'm a C++ monkey. No formal training. Just an itch to scratch and I
scratch so deep that I find myself in the source code. I usually go by
example, so for the coding style I just looked at how the file was and
adapted.

This is OK when changing a couple of lines to fix a bug; or when working
alone. But when contributing serious chunks of code or when working in a
team it is not OK.

Some nuances where not immediately clear on me and when I started moving
from file to file and finding completely different conventions, it
became difficult to read.

Good style is important for readability. Consistent style is important
for guidance for newbies. Both make the project more viable long term,
and more scalable in terms of people working on it.

So I came to the conclusion that I will document the coding style in
much more detail than I thought (there are some really good
feedbacks/additions here on the thread, keep them coming) and propose it
for adoption.

I don't think it will take one day to read/learn.

I do acknowledge that it is slightly more difficult for individual
contributors to adapt, especially if they already have strong opinions
about how things should be; and if they are change-averse. Adaptability
is a good skills to learn/have.

I am still unsure about the 1TBS vs. Allman style. I read good arguments
on both sides. I am currently a 1TBS user. Maybe I should stay so? or
maybe I should adopt Allman? I don't know. I need guidance, but most of
all the project needs consistency.

Yuv


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lukáš Jirkovský  
View profile  
 More options Aug 9 2009, 3:36 am
From: Lukáš Jirkovský <l.jirkov...@gmail.com>
Date: Sun, 9 Aug 2009 09:36:30 +0200
Local: Sun, Aug 9 2009 3:36 am
Subject: Re: [hugin-ptx] Re: coding style
2009/8/8 Yuval Levy <goo...@levy.ch>:

I understand this need and I've nothing against it. Moreover, when it
takes less than a day to learn it's OK ;-)

> I do acknowledge that it is slightly more difficult for individual
> contributors to adapt, especially if they already have strong opinions
> about how things should be; and if they are change-averse. Adaptability
> is a good skills to learn/have.

> I am still unsure about the 1TBS vs. Allman style. I read good arguments
> on both sides. I am currently a 1TBS user. Maybe I should stay so? or
> maybe I should adopt Allman? I don't know. I need guidance, but most of
> all the project needs consistency.

I'd select the one which is more widely used in current code. After a
quick look it seems to be neither 1TBS neither Allman style but
something more like BSD KNF [1]. Anyway, what about wait for a Pablo's
attitude, he has written most of the code.

Lukáš

> Yuv

[1] http://en.wikipedia.org/wiki/Indent_style#BSD_KNF_style

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »