Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Suggesstion for standard upgrade

Reply
Thread Tools

Suggesstion for standard upgrade

 
 
Jon
Guest
Posts: n/a
 
      10-31-2010
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.


 
Reply With Quote
 
 
 
 
Geoff
Guest
Posts: n/a
 
      10-31-2010
On Sat, 30 Oct 2010 23:50:44 -0500, "Jon" <(E-Mail Removed)> wrote:

>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.
 
Reply With Quote
 
 
 
 
Tom St Denis
Guest
Posts: n/a
 
      10-31-2010
On Oct 31, 12:50*am, "Jon" <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-31-2010
On 2010-10-31, Tom St Denis <(E-Mail Removed)> wrote:
> 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HI can give suggesstion aslamhenry@yahoo.com C Programming 11 09-25-2007 12:34 AM
HI can give suggesstion aslamhenry@yahoo.com C Programming 0 09-18-2007 02:11 PM
add pexpect to the standard library, standard "install" mechanism. funkyj Python 5 01-20-2006 08:35 PM
How standard is the standard library? steve.leach Python 1 04-18-2005 04:07 PM
GUI .. Ruby .. Suggesstion Mohammad Khan Ruby 3 05-14-2004 10:26 AM



Advertisments