Re: Variable as an index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yes, i agree with this. Even if it takes a few nano seconds more to write
out more understandable code, it's worth doing it because code management is
more important than sqeezing out the last nano second. And then also an
$var = "Hello";
echo "$val World";

has less characters than and is more readable than

$var = "Hello";
echo $var ." World";

So it would take maybe a few nano seconds less to read it from the hard
drive. And we all know that disk I/O is more expensive than pushing around
variables in main memory in terms of time. And RAM is soo cheap these days.

Tim-Hinnerk Heuer

http://www.ihostnz.com


On Mon, Dec 22, 2008 at 12:50 PM, Anthony Gentile <asgentile@xxxxxxxxx>wrote:

> True, it might mean the very slightest in milliseconds...depending on what
> you're doing/hardware. However, no harm in understanding the difference/how
> it works.
> Many will code echo "Hello World" and echo 'Hello World'; and never know
> the
> difference, I just happen to think being aware of the details will help for
> the long term programmer.
> Since, I brought it up, I'll go ahead and give another example. Ternaries
> that make a lot of people feel awesome because a lot is being accomplished
> in one line are also more opcodes than their if-else statement
> equivalents...and often times can be more confusing to future maintainers
> of
> the code.
>
> Anthony Gentile
>
>
>
> On Sun, Dec 21, 2008 at 6:20 PM, Chris <dmagick@xxxxxxxxx> wrote:
>
> > Anthony Gentile wrote:
> >
> >> for e.g.
> >> $var = 'world';
> >> echo "hello $var";
> >> vs
> >> echo 'hello '.$var;
> >>
> >> The first uses twice as many opcodes as compared to the second. The
> first
> >> is
> >> init a string and adding to it the first part(string) and then the
> second
> >> part (var); once completed it can echo it out. The second is simply two
> >> opcodes, a concatenate and an echo. Interpolation.
> >>
> >
> > I'd call this a micro-optimization. If changing this causes that much of
> a
> > difference in your script, wow - you're way ahead of the rest of us.
> >
> >
> >
> http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html
> >
> > http://www.phpbench.com/
> >
> > --
> > Postgresql & php tutorials
> > http://www.designmagick.com/
> >
> >
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux