473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Another style question

How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code written
like

if( cond ) {
...
} else
if( some_other_cond ) {
...
} else
if( explode_with_pretty_colors) {
/* explode with pretty colors */
}
else {
...
}

to my preferred style:

if( cond ) {
...
}
else if( some_other_cond ) {
...
}
else if( explode_with_pretty_colors ) {
/* explode! */
}
else {
...
}

Another possibility (I don't use it in C) is

if( cond ) {
...
} else if( blah ) {
...
}
....

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
31 1960
Christopher Benson-Manica <at***@nospam.cyberspace.org> scribbled the following:
How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code written
like if( cond ) {
...
} else
if( some_other_cond ) {
...
} else
if( explode_with_pretty_colors) {
/* explode with pretty colors */
}
else {
...
} to my preferred style: if( cond ) {
...
}
else if( some_other_cond ) {
...
}
else if( explode_with_pretty_colors ) {
/* explode! */
}
else {
...
}
Make those if( cond ) thingies if (cond), and you've got my style
pretty much spot-on.
Another possibility (I don't use it in C) is if( cond ) {
...
} else if( blah ) {
...
}
...


--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft
Nov 14 '05 #2
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Make those if( cond ) thingies if (cond), and you've got my style
pretty much spot-on.


That's a house rule. If I were a style Nazi I would have committed
seppuku my first week ;)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:bv**********@chessie.cirr.com...
How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code [...]


Why do you need to transform code from one style to another? If you use
any source-control system, it may lead to too many differences that aren't.

FWIW, my prefered style is similar to yours, except that I use:

if (cond)
{
...
}
else if (some_other_cond)
{
...
}
else
{
...
}

The opening brace sits on its own line, just like the closing one, and the
two indent the same. There is a space before the opening parenthesis and
voluntary space after the closing one, but never the other way round. Now,
this is The Only True Style, so stick to it! :-)

Peter
Nov 14 '05 #4
Christopher Benson-Manica wrote:
How about your if/else if/else constructs?
Being [anal] like any good C programmer,
I'm in the process of transforming code written like


[snip]

I prefer:

if (cond) {
...
}
else
if (some_other_cond) {
...
}
else
if(explode_with_pretty_colors) {
/* explode with pretty colors */
}
else {
...
}

But like I said
Get a C reformatter program like indent:

http://www.gnu.org/software/indent/indent.html

so that you can convert
from one format to another automatically.

Nov 14 '05 #5


Christopher Benson-Manica wrote:
How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code written
like <snip>> to my preferred style: <snip> Another possibility (I don't use it in C) is

if( cond ) {
...
} else if( blah ) {
...
}
...


If you're going for consistency, why not just run all your code through
a C beautifier and just accept whatever it spits out? As long as all the
code's consistent in style, the actual style selected doesn't matter a
whole lot.

FWIW the UNIX tool "cb -s" (K&R mode) spits out your boss's preferred
style for case statements and the final style above for if...else.
Without the "-s" it still prefers your boss's case style but doesn't
appear to do anything useful with "if...else".

Ed.

Nov 14 '05 #6
Peter Pichler <pi*****@pobox.sk> spoke thus:
Why do you need to transform code from one style to another? If you use
any source-control system, it may lead to too many differences that aren't.


Well, there is that, of course, but I figure that since MY style is
the "One Style," it's justified. One style to rule them all...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #7
Christopher Benson-Manica <at***@nospam.cyberspace.org> scribbled the following:
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Make those if( cond ) thingies if (cond), and you've got my style
pretty much spot-on.
That's a house rule. If I were a style Nazi I would have committed
seppuku my first week ;)


Can you please ask whoever came up with that rule what they were
smoking? =)

Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:
- Indents are 2 spaces
- Braces K&R style: opening brace on the same line, closing on its own
line, one space before the opening brace
- Always 1 space after every comma and every semicolon, otherwise
1 space around every "important" operator or no spaces at all if it's
not "important"
- Always 1 space between *keywords* (if, for, while, etc) and the
opening paren, never any space between a function or a macro name and
the opening paren
- Two blank lines between each function, one blank line separating
conceptual groups of statements
That's pretty much the important stuff.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Normal is what everyone else is, and you're not."
- Dr. Tolian Soran
Nov 14 '05 #8
Ed Morton <mo****@lsupcaemnt.com> scribbled the following:
If you're going for consistency, why not just run all your code through
a C beautifier and just accept whatever it spits out? As long as all the
code's consistent in style, the actual style selected doesn't matter a
whole lot. FWIW the UNIX tool "cb -s" (K&R mode) spits out your boss's preferred
style for case statements and the final style above for if...else.
Without the "-s" it still prefers your boss's case style but doesn't
appear to do anything useful with "if...else".


Can the C beautifier also beautify Java?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am lying."
- Anon
Nov 14 '05 #9
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Can you please ask whoever came up with that rule what they were
smoking? =)
Will do! :)
- Indents are 2 spaces
Ours are five. I count on the pain to wake me up on Monday morning.
It isn't as bad as our <ot>HTML, however - indentation is essentially
random, making editing tables and scripts a joy. I've spent several
days just reformatting it, never mind fixing actual errors...</ot>
- Braces K&R style: opening brace on the same line, closing on its own
line, one space before the opening brace
I'm a former separate-line'r who's been beaten into submission...
- Two blank lines between each function, one blank line separating
conceptual groups of statements


That's another bad thing - there is space between initial declarations
and code, but blank lines elsewhere within functions are frowned upon.
Heavens knows why...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #10


Joona I Palaste wrote:
Ed Morton <mo****@lsupcaemnt.com> scribbled the following:
If you're going for consistency, why not just run all your code through
a C beautifier and just accept whatever it spits out? As long as all the
code's consistent in style, the actual style selected doesn't matter a
whole lot.


FWIW the UNIX tool "cb -s" (K&R mode) spits out your boss's preferred
style for case statements and the final style above for if...else.
Without the "-s" it still prefers your boss's case style but doesn't
appear to do anything useful with "if...else".

Can the C beautifier also beautify Java?


Maybe, but I wouldn't trust cb with Java or even C++. There are plenty
of beautifiers for those and other languages out there though, e.g. take
a look at
http://ldp.homegrownhost.net/HOWTO/C...or_others.html

Ed.

Nov 14 '05 #11
Ed Morton wrote:
Joona I Palaste wrote:
Can the C beautifier also beautify Java?
Maybe, but I wouldn't trust cb with Java or even C++.
There are plenty of beautifiers
for those and other languages out there though, e.g. take a look at

http://ldp.homegrownhost.net/HOWTO/C...or_others.html


BEWARE!

Code "beautifiers" are not necessarily [style] reformatters.
Most beautifiers insert text and embedded printer control sequences
that your compiler will *not* accept.

You also need to verify that
reformatting did not change the meaning of your code.
Always compile both the original and the reformatted versions
of your code and verify that the resulting objects are identical.

Nov 14 '05 #12
Joona I Palaste wrote:
Can you please ask whoever came up with that rule what they were
smoking? =)

Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:
- Indents are 2 spaces
- Braces K&R style: opening brace on the same line, closing on its own
line, one space before the opening brace
- Always 1 space after every comma and every semicolon, otherwise
1 space around every "important" operator or no spaces at all if it's
not "important"
- Always 1 space between *keywords* (if, for, while, etc) and the
opening paren, never any space between a function or a macro name and
the opening paren
- Two blank lines between each function, one blank line separating
conceptual groups of statements
That's pretty much the important stuff.


Say what you will, but the above are not very important elements in
determining whether a style is good or bad. Some are more important
than other. I would say spaces around most operators is a good thing.

But in general, as long as layout style is consistent and somewhat
reasonable, naming and commenting conventions are more important.
As are conventions for when to use and not to use macros.

If you find code much harder to read because the opening brace of
a block is on its own line instead of K&R style, then it is not
the code that has a problem.

1. while(condition) {
condition = important();
}

2. while ( condition )
{
condition = important();
}

Point is, 1 vs 2 should be hardly an issue. If you are someone who uses
1 and must work for some people who demand 2 then I don't see that you
have a problem at all.

I use neither of the above, but if someone gave me some reason for why
I should use 1 or 2 I would not have a problem doing that.

I think I would object if someone told me to code like this though:
a=b+c*3;
I think a = b + c * 3; is much better. There is even a physiological
reason for this. I think it is called crowding. It basically means that
human eyes have an easier time distuinguishing objects which are further
apart than close together. So there, I have a non-emotional,
non-subjective reason for this particular style choice. Which means I
win ;)
--
Thomas.

Nov 14 '05 #13
Thomas Stegen CES2000 wrote:
Joona I Palaste wrote:

I think I would object if someone told me to code like this though:
a=b+c*3;
I think a = b + c * 3; is much better.


And I prefer

a = c * 3 + b;

YMMV.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #14
Christopher Benson-Manica wrote:
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Make those if( cond ) thingies if (cond), and you've got my style
pretty much spot-on.


That's a house rule. If I were a style Nazi I would have committed
seppuku my first week ;)


My argument is that if is not a function, and thus should have a
following blank. If you want blanks surrounding "cond" be my
guest. I want to easily distinguish function calls from other
constructs. Richard Heathfield disagrees.

So, which is the house rule?

BTW, a useful style rule is that the else clause is the longer
one, other things being equal. This makes finding the controlling
statements easier. Contrast:

if (foo) {
....
....
}
else {
/* notmuch */
bar();
}

with
if (notfoo) {
/* notmuch */
bar();
}
else {
....
....
}

finding a controlling statment for something in the else clause
involves first finding the else, and then continuing north. The
second phase is much easier with the short then clause. In the
extreme, when applied to else if clauses, you get:

if (foo) foof();
else if (bar) barf();
else if (goo) goof();
else {
moo();
gou();
gai();
pan();
}

All of this is all very well when you are developing your style.
However once you have something, be consistent, at least through
any single source file. Try things out and see what minimizes the
errors and maximizes the readability.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #15
Joona I Palaste wrote:
.... snip ...
Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:
- Indents are 2 spaces
- Braces K&R style: opening brace on the same line, closing on its
own line, one space before the opening brace
- Always 1 space after every comma and every semicolon, otherwise
1 space around every "important" operator or no spaces at all if
it's not "important"
- Always 1 space between *keywords* (if, for, while, etc) and the
opening paren, never any space between a function or a macro name
and the opening paren
- Two blank lines between each function, one blank line separating
conceptual groups of statements
That's pretty much the important stuff.


I think we are pretty close to agreement. Try the following for
indent.pro. It is not perfect, but comes as close as I have found
possible to my style.

-kr -l66 -i3 -bad -di16 -lc66 -nce -ncs -cbi0 -bbo -pmt -psl -ts1

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #16
"E. Robert Tisdale" wrote:
Christopher Benson-Manica wrote:
How about your if/else if/else constructs?
Being [anal] like any good C programmer,

^^^^^^
This is another of Trollsdales gratuitious alterations of quotes.
He is sneaky, very sneaky.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #17
Richard Heathfield wrote:
Thomas Stegen CES2000 wrote:
Joona I Palaste wrote:

I think I would object if someone told me to code like this though:
a=b+c*3;
I think a = b + c * 3; is much better.


And I prefer

a = c * 3 + b;

YMMV.


Definitely MV. I can even find cases where I want different
emphasis, and would write:

a = 3*c + b;
or
dsq = b*b - 4*a*c;

although normally I would not suppress the blanks.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #18
CBFalconer <cb********@yahoo.com> spoke thus:
So, which is the house rule?


Both - the if( and the ( cond ). Our editor even auto-formats like
this.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #19
CBFalconer <cb********@yahoo.com> scribbled the following:
"E. Robert Tisdale" wrote:
Christopher Benson-Manica wrote:
> How about your if/else if/else constructs?
> Being [anal] like any good C programmer,

^^^^^^
This is another of Trollsdales gratuitious alterations of quotes.
He is sneaky, very sneaky.


Christopher originally wrote "nitpicky", not "anal". It's fun to see
what Trollsdale will alter *my* message to. =)

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I will never display my bum in public again."
- Homer Simpson
Nov 14 '05 #20
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Christopher originally wrote "nitpicky", not "anal". It's fun to see
what Trollsdale will alter *my* message to. =)


Well, in this case at least it's fairly benign - one might call it
un-euphemizing my choice of words ;)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #21
Christopher Benson-Manica wrote:
How about your if/else if/else constructs?


if (cond) { /* brace can be here... */
/* ... */
}
else
if (cond) /* ...or line below... */
{ /* (depending on what looks best at the time) */
/* ... */
}
else /* ...but never after final else */
{
/* ... */
}

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Nov 14 '05 #22
In <bv**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:


Which means that you've never been involved in some open/free source
code collaboration, where the ability to produce and read *meaningful*
diffs is essential. Any stylistical changes to the code are a major
source of "noise" and the rest of the collaboration would promptly
kick you out.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #23
In <40***************@yahoo.com> CBFalconer <cb********@yahoo.com> writes:
Richard Heathfield wrote:
Thomas Stegen CES2000 wrote:
> Joona I Palaste wrote:
>
> I think I would object if someone told me to code like this though:
> a=b+c*3;
> I think a = b + c * 3; is much better.


And I prefer

a = c * 3 + b;

YMMV.


Definitely MV. I can even find cases where I want different
emphasis, and would write:

a = 3*c + b;
or
dsq = b*b - 4*a*c;

although normally I would not suppress the blanks.


As a beginner, I would not insert any space that was not required by the
language. A habit inherited from FORTRAN programming on punched cards,
where you really wanted to avoid continuation cards. Then, one day I was
bitten by

i=-1;

being parsed as

i =- 1;

by a VAX C compiler (=- was the anachronic form of -=, but some
pre-ANSI compilers still supported it). After that, I always left one
space between operators and operands, just to be on the safe side. This
kind of bugs (the compiler parses the code differently than the human) is
just too difficult to spot, so it pays the "effort" needed to avoid it.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #24
Dan Pop <Da*****@cern.ch> scribbled the following:
In <bv**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:
Which means that you've never been involved in some open/free source
code collaboration, where the ability to produce and read *meaningful*
diffs is essential. Any stylistical changes to the code are a major
source of "noise" and the rest of the collaboration would promptly
kick you out.


You guessed right. The only "real" programming I've ever done is for
university exercises and an actual commercial job. With both of these,
a change that does nothing else than make the code more readable is
accepted.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The truth is out there, man! Way out there!"
- Professor Ashfield
Nov 14 '05 #25
On 5 Feb 2004 18:02:56 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.helsinki.fi> wrote:
Dan Pop <Da*****@cern.ch> scribbled the following:
In <bv**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
Personally I'm a bit of a style Nazi myself. Whenever I have to edit
code someone else wrote, I take time to format it to "readable" style
first. Which means:

Which means that you've never been involved in some open/free source
code collaboration, where the ability to produce and read *meaningful*
diffs is essential. Any stylistical changes to the code are a major
source of "noise" and the rest of the collaboration would promptly
kick you out.


You guessed right. The only "real" programming I've ever done is for
university exercises and an actual commercial job. With both of these,
a change that does nothing else than make the code more readable is
accepted.


Its also worth noting that any code diff or version control tool that
takes meaningless whitespace into account should be abandoned. It
should always be possible to beautify dense code without aggravation.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #26
Mark McIntyre <ma**********@spamcop.net> spoke thus:
Its also worth noting that any code diff or version control tool that
takes meaningless whitespace into account should be abandoned. It
should always be possible to beautify dense code without aggravation.


Believe me, if it were in my power to use something other than
Microsoft's Visual Sourcesafe at my employment docimile, I certainly
would.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #27
In <bv**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
You guessed right. The only "real" programming I've ever done is for
university exercises and an actual commercial job. With both of these,
a change that does nothing else than make the code more readable is
accepted.


Keep in mind that readability is in the eye of the beholder. What's
more readable to you may be less readable to the person who wrote the
code in the first place. We had plenty of threads proving this, in this
very newsgroup.

The only consensus is that some form of indentation is better than
no indentation at all and that identifiers with meaningful names are
better than identifiers of the form oo0o00oo and l111ll1ll.

But once we start comparing the merits of different kinds of indentations
or identifier naming conventions, the Pandora's box is open...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #28
On Fri, 6 Feb 2004 02:18:06 +0000 (UTC), in comp.lang.c , Christopher
Benson-Manica <at***@nospam.cyberspace.org> wrote:
Mark McIntyre <ma**********@spamcop.net> spoke thus:
Its also worth noting that any code diff or version control tool that
takes meaningless whitespace into account should be abandoned. It
should always be possible to beautify dense code without aggravation.


Believe me, if it were in my power to use something other than
Microsoft's Visual Sourcesafe at my employment docimile, I certainly
would.


the vesion of vss that I last used actually had an option to ignore
whitespace. STR that it didn't actually work as such tho....
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #29
Dan Pop wrote:

In <bv**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> writes:
You guessed right. The only "real" programming I've ever done is for
university exercises and an actual commercial job. With both of these,
a change that does nothing else than make the code more readable is
accepted.


Keep in mind that readability is in the eye of the beholder. What's
more readable to you may be less readable to the person who wrote the
code in the first place. We had plenty of threads proving this, in this
very newsgroup.

The only consensus is that some form of indentation is better than
no indentation at all and that identifiers with meaningful names are
better than identifiers of the form oo0o00oo and l111ll1ll.

But once we start comparing the merits of different kinds of indentations
or identifier naming conventions, the Pandora's box is open...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de


I think it's possible to develop reasonably objective, nonrandom
standards of readbility. But some things done in the name of readability
fly in the face of prohibitions against early return, some formatting
conventions.

--
Les Cargill
Nov 14 '05 #30
Les Cargill wrote:
I think it's possible to develop
reasonably objective, nonrandom standards of readability.
I think that it's possible to develop several of them.

Take a look at the indent man page:

http://www.cs.umbc.edu/cgi-bin/man-cgi?indent

Look for the COMMON STYLES header.
But some things done in the name of readability
fly in the face of prohibitions against early return,
some formatting conventions.


You probably need to distinguish
between *coding* styles and *programming* styles.

Coding styles are adequately handled by a program like indent
which will reformat your code for you.
Any attempt to impose a particular coding style is pure mischief.
You should develop or adopt a coding style and -- stick to it!
Consistency is most important in your coding style.
It will help you spot mistakes.
If other programmers need to read, understand and maintain your code,
they will quickly become accustomed to your style
or they will reformat it with indent.

Programming style, on the other hand, is something much more serious.
It's about nothing less than good programming practice --
developing good programming habits and avoiding bad programming habits.
For C programmers, it's about [self]discipline.
Good C programmers try to get their compiler to detect bugs for them.
They also include assertions to help them trap bugs at run time.
They use const to make their code easier for other programmers
to analyze. They avoid global and static variables.
They pass by value or const reference so that other programmers
need not be concerned about whether or not a function call modifies
its actual arguments. etc.

Nov 14 '05 #31
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message news:<40**************@jpl.nasa.gov>...
Ed Morton wrote:
Joona I Palaste wrote:
Can the C beautifier also beautify Java?


Maybe, but I wouldn't trust cb with Java or even C++.
There are plenty of beautifiers
for those and other languages out there though, e.g. take a look at

http://ldp.homegrownhost.net/HOWTO/C...or_others.html


BEWARE!

Code "beautifiers" are not necessarily [style] reformatters.
Most beautifiers insert text and embedded printer control sequences
that your compiler will *not* accept.

You also need to verify that
reformatting did not change the meaning of your code.
Always compile both the original and the reformatted versions
of your code and verify that the resulting objects are identical.

Ok, how about gnu indent - is it to be trusted?
Nov 14 '05 #32

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: HolaGoogle | last post by:
hi there, i've 2 questions for you guys.... 1: is there any way to "force" a session_onend(), session timeout or at least call my logout method when a user leaves the application window without...
19
by: CMAR | last post by:
I have the following markup. The problem is that the browser, e.g., IE6, inserts several lines of blank space between the <div> and the following table. Is there a way to minimize that vertical...
2
by: andy.dreistadt | last post by:
Hi all, I came across another problem that is probably pretty easy but, again, due to my rusty-ness with C, I'm a little stumped. I have a struct that looks like this: /* Instrument Data...
7
by: Calan | last post by:
Mike, Your code on the dynamic input checking was excellent and very well explained. (The only thing I had to do was change the test for text input to be "1 > len of text", instead or "0 >...
27
by: Terry Olson | last post by:
I'm trying to build a table on an output page based on text input by the user. And what I am trying to do is create 4 table data boxes on a row, then start a new row on the 5th one. But I can't...
0
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
2
by: Jon Paal [MSMD] | last post by:
This "show-hide" works in IE7 but fails in FF2 - Error in FF: "this.children is not a function" Can someone help ? <DIV id=sect style="display:block;" onclick="javascript:if...
17
by: sagar | last post by:
Hi, I have a C file(add.c) in which i have a function called add.now i want to call the same add function from another file sub.c .Can any1 tell how to do that... Thanks in advance Mark
22
by: sheldonlg | last post by:
I am looking for a clean solution to a problem that I solved in, what I call, a "dirty" way. Here is what I want to do. I have a dropdown list. Clicking on an item in the dropdown list invokes...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.