Re: Re: PHP textbook suggestions?

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

 



You're missing the point-- it's not that there is a practical
difference in the examples, it's that there IS a difference, the
students see it, and it is an extra point of confusion that isn't
needed if one is being consistent.

I completely recognize that the practical effects of the differences
are small, but the learning effects of the inconsistencies is much
larger, particularly with a group of students that are not techies,
not geeks, not computer science or IT students...

c

On 4/10/07, LuKreme <kremels@xxxxxxxxx> wrote:
On 6-Apr-2007, at 08:13, Chris Lott wrote:
> echo substr("abcdef", 1);
>
> So they naturally want to know-- why the double quotes? And there's no
> good logical reason for double quotes in the example-- and there are
> languages where the function could take a variable to be interpolated
> that DOES need double quotes-- so it is very confusing to them.

But it's quite simple: it's a matter of preference, style, or just
the mood of the programmer.  Basically, there is NO difference between

echo substr("abcdef", 1);
echo substr('abcdef', 1);

Oh sure, there is some number of nanoseconds difference in evaluation
time, but that's meaningless as it is an insignificant amount of time
(and takes millions and millions of iterations to make any
perceivable difference).

Use whichever you want.  For me, I use " mostly, and usually only use
' when I am enclosing "'s to save myself having to escape them.

On 5-Apr-2007, at 14:52, Chris Lott wrote:
> print 'The cost is ' . $cost;
> NOT
> print "The cost is $cost";

But that is certainly a silly destination to make.  Both are
perfectly valid and, in fact, I would argue the latter is better as
it is clearer, cleaner, and shorter.

> echo substr('abcdef', 1);
> NOT
> echo substr("abcdef", 1);

Both are perfectly fine.  I'd use the latter myself as I tend to
reserve the single quotes for enclosing strings containing double
quotes, but that's just my preference.  I certainly wouldn't deign to
argue that my way was 'correct'.

--
A: You can never go too far. B: If I'm gonna get busted, it is *not*
gonna be by a guy like *that*.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Chris Lott

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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