In message <[EMAIL PROTECTED]> on Thu, 22 Nov 2007 17:13:26 -0600, "Matthew D. 
Fuller" <[EMAIL PROTECTED]> said:

fullermd> On Fri, Dec 22, 2006 at 11:44:02PM +0100 I heard the voice of
fullermd> Rhialto, and lo! it spake thus:
fullermd> > 
fullermd> > Once we settle on some layout, [...]
fullermd> 
fullermd> Which we should move toward.  The present situation is
fullermd> downright painful.  The style is inconsistent in every way.
fullermd> The amount of cruft is staggering; what variables we declare
fullermd> where and in what scope, what functions are prototypes where
fullermd> (or at all)...

I generally agree.  There's a lot of baggage, and I suspect some of it
comes all the way from twm itself.

fullermd> The following, I think, should not be contentious:
fullermd> 
fullermd> - Tabs should not be used for alignment.  See e.g. #define's
fullermd>   and comments after lines in structure definitions in twm.h
fullermd>   and other .h's.  This goes all wonky with any tabstop
fullermd>   except that of the person writing it.  The only thing a
fullermd>   tab is the same size as is a tab, so unless they happen at
fullermd>   the beginning of the line in equal numbers, you can be
fullermd>   assured that tabs will misalign somewhere.

I agree.  To make it easy, we could add something similar to this (but
with C instead of C++ style comments) at the end of each file:

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Now, there's no need for the GNU style specifically, although I happen
to like it, but I hope you catch my drift...

fullermd> - Single-line if()'s are the devil.  I've used 'em in code
fullermd>   before, but almost always for bad reasons.

Agreed.

fullermd>   Similarly, cramming two statements on one line like
fullermd>   "i = 0; j = 0;" is usually more hinderance than help.

Not sure I agree in all cases.

fullermd> - We have way too many lines that are way too long.  Sub-80
fullermd>   char!  Going with that, comments at EOL are probably
fullermd>   usually best put elsewhere.

I try to keep lines at sub-80, but there are cases where doing so
becomes butt ugly.  Those are often better kept long.

fullermd> - Speaking of comments, we need a lot more of 'em.  Except
fullermd>   in the places where there are long comments embedded in
fullermd>   the middle of statements, like in the if() a dozen lines
fullermd>   into ChangeOccupation(). I'm hot on comments and vertical
fullermd>   whitespace.

Yes, more well placed comments good!  Anyone feeling like documenting
a piece of code somewhere with comments?  By all the mighty gods,
don't let anything stop you!

fullermd> - We have too damn many global variables.

True, but they do serve a purpose.

fullermd> These are probably more so:
fullermd> 
fullermd> - Indent with either 1 tab per level, or some number (2?  4?
fullermd>   3 maybe, to really mess with people mixing in tabs?) of
fullermd>   spaces per level.  No number of spaces should ever turn
fullermd>   into a tab (see ci and pi flags in vim).  That part at
fullermd>   least shouldn't be too argumentative; it's which of the
fullermd>   two that gets rough.

My preference is the GNU style or BSD KNF style with 4 spaces for
indentation.

For those wondering about the different styles, see
http://en.wikipedia.org/wiki/Indent_style

fullermd> - Spaces before args.  "if (x)" and "foofunc (x)".  I don't
fullermd>   like 'em.

Well, I'd like to differenciate between statements (such as "if") and
functions.  The former gets a space, the latter not.  That goes along
with the BSD KNF style.

fullermd> - Braces.  It seems like a majority (but not a large one) of
fullermd>   the code K&R's it.  I prefer Allman; I especially dislike
fullermd>   the cuddled up "else if"'s you end up with in K&R...

I dunno, Allman's style always made me cringe...  Now, what exactly is
wrong with "else if"?  Can you show an example of what's so horrible
and how you would write it instead?

fullermd> Other random bits:
fullermd> 
fullermd> - Multi-line alignment.  I tend to align later lines where
fullermd>   they 'belong' logically; up to the ( of function calls,
fullermd>   and sometimes layers deeper on long many-parenthesized
fullermd>   if()'s, except when that is "too far" over (where "too
fullermd>   far" is interpreted on a variety of criteria), in which
fullermd>   case I push them over 2 indentation levels (which
fullermd>   distinguishes them well from inner blocks).

Agreed.

fullermd> - Underscores good.  CamelCase bad.

I generally agree, except CamelCase seems to be the general X11
style.  I've no problem adapting to that.

fullermd> - Defining functions with a newline before the function name
fullermd>   sure does make finding stuff easier.
fullermd> 
fullermd>   void
fullermd>   foobar(blah)
fullermd> 
fullermd>   not
fullermd> 
fullermd>   void foobar(blah)

The former is yet one of those things that make me cringe.  I can't
see how it's hard to search the latter...

fullermd> - Implicit comparisons as boolean (e.g., "if(x)" instead of
fullermd>   "if(x!=NULL)" and equivalents for numerics) bad.

Why?

fullermd> - I don't like multi-line comments that start on their first
fullermd>   line...

Why?

fullermd> - Urg, there are array references with spaces before the [
fullermd>   too.  And some function calls with MANY spaces before the
fullermd>   (; see workmgr.c around line 1700.

Agreed.

fullermd> - We should probably have less commented out code.  Unless
fullermd>   it's clarifying something, or commented out rather short
fullermd>   term...   well, we've got a VCS after all.  That's what
fullermd>   it's for.

I assume you're not talking about conditional code...

fullermd> And other stuff that I've managed to put out of mind,
fullermd> probably.  We should hash out the One True Ctwm Style and be
fullermd> done with it, so we can use it for new code and convert
fullermd> existing code as we're messing with it.

Agreed.  I suggest starting to write a file HACKING and tweak it until
we're all agreeing enough.

Cheers,
Richard

-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.

-- 
Richard Levitte                         [EMAIL PROTECTED]
                                        http://richard.levitte.org/

"When I became a man I put away childish things, including
 the fear of childishness and the desire to be very grown up."
                                                -- C.S. Lewis

Reply via email to