Re: To quote or unquote strings in an echo?



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
.



Relevant Pages

  • Re: Create Table SQL not working
    ... Tim & Jeff seemed to be so ... > concatenating the Number (converted to a string) to the end of a constant ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Advantage of Parameters
    ... the method where you are concatenating the string. ... new Parameter object, and then during the execution of the Command, it has to ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Multi-valued field
    ... I like the idea of concatenating the values as a string, ... way around writing out the code? ... the child record values into a text string: ...
    (microsoft.public.access.queries)
  • Re: How can I save a Document from a Template witha Conditional File Name Pre-Defined
    ... Use the .Result property of each formfield to obtain the data entered into ... Then create a string to use as the file name by concatenating the ... or Proposal I want to be able to save the individual Contract Files ...
    (microsoft.public.word.vba.general)
  • Re: string concat vs. join/implode
    ... $str = array; ... echo implode); ... concatenating a char and adding an element to an array, ... that'll create some overhead for the second version. ...
    (comp.lang.php)