|
Posted by Lόpher Cypher on 01/02/06 11:19
Curtis wrote:
> Occasionally I encounter this style of coding, where the
> coder is apparently religiously opposed to outputting HTML
> with PHP. The result is very difficult to read:
>
> <?php
> global $user;
> if ($user->uid) {?> <li><a href="logout" title="">Log
> Out</a></li>
> <?php } else {?> <li><a href="user/login" title="">Log
> In</a></li>
> <?php }?>
>
> Ten characters in order to type that closing brace? Wow.
That's just bad style :)
>
> What's the thinking behind this style, and what's wrong with
> the following?
>
> <?php
> global $user;
> if ($user->uid)
> {
> print '<li><a href="logout" title="">Log Out</a></li>';
> }
> else
>
>
> print '<li><a href="user/login" title="">Log
> In</a></li>';
> }
> ?>
Nothing is wrong with it :) In fact, that'd be preferred :)
>
> ... assuming one wanted to keep the braces, and didn't want
> to escape quotes.
Btw, I prefer to rather escape quotes (\"). I believe "" is a standard
for xhtml, and there was some slight difference between '' and "" in
php. However, for strings in php, you can't go wrong with "" :)
>
> While I'm on the subject, I note that a lot of PHP coders do
> the opening braces like so:
>
> <?php
> if ($something) {
> do this();
> } else
>
> dothat();
> }
> ?>
>
>
> I don't find this as readable/maintainable as lining up
> opening and closing braces the same way I would line up
>
> begin
> begin
> end
> end
>
> in Pascal--especially when things get nested three or four
> levels deep.
>
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 :)
--
- lΓΌpher
---------------------------------------------
"Man sieht nur das, was man weiΓ" (Goethe)
Navigation:
[Reply to this message]
|