You are here: Re: Coding style... « All PHP « IT news, forums, messages
Re: Coding style...

Posted by Lόpher Cypher on 01/03/06 00:04

Curtis wrote:

>> I started programming in Pascal, and when I started
> learning C++, and
>> later C-like-syntax languages, I was finding pascal-style
> blocks better.
>> But I think that for C-like-syntax languages opening
> blocks with a brace
>> on the same line is so common that one can say it's a
> "standard" :)
>> Anyways, you'd get used to it over time :)
>
> I hope not. Heh.
>
> A person can get used to about anything, but it just makes
> too much sense to me to use the visual symmetry of
>
> {
> {
> {
> }
> }
> }
>
> I can't think of a good reason NOT to, with the exception of
> some additional vertical white space. And that's not so bad,
> as I like to comment from the 50th column to the 80th, and
> that white space is often good for comment continuation.
> Like so:
>
> 1 50
> ____________________________________
> if (!$skip) # If comment
> { # really vital
> codestuff(); # do it here.
> }
>
>
>
> I find that MUCH easier to read than:
>
> // Do the foo to the fee because bar.
> if (!$skip)
>
> codestuff();
> }
>
> // More comments blah blah blabbity-blab.
> if ($skyisfalling) {
> morecodestuff();
> }
>
> My style was almost a requisite back in the days of assembly
> language programming, and with good variable name selection
> code is more self-documenting these days, but I find the
> style still has a lot to be said for it, particularly if the
> coder comments about the nonobvious aspects of the
> algorithm.
>

Well, one of the reasons could be the software one uses :) I use, for
instance, Zend Studio, and it automatically inserts the braces in
C-style :) It's just quicker :) I got a habit of using phpDoc blocks
(also completed automatically on "/**" <enter>), and put them before
variables and functions, describing them, and regular comments before
the line:

/**
* Does some processing.
*
* @param int $var Some parameter.
* @return bool Whatever
*/
function foo($var) {

# $var gets squared
$var *= $var;
...

# $var gets doubled
$var *= 2;
...
}

Using comments on the side could sometimes be less readable, especially
when the line is long; also, if you have a comment spanning three lines
and you need to insert something in-between, you'd have to copy over the
comment :)


--

- lΓΌpher
---------------------------------------------
"Man sieht nur das, was man weiß" (Goethe)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация