[TYPO3-core] RFC Feature #16189: Optimize stdWrap usage for TypoScript content element CLEARGIF

JoH asenau info at cybercraft.de
Mon Nov 1 00:14:45 CET 2010


> why are you checking isset($conf['width.'])? To avoid notices? Then
> you should also check isset($conf['width']).

Nope - since the check is done to avoid the stdWrap function call at all.
If there is no "dotted" key, there can't be stdWrap, so no need to do call the function just to the same unchanged string.
 
> And then: nested ternary operators are not very readable. ($wrap =
> ...) 

good point - although I like them much more than the usual if/else constructs and I am not sure about performance here.
 
> Another suggestion:  If your touching this part anyways I would go
> for a refactoring. Long strings concatenated using other strings and
> variables are also very unreadable. It's hard to say how the final
> string will look like and what are the dynamic part in it. I formed a
> habit to use sprintf in those situations:
> 
> $theValue = $this->cObj->wrap(
> sprintf('<img src="%sclear.gif" width="%s" height="%s" %s alt=""
> title="" />',
> $GLOBALS['TSFE']->absRefPrefix,
> $width,
> $height,
> $this->cObj->getBorderAttr($wrap)
> ),
> $wrap
> );
> 
> Minor thing: As the title tag is an optional tag and empty in this
> case I would remove it from here...

Well - as with the ternary operators, for me the major point is not readability for developers but performance.
So, if it's faster, I will change it - if not, I would like to get some other opinions, since I would prefer just changing the "layout" of the code to improve the readability then.

So are there any reliable sources for benchmarks of sprintf and ternary operators vs. if/else?

Abyway, thx for your feedback.

Joey

-- 
Wenn man keine Ahnung hat: Einfach mal Fresse halten!
(If you have no clues: simply shut your gob sometimes!)
Dieter Nuhr, German comedian
Xing: http://contact.cybercraft.de
Twitter: http://twitter.com/bunnyfield
TYPO3 cookbook (2nd edition): http://www.typo3experts.com


More information about the TYPO3-team-core mailing list