Re: To quote or unquote strings in an echo?
- From: Mechphisto <mechphisto@xxxxxxxxx>
- Date: Thu, 9 Apr 2009 07:14:33 -0700 (PDT)
On Apr 8, 5:12 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
Lars Eighner wrote:
Why are single quotes better?
Because the string is not scanned for variable to be expanded. Since
this operation is not necessary in this case, performing is a waste of
time.
Wrong. Both string parsers (for double- and single-quotes) will run for the
same amount of time. They are, in essence, finite state machines that
behave different (one expands variables, the other does not).
However, for a double-quoted string with no dollar signs, the running time
will be the same as the single-quote one as it'll run the same exact way.
Complexity of both parsers will be O(n) in this case, as neither of them
has to access the symbol table.
And commas for concactination?
It is not concactinating. That's another waste of time.
Say it: using commas within echo() is a language construct. echo() itself is
a language construct that behaves differently from most functions, and
treats the comma operator differently.
In any other circumstances, a set of comma-separated items not in a function
call will evaluate all of them left-to-right, and the return value will be
the evaluation of the rightmost item IIRC. But if you call echo() with a
set of comma-separated values, echo() will add them to the output buffer,
in order...
... which leads us to the matter of concatenating stuff. As echo() is a
language construct, and that *lots* of people use concatenation, we can
safely assume that the devs have tweaked the interpreter to not concatenate
the string in-line, but to behave as commas (concatenate it all to the
output buffer). And, even if it was concatenating the string beforehand,
the complexity wouldn't be too different from the complexity of
concatenating every item to the output buffer. Heck, run-time would be
faster by concatenating if the output buffer would be off, just because of
the extra I/O calls for flushing!!
As I always say: focus on the overall complexity of your algorithms. Don't
worry about premature optimization. Leave this kind of stuff to the parser
and compiler.
Cheers,
--
Whoa! That's a lot to try to take in for this liberal arts grad. :)
But I think I understand your point.
Thanks for the info and the tips from before!
Liam
.
- References:
- To quote or unquote strings in an echo?
- From: Mechphisto
- Re: To quote or unquote strings in an echo?
- From: Lars Eighner
- Re: To quote or unquote strings in an echo?
- From: Mechphisto
- Re: To quote or unquote strings in an echo?
- From: Lars Eighner
- To quote or unquote strings in an echo?
- Prev by Date: Re: Reverse "LIKE" sql statement
- Next by Date: Re: Simultaneous calling two PHP scripts
- Previous by thread: Re: To quote or unquote strings in an echo?
- Next by thread: What is a good ide to use?
- Index(es):
Relevant Pages
|