Reply to Re: Coding style...

Your name:

Reply:


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)

[Back to original 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

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