Re: [PHP] using ($test)?$true:$false in a string
On Mon, 2005-11-21 at 10:43, Jochem Maas wrote: > Richard Heyes wrote: > > Robert Cummings wrote: > > > >> On Mon, 2005-11-21 at 10:02, Richard Heyes wrote: > >> > >>> Readability is in the eye of the beholder. > >> > >> > >> > >> But efficiency isn't ;) > > yes it is actually - everything is in the eye of the beholder. > it just so happens that we often have consensus ;-) *lol* I was hoping nobody would call me on that ;) > with regard to the bulldozer metaphor - true that using sprintf() is > such a simple case may be excessive BUT I was merely introducing the OP to > something new (possibly) - anyone asking such 'simple' questions is > not at a stage that this kind of efficiency is an issue (i.e. give > them 'whats possible' before telling them 'whats best') > > the sprintf() example leaves lots of room for creativity and > code reuse (even by relative newcomers) or aleast the possiblity of > writing more managable code Chris Boget liked it anyway :-) True, coming from a C background I can attest to my love for the *printf series of functions. In fact, 6 years ago I might have actually liked Java more if they had bothered to add it (I've heard it's been added since). > PS - Robert Cummings, I totally agree with your general comments on > internals@ regarding migration/irritation/etc btw. and if I didn't > spend so much time on 'fixing' my working code I might have had time > to take a proper look at your InterJinn project - more's the pity > that I haven't been able to so far :-/ *lol* Might be good till I clean the docs up. Also I've been adding a flurry of stuff lately to support better inclusion of external resources like JavaScript. I want clean including of javascript modules within templates and modules such that requesting the resource never includes it twice and so that I have the same replaceable modularity that exists in InterJinn. Also I want to have dependencies managed internally rather than having to think about it myself. I guess I'm making a mini JavaScript InterJinn lib *lol*. This will tie in nicely with my work to bring in almost transparent XmlHttpRequest functionality. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On Mon, 2005-11-21 at 10:31, Richard Heyes wrote: > Robert Cummings wrote: > > On Mon, 2005-11-21 at 10:02, Richard Heyes wrote: > > > >>Readability is in the eye of the beholder. > > > > > > But efficiency isn't ;) > > Try measuring the difference between the various methods over a > realistic number of iterations, eg. 100. There's little point in going > through ones code trying to "optimise" these things. Sure you might gain > a millisecond here or there, but so what? You'd have to have a > *seriously* busy site for that to make a difference. I won't disagree, but I'd say being in the habit of writing semi-optimal code in the fist place, will save you needing to learn new habits later when you do work on a *seriously* busy site :) I didn't argue for '' versus "", but sprintf() is a cycle pig in comparison to either. not only that, but since it's not a keyword, it incurs stack overhead. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On 21 Nov 2005, at 15:43, Jochem Maas wrote: using sprintf() is such a simple case may be excessive BUT I was merely introducing the OP to something new (possibly) - anyone asking such 'simple' questions is not at a stage that this kind of efficiency is an issue (i.e. give them 'whats possible' before telling them 'whats best') sprintf is also a good example of a different way of thinking about string interpolation, and what's more it's remarkably close to the whole concept of using prepared statements in SQL, a measure that can gain you both speed and security, plus it's supported very nicely in PDO in PHP 5.1. A tangent I know, but a useful one nonetheless. Hey, and I remember when "print using" was considered a 'power user' feature in BASIC in 1981! Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture [EMAIL PROTECTED] | http://www.synchromedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
Richard Heyes wrote: Robert Cummings wrote: On Mon, 2005-11-21 at 10:02, Richard Heyes wrote: Readability is in the eye of the beholder. But efficiency isn't ;) yes it is actually - everything is in the eye of the beholder. it just so happens that we often have consensus ;-) with regard to the bulldozer metaphor - true that using sprintf() is such a simple case may be excessive BUT I was merely introducing the OP to something new (possibly) - anyone asking such 'simple' questions is not at a stage that this kind of efficiency is an issue (i.e. give them 'whats possible' before telling them 'whats best') the sprintf() example leaves lots of room for creativity and code reuse (even by relative newcomers) or aleast the possiblity of writing more managable code Chris Boget liked it anyway :-) PS - Robert Cummings, I totally agree with your general comments on internals@ regarding migration/irritation/etc btw. and if I didn't spend so much time on 'fixing' my working code I might have had time to take a proper look at your InterJinn project - more's the pity that I haven't been able to so far :-/ Try measuring the difference between the various methods over a realistic number of iterations, eg. 100. There's little point in going through ones code trying to "optimise" these things. Sure you might gain a millisecond here or there, but so what? You'd have to have a *seriously* busy site for that to make a difference. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
Robert Cummings wrote: On Mon, 2005-11-21 at 10:02, Richard Heyes wrote: Readability is in the eye of the beholder. But efficiency isn't ;) Try measuring the difference between the various methods over a realistic number of iterations, eg. 100. There's little point in going through ones code trying to "optimise" these things. Sure you might gain a millisecond here or there, but so what? You'd have to have a *seriously* busy site for that to make a difference. -- Richard Heyes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On Mon, 2005-11-21 at 10:02, Richard Heyes wrote: > > Readability is in the eye of the beholder. But efficiency isn't ;) Cheers, Rob -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
Robert Cummings wrote: On Mon, 2005-11-21 at 09:42, Chris Boget wrote: and I feel it would be more elegant to be able to do something like: $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; $templateStr = 'first part of string %s rest of string'; $outputStr = sprintf($templateStr, (($a==$b)?$c:$d)); That is so totally slick! I'm definitely going to have to remember this neat little trick! :) That's like using a bulldozer to tidy your living room. Why not use the following even more readable style (and more efficient)? $outputStr = 'first part of string ' .($a == $b ? $c : $d) .' rest of string'; Readability is in the eye of the beholder. -- Richard Heyes http://www.phpguru.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On Mon, 2005-11-21 at 09:42, Chris Boget wrote: > >> and I feel it would be more elegant to be able to do something like: > >> $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; > > $templateStr = 'first part of string %s rest of string'; > > $outputStr = sprintf($templateStr, (($a==$b)?$c:$d)); > > That is so totally slick! I'm definitely going to have to remember this > neat little trick! :) That's like using a bulldozer to tidy your living room. Why not use the following even more readable style (and more efficient)? $outputStr = 'first part of string ' .($a == $b ? $c : $d) .' rest of string'; Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
and I feel it would be more elegant to be able to do something like: $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; $templateStr = 'first part of string %s rest of string'; $outputStr = sprintf($templateStr, (($a==$b)?$c:$d)); That is so totally slick! I'm definitely going to have to remember this neat little trick! :) thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On 18 Nov 2005, at 20:13, Dylan wrote: $var = "first part of string ".(($a==$b)?$c:$d)." rest of string"; and I feel it would be more elegant to be able to do something like: $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; Strange as it may seem, you'll probably find that this is the fastest method: 'first part of string '.(($a==$b)?$c:$d).' rest of string' I benchmarked this a while ago and was surprised to find that multiple concats with single quotes are significantly faster than interpolation. Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture [EMAIL PROTECTED] | http://www.synchromedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
Dylan wrote: Hi Is it possible to use the ($test)?$true:$false construction in a (double quoted) string without dropping out of the string and concatenating? I have many lines like: $var = "first part of string ".(($a==$b)?$c:$d)." rest of string"; and I feel it would be more elegant to be able to do something like: $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; $templateStr = 'first part of string %s rest of string'; $outputStr = sprintf($templateStr, (($a==$b)?$c:$d)); Cheers Dylan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
Richard Lynch wrote: > On Fri, November 18, 2005 2:13 pm, Dylan wrote: >> Is it possible to use the ($test)?$true:$false construction in a >> (double >> quoted) string without dropping out of the string and concatenating? I >> have >> many lines like: >> >> $var = "first part of string ".(($a==$b)?$c:$d)." rest of string"; >> >> and I feel it would be more elegant to be able to do something like: >> >> $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; > > You could try it faster than I could answer... > > If it doesn't work, maybe do: > $z = $a==$b ? $c : $d; > $var = "first part of string $z rest of string"; > > Burying too much login in the middle of your data/string is probably a > Bad Idea (tm) anyway. > I already discounted that since we're talking about a couple of hundred instances, each of which would need a different $z. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] using ($test)?$true:$false in a string
On Fri, November 18, 2005 2:13 pm, Dylan wrote: > Is it possible to use the ($test)?$true:$false construction in a > (double > quoted) string without dropping out of the string and concatenating? I > have > many lines like: > > $var = "first part of string ".(($a==$b)?$c:$d)." rest of string"; > > and I feel it would be more elegant to be able to do something like: > > $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; You could try it faster than I could answer... If it doesn't work, maybe do: $z = $a==$b ? $c : $d; $var = "first part of string $z rest of string"; Burying too much login in the middle of your data/string is probably a Bad Idea (tm) anyway. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] using ($test)?$true:$false in a string
Hi Is it possible to use the ($test)?$true:$false construction in a (double quoted) string without dropping out of the string and concatenating? I have many lines like: $var = "first part of string ".(($a==$b)?$c:$d)." rest of string"; and I feel it would be more elegant to be able to do something like: $var ="first part of string {(($a==$b)?$c:$d)} rest of string"; Cheers Dylan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php