Quote: Consistent Coding Style

Submitted by Jeremy
on March 28, 2008 - 4:27am

"Is it your argument that consistent coding style is bad? That argument has been settled long ago with the creation of Documentation/CodingStyle. All kernel code is supposed to follow that style, unless the resulting line of code looks clearly _wrong_. Your arguments seem to center around ''hey, my way it looks similarly good so i'll do that instead because i'm the maintainer'' - and that argument does not fly. CodingStyle is definitely not gospel and common sense should be applied, but _arbitrarily_ and _intentionally_ deviating from it is considered bad manners and hurts Linux as a whole."

Two-dimensional indentation

Lawrence D'Oliveiro (not verified)
on
March 30, 2008 - 3:51am

For complicated expressions, I like to use an indentation style which gives a two-dimensional layout, e.g.

        !defined($best_result)
    ||
        !defined($providing->{"op"})
    ||
            $providing->{"op"} eq "="
        &&
            (
                    defined($providing->{"version"})
                &&
                    !defined($best_version)
            ||
                    compare_rpm_versions
                      (
                        $providing->{"version"},
                        $best_version
                      )
                >
                    0
            )

This makes the structure clearer.

Coding style for better automated source text processing

olecom
on
March 29, 2008 - 10:07pm
Heck, it's Open Source, yet no automation on text processing in that open source...

http://kernelnewbies.org/olecom

Any ideas, help, communication is appreciated.

http://mid.gmane.org/E1JfpB2-00036u-2G@flower
-- 
-o--=O`C
 #oo'L O
<___=E M

I absolutely detest having

Anonymous (not verified)
on
March 28, 2008 - 11:15am

I absolutely detest having if/while/for and the opening brace on the same line.. breaking the line after the return type and the function body sucks as well :-)
The BSDs do this to the extreme and even leave an empty line between the brace and the first statement, for example (sys/kern/vfs_bio.c)

static __inline
void
bd_speedup(void)
{

bd_wakeup(1);
}

That indeed is ugly I can

Anonymous (not verified)
on
March 28, 2008 - 3:21pm

That indeed is ugly

I can understand static __inline in one line

but splitting

void
bd_speedup(void)

to two lines SUCKS

Practical

Anonymous (not verified)
on
March 31, 2008 - 12:01am

I hated having the return type and function name on two lines, but once you get used to it it's pretty nice. You just have to get over the aesthetic barrier ;-) Now I think it looks good, and it's also much easier to grep for function names.

I don't know what the deal with splitting static __inline void bd_speedup (void) on three lines, though *shrugs*

I could venture a guess

Mr_Z
on
March 31, 2008 - 9:53am

With static __inline on its own line, it becomes easier to comment out, particularly if you use a C++ style // comment. This can become important when you want to debug something that's normally inlined and/or its name is not exported. (Or, at least, rule the function out of suspicion.)

An alternative approach, of course, is to wrap these in a macro and modulate that, but then that modulates all occurrences of "static inline" in a given translation unit.

That said, I'm not a big fan of the style. I like to be able to yoink all my prototypes into the header and have the columns line up. And the way I usually do that is to read the C file in and delete the function bodies (and sometimes the argument names). I end up with headers that look like this one or this one.

--
Program Intellivision and play Space Patrol!

Well, you are wrong. It

korowiow (not verified)
on
March 29, 2008 - 12:26am

Well, you are wrong. It allows you to _easly_ grep sources for '^bd_speedup' and find body of this function.

BSD KNF style

Anonymous (not verified)
on
March 28, 2008 - 7:02am

The BSD KNF style is pretty nice.
http://en.wikipedia.org/wiki/Indent_style#BSD_KNF_style

Everyone should follow the kernel style though, and not use their own style. To keep it from becoming a mess.

Absolutely

Anonymous (not verified)
on
March 28, 2008 - 8:29am

The BSD KNF style is pretty nice.

It's pretty close to my personal coding style (I use 3-space indentation and a space separating function names from the argument list).

Everyone should follow the kernel style though, and not use their own style.

Absolutely, even though I think their coding style is sort of ugly. There are worse, however (GNU anyone?). The point is that everyone should use the coding style used in the project they're contributing to. How "nice" it would be if everyone where allowed to use their own personal style ;-)