The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

FW: [OT] Coding style nazis



Hi Andy,

Whooa - religious war stuff :-)

Following books are good resources.

- Writing Solid Code. Steve Maguire. Microsoft Press.
- Code Complete. Steve McConnell. Microsoft Press.
- Enough Rope To Shoot Yourself in the Foot, Allen Holub.

Assuming your first example had the code between braces actually indented
then both are fairly acceptable styles.  If the first example didn't have
the code between the braces indented then I'm surprised anyone would claim
it is better since indenting a block of compound statements is such normal
practice that most software engineers 'recognise' it easily by habit.

Most likely reason for people claiming the second example is 'wrong' is
because the braces are also indented. An often used intellectual argument
for this is that the braces identify a compound statement ie. a number of
individual expression statements or nested compound and control statements,
that are effectively one statement.  Hence the braces should be at the
level
that a single line expression statement would normally exist at ie.

for (my $x=0;$x<@_;$x+=2)
{
somestuff;
somestuff;
somestuff;
somestuff;
somestuff;
}

However I think most people agree that consistency within a module/file and
if possible a project is the most important.  I personally think next comes
commenting and use of white space.

Of course as always, and more so in this case than most, these views are
simply my opinion and I realise others may not agree.


HTH

Cheers
Shane

> -----Original Message-----
> From: UKHA [mailto:ukha@xxxxxxx]
> Sent: Friday, 9 July 2004 7:35 a.m.
> To: ukha_d@xxxxxxx
> Subject: [ukha_d] [OT] Coding style nazis
>
>
> Ok,
>
> Totally OT, but there you go.
>
> I'm looking for some decent resources that will explain why my
> coding style is "wrong", anyone have any?
>
> I'm referring to stuff like why:
>
> for (my $x=0;$x<@_;$x+=2) {
> somestuff;
> somestuff;
> somestuff;
> somestuff;
> somestuff;
> }
>
>
> is better than:
>
> for (my $x=0; $x < @_; $x+=2)
> 	{
> 	somestuff;
> 	somestuff;
> 	somestuff;
> 	somestuff;
> 	somestuff;
> 	}
>
>
> (assuming yahoo doesn;t make a right old pigs ear of it)
>
>
> Andy
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>






UKHA_D Main Index | UKHA_D Thread Index | UKHA_D Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.