Re: Coding style...



Curtis wrote:
> J.O. Aho <user@xxxxxxxxxxx> wrote in message
> news:41t3tcF1gctppU1@xxxxxxxxxxxxxxxxx
>> 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
.



Relevant Pages

  • Re: How do we get there from here?
    ... > then sub the whole of that generated markup into the template? ... layed out on the fly, a simple IMG tag, or even an entire HTML document. ... PHP scripting provides 10 times the features of both of these ... idea as tokens can eliminate a huge amount of maintance, ...
    (comp.databases.pick)
  • Re: query string passing woes........ help... please....
    ... |> | offer any help other than saying that my validation could be FAR more ... I'm a total newbie at php. ... The easiest way for you would be to make the html form called form.php ... $_SESSION array using the same names. ...
    (alt.php)
  • Re: HELP - Cant change Include Path
    ... Here is my php.ini path for the php.ini in both php and sql dirs: ... which did work on the remote linux server and sent me some mail ... Although my gmail acct picked the mail up as ... an attachment instead of as html - but gmail is really wierd about ...
    (comp.lang.php)
  • Re: How do we get there from here?
    ... server-side-scripted html. ... This is a simple example with very little php scripting. ... means that the version of the php pre-processor on your web server must ... >>> The browser never sees anything not sent to it by the script. ...
    (comp.databases.pick)
  • Re: PHP-Yes, HTML-No --- Why?
    ... Because the files, when downloaded, are called .php and have absolutely no php in them:) ... But the extension doesn't match the contents of the file. ... Surely a dynamic web server should appear exactly the same as a static one - all files that contain HTML when viewed should be called .html. ...
    (comp.lang.php)