Posted by Curtis on 01/02/06 10:20
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.
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>';
}
?>
.... assuming one wanted to keep the braces, and didn't want
to escape quotes.
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.
--
Curtis
Visit We the Thinking
www.wethethinking.com
An online magazine/forum
devoted to philosophical
thought.
[Back to original message]
|