Suggesstion for standard upgrade

J

Jon

A utility, written in (duh) Perl. ;) JK! A standard utility (written in
C, for those of you "nice" (and one can only hope that you are) people
who don't grok "the richness of the language that is English") that
changes the *abhorrent* programming style of some, to something more
decipherable.

A. Example of the abhorrency:

if (x) {
// stmt 1
// stmt 2
}

if (x) {
// stmt
}

B. Which of course any *sane* programmer would instead write as:

if (x)
{
// stmt 1
// stmt 2
}

if (x)
// stmt

(There, I "said" that, just right). Disclaimer: I am not a compiler.
 
G

Geoff

A utility, written in (duh) Perl. ;) JK! A standard utility (written in
C, for those of you "nice" (and one can only hope that you are) people
who don't grok "the richness of the language that is English") that
changes the *abhorrent* programming style of some, to something more
decipherable.

A. Example of the abhorrency:

if (x) {
// stmt 1
// stmt 2
}

if (x) {
// stmt
}

B. Which of course any *sane* programmer would instead write as:

if (x)
{
// stmt 1
// stmt 2
}

if (x)
// stmt

(There, I "said" that, just right). Disclaimer: I am not a compiler.

Such a tool exists. It's called GNU Indent. GIYF.
 
T

Tom St Denis

A utility, written in (duh) Perl. ;) JK! A standard utility (written in
C, for those of you "nice" (and one can only hope that you are) people
who don't grok "the richness of the language that is English") that
changes the *abhorrent* programming style of some, to something more
decipherable.

A. Example of the abhorrency:

if (x) {
   // stmt 1
   // stmt 2

}

if (x) {
   // stmt

}

B. Which of course any *sane* programmer would instead write as:

if (x)
{
   // stmt 1
   // stmt 2

}

if (x)
   // stmt

(There, I "said" that, just right). Disclaimer: I am not a compiler.

Why is 'B' the "good" example? In the first half you have extra lines
for your { } ... that just makes the file longer and not easier to
read. Ultimately, indenting makes it easier to read, e.g.

if (x)
{
do();
}

is harder to read than

if (x)
{
do(x)
}

Which is easier to read as

if (x) {
do(x)
}

Since the visual information you need is the indenting on "do()" not
the {} to tell levels of nesting.

In the latter half of your 'B' example that form is actually dangerous
as I've seen it numerous times turn into

if(x)
do();

To something like

if (x)
debug_cmd();
do(x);

Which of course is wrong. Putting the {} braces around even a single
statement co-routine is just smart since it allows ease of adding
debug/additional code without worrying about flow.

And as Geoff pointed out GNU indent can help you indent/space your
code. It won't add/remove braces,etc though...

Tom
 
S

Seebs

Why is 'B' the "good" example?

Because he's trolling.

Come on, calling the K&R style "abhorrent", referring to an alternative
as what "any *sane*" programmer would use, arguing about indentation
styles at all?

100% pure trolling. You got hooked.

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top