|
Posted by Toby A Inkster on 11/30/07 11:07
taps128 wrote:
> I can't stop thinkign this is to complicated to read. Wouldn't be simple
> to just use the GLOBAL keyword for the global namespace, so this:
> A::foo() will run the function foo from the A namespace, and this
> GLOBAL::A::foo() will run the static mehod foo of class A from the
> global namespace.
Firstly, what did I tell you in that "Assigning variables in ifs" thread?!
"GLOBAL::A::foo()" is a waste of 6 bytes! Six precious bytes!
::A::foo() is clear when you consider namespaces to be a bit like Unix
paths. "A/foo.txt" means "from the current directory, find subdirectory A,
and in there, look at file foo.txt". However, "/A/foo.txt" has an entirely
different meaning -- "from the root directory, find subdirectory A and in
there, look at file foo.txt".
Consider namespaces, classes and methods to be like a Unix file system,
but with :: as a path separator instead of /, and it all becomes clear.
The "namespace" keyword then becomes equivalent to "chdir". It takes the
mystery out of namespaces by making them work like something you're
already familiar with.
That said, it's probably going to be pretty rare when you're going to
explicitly want to reference the global namespace.
If you're coding without namespaces, everything's already in the global
namespace, so you never need to explicitly reference it.
If you're coding in a namespace and you've defined your own function
preg_match(), then chances are, when you call preg_match(), it's your own
function that you want to run -- the main exception being that if your
preg_match() function is a wrapper around the global preg_match, then your
preg_match will need to call the global preg_match, and then you'll need
to explicitly reference the global namespace.
Overall, I think they've managed fairly miraculously to introduce
namespaces without breaking old code.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 5 days, 17:31.]
Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
Navigation:
[Reply to this message]
|