[UPHPU] reassigning foreach function opposed to all at once

Jeremy Burgess jeremy at edgecast.net
Thu Apr 12 13:42:01 MDT 2007


Scott Hill wrote:
> On 4/11/07, Wade Preston Shearer <lists at wadeshearer.com> wrote:
>> Is there a performance difference between…
>>
>> $pretty_user_url = substr($author->user_url, 7);
>> $pretty_user_url = str_ireplace('www.', '', $pretty_user_url);
>> $pretty_user_url = rtrim($pretty_user_url, '/');
>>
>> …and…
>>
>> $pretty_user_url = rtrim(str_ireplace('www.', '', substr($author-
>> >user_url, 7)), '/');
>>
>> …or is it just a preference of legibility?
> Most of the time I HAVE to do it long hand just so I can figure out 
> how it
> works or try to keep straight in my mind what I am trying to do.  
> Sometimes,
> after I get it working, I change it to a one liner just to impress 
> someone
> who may see the code in the future.  Most of the time, it's not worth the
> effort because it either breaks and I have to spend time 
> troubleshooting or
> no one ever sees the code.  In other words (after all that), I usually
> prefer the first example so that it's easier for ME to figure it out 
> later.
I just like concise code so if I can assign the variable in one line I 
find it easier to follow the code at a glance. When I need to examine 
the nested statements I'll quickly expand it in place. The code will 
still run and when I'm happy with it I may choose to flatten it out again

$pretty_user_url = rtrim(
    str_ireplace(
        'www.',
        '',
        substr(
            $author->user_url,
            7
        )
    ),
    '/'
);

-Jeremy


More information about the UPHPU mailing list