FAQ Search Today's Posts Mark Forums Read

» Linux Archive
Home
New Posts
Search
FAQ


Go Back   Linux Archive > Debian > Debian dpkg

 
 
LinkBack Thread Tools
 
Old 06-26-2008, 12:46 PM
Goswin von Brederlow
 
Default What coding style should be used?

Hi,

as you might have seen from my other mails I'm working on mutliarch
for dpkg. So I've patched quite a few of the source files and looked
at more. Unfortuanetly the coding style is inconsistent. Which one
should be used?

Indentation
===========

void foo() {
int bla;
};

or

void foo() {
int bla;
};


Assignment
==========

bla= 17;

or

bla = 17;


Spacing
=======

foo(x,y,z);
for(x= 1;x<10;++x) { }
bla= blub+baz;
if(1) { }
while(1) { }
do { } while(1);

or

foo(x, y, z);
for (x= 1; x < 10; ++x) { }
bla= blub + baz;
if (1) { }
while (1) { }
do { } while (1);


Pre or Post increment
=====================

x++;
for (x= 1; x<10; x++) { }

or

++x;
for (x= 1; x<10; ++x) { }


Combined or seperate increments
===============================

*p++= 0;

or

*p = 0;
++p;


Printf formating
================
(not quite coding style but both are used)

printf("%.250s
", package->name);

or

printf("%s
", package->name);


Line breaks in complex conditionals
===================================

if (foo == 1 &&
bar == 2) { }

or

if (foo == 1
&& bar == 2) { }


Line length
===========

80 chars?

MfG
Goswin

PS: Maybe someone can put the answeres in README.coding-style in the
source?


--
To UNSUBSCRIBE, email to debian-dpkg-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 06-27-2008, 07:16 PM
Ian Jackson
 
Default What coding style should be used?

Goswin von Brederlow writes ("What coding style should be used?"):
> as you might have seen from my other mails I'm working on mutliarch
> for dpkg. So I've patched quite a few of the source files and looked
> at more. Unfortuanetly the coding style is inconsistent. Which one
> should be used?

As the original author, and still the author of most of the code by
bulk, I think my view should be determinative. It is of course a bad
idea to reformat code in a free software project.

I know that the current maintainers don't agree. But here are my
answers:

> void foo() {
> int bla;
> };

> bla= 17;

> foo(x,y,z);
unless x y z are long in which case something like

> foo(x ? 3 : 4, strange[y].zork, z);

ie both are acceptable. Clarity is key, which means using whitespace
to ensure that more closely related subexpressions are nearby.

> for (x=1; x<10; x++) { }

which is not one of your examples. Note
- Exceptionally no ` ' in assignment
but use of whitespace in expressions is always a matter of judgement
rather than hard and fast rules so
for (x= &big[complicated(expression)];
x < &end[complicated(array)];
x++) {
is OK too.

> if (1) { }
> while (1) { }

in the macro encapsulation idiom:
> do{ }while(0);
otherwise I would usually write
for (; {
and use break and continue

but this is hardly ever used except

> x++;

The reasons for writing prefix in C++ don't really apply to C.

> *p++= 0;

I would prefer this unless there was a reason to do the other.

> printf("%.250s
", package->name);
> printf("%s
", package->name);

That depends on whether the thing needs to be limited in length. Many
of the printfs with %.250s are sprintfs into fixed buffers.

> if (foo == 1 &&
> bar == 2) { }

> 80 chars?

79. But many of the lines are from an older age when I used to use up
to 90 because I was BATSHIT INSANE. One shouldn't change those unless
one happens to be changing the code anyway, because reformatting for
the sake of it is always bad.

Ian.


--
To UNSUBSCRIBE, email to debian-dpkg-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 06-27-2008, 09:36 PM
Raphael Hertzog
 
Default What coding style should be used?

Hi,

On Fri, 27 Jun 2008, Ian Jackson wrote:
> Goswin von Brederlow writes ("What coding style should be used?"):
> > as you might have seen from my other mails I'm working on mutliarch
> > for dpkg. So I've patched quite a few of the source files and looked
> > at more. Unfortuanetly the coding style is inconsistent. Which one
> > should be used?
>
> As the original author, and still the author of most of the code by
> bulk, I think my view should be determinative.

How do you reconcile that with what you just said in another thread ?

"After my last experience I don't have any plans to do any substantial
coding in dpkg :-/."

My opinion is that either you plan to work with us and you express your
opinion, or you don't want to and then you don't have much to say, I'm
afraid.

That said I would still like to have you around as your experience
can be very useful and your help in diagnosing/fixing some bugs is very
welcome.

Cheers,
--
Raphaël Hertzog

Le best-seller français mis à jour pour Debian Etch :
http://www.ouaza.com/livre/admin-debian/


--
To UNSUBSCRIBE, email to debian-dpkg-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 06-28-2008, 09:00 AM
Tollef Fog Heen
 
Default What coding style should be used?

]] Ian Jackson

| As the original author, and still the author of most of the code by
| bulk, I think my view should be determinative. It is of course a bad
| idea to reformat code in a free software project.

[...]

| > 80 chars?
|
| 79. But many of the lines are from an older age when I used to use up
| to 90 because I was BATSHIT INSANE. One shouldn't change those unless
| one happens to be changing the code anyway, because reformatting for
| the sake of it is always bad.

I believe this is a crucial point: It's fine to reformat code if
you're changing it anyway, but please don't reformat it just for the
heck of it (since that's problematic wrt bisecting and such).

(Oh, and I disagree with your formatting, but I'm not a dpkg
developer, just a patch contributor, so I'm not going to stir that
pot, not now at least.)

--
Tollef Fog Heen
UNIX is user friendly, it's just picky about who its friends are


--
To UNSUBSCRIBE, email to debian-dpkg-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 07-02-2008, 06:12 PM
Ian Jackson
 
Default What coding style should be used?

Raphael Hertzog writes ("Re: What coding style should be used?"):
> On Fri, 27 Jun 2008, Ian Jackson wrote:
> > As the original author, and still the author of most of the code by
> > bulk, I think my view should be determinative.
>
> How do you reconcile that with what you just said in another thread ?
>
> "After my last experience I don't have any plans to do any substantial
> coding in dpkg :-/."

Because reformatting code is (a) wrong for practical reasons and
(b) rude. Since a mixed style is worse than any one consistent style,
the original style should be determinative.

Ian.


--
To UNSUBSCRIBE, email to debian-dpkg-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 03:19 PM.

VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org