|
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]
|