|
Posted by J.O. Aho on 01/03/06 00:06
Curtis wrote:
> J.O. Aho <user@example.net> wrote in message
> news:41t3tcF1gctppU1@individual.net...
>> Curtis wrote:
>>
>>> <?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.
>> This generates less work for PHP than what
>>
>> <?PHP
>> if ($user->uid) {
>> echo "<li><a href=\"logout\" title=\"\">Log
> Out</a></li>";
>> } else {
>> echo "<li><a href=\"login\" title=\"\">Log In</a></li>";
>> }
>> ?>
> I'm not sure the tradeoff is anywhere near worth it, though.
> Better more work for PHP, I'd think, that be driven crazy as
> a code maintainer trying to read the mixed PHP-MTML soup.
It's first on really slow machines you will be able to notice it, but today
most machines are quite fast, I guess quite much is for so many uses a CPU
demanding environment on their desktop.
I do agree that the code is difficult to read, specially the way it's written
in the original post. For one or two lines of HTML printed from PHP is all
okey, but when you have larger amounts of HTML it's better to not process that
at all.
> I suspect that on most sites the speed improvement, if any,
> would be marginal. I can't speak from much experience, but
> in the project I'm working on--a text filter--the text
> processing done by PHP scanning text twenty-plus times and
> substituting this for that would probably dwarf the output
> of a little HTML as PHP strings.
On a ~2000MHz x86, the time difference is something like 0.001s for 1000 rows
of text, so in most servers today you would just spend extra money when modify
the code and the gain ain't worth it. But what can be worth is to make a code
more readable with comments, which usually seems to be missing.
//Aho
Navigation:
[Reply to this message]
|