Re: [PHP-DEV] Simple Namespace Proposal
by Guilherme Blanco other posts by this author
Jul 23 2007 9:22AM messages near this date
Re: [PHP-DEV] Simple Namespace Proposal
|
Re: [PHP-DEV] Simple Namespace Proposal
> >
> > 2) In short and clear, why are braces not being used ? C++,
> > C# uses it. (Short answer and if the answer is "Developer
> > didn't want to do it..." just say "Usual"
>
> We are not C++. Python doesn't use braces.
> The only neediness for braces is placing several namespaces into one file,
> but one of the goal of our concept is avoiding this.
Your answered like "We are not like C#, but we are like Python.". I'm
not the one that will point that Python always try to be a unique
language or will criticize you.
I've read dozen of PHP books, and what I suggested earlier is only
based on what I've read.
The topic is always entitled as "block scope".
Since namespace is a block scope too, so it's a commom sense. It's
easier to read, easier to understand, etc.
Your short answer is "no, because it's not needed, since there'll be
only one namespace per file."
It doesn't matter is one, two or hundreds namespaces are defined in a
single file, but the KIS idea must remain. Stanislav mentioned that
file names, directories, etc do not require braces.
Ok, but we are not talking about File System, we are talking about
language structure and standards. PHP uses braces to define new scope,
like block scope, loops, if-else, switch, function, classes, etc.
But namespaces are different!
Why different? It's another language functionality, as all others I mentioned.
So, let's change the PHP to allow only one class per file, and remove
the braces' need too. Classes are different too.
Or maybe better... only one namespace per file and only in one file.
Namespaces are different, as you said!
If PHP supports more than one namespace per file, why not provide it
to developers? It's a functionality, not a bug. Do not restrict
functionalities because you do not like them.
I'm repeating... it's up to the PHP developer decide if he wants this
or that way to code. Currently he's able to define more than one class
in a single file. Ok, I don't do it, and will do one namespace per
file (and continue one class per file), but I don't think that this
restriction is really necessary.
That's my final point, and my last try to talk about braces. Seems you
do not like external ideas.
> > I'll give you an example... PHP Doctrine package has a lot of files,
> > hundreds... there is a way to compile it in a single file, to save
> > some memory usage for including these files. Including a single file
>
> Putting all code together in the same file rarely saves any significant
> amount of memory and leads to a very messy code. Of course, it's your
> application and your decision, but I don't see any reason to promote
> such style on the language level. Anyway, if you can do with everything
> in single file, I think having single namespace won't hurt.
It saves the time needed to include all the files and also the memory
that it saves for calling require_once, include_once, etc.
Forget this, it was only one illustration that such optimizations
(what Doctrine call as compile into a single file) does. You keep all
the hundred files but you have one "compiled" with all the code.
> > 2 - Overwrite will be implemented?
> > Something like: overwrite function strlen( ... ) { ... }
>
> What it's supposed to do?
I think it's overload. Someone mentioned earlier and I was curious if
you implemented this or not.
> > <?php
> > class Bar { ... }
> >
> > <?php
> > namespace Foo {
> > class Bar { ... }
> > }
> >
> > <?php
> > import Foo;
>
> For 100th time, import Foo is a no-op. I'm thinking about prohibiting it
> at all... If you do import Foo::bar you'll get an error if Bar is
> already defined.
I was supposed to suggest triggering a E_NOTICE that Bar is already
defined and instantiate the Bar class of "global". But if you want
something more radical... =)
> > 4 - Will namespaces support anything else than functions and classes
> > (like constants, for example)?
>
> Not likely, since there's no such thing as free-form constant. Though,
> in fact, we might add one (i.e. const X = 'foo' which is define('X',
> 'foo')) ... But, if you need a constant, why not put it into a class?
Bad example I did. I was supposed to ask for namespace level
variables. Not in global scope, not in class scope. =)
I have another questions regarding namespace support... well, about
function support.
1- How will is_a, instanceof, will behave in this situation?
$a = new NS1::SubNS1::MyClass();
echo is_a( $a, "MyClass" ); ????? true/false?
echo is_a( $a, "NS1::SubNS1::MyClass" ); ???
2- Will exist some namespace specific functions? Examples:
$a = namespace_contains( "SomeClass" );
$b = namespace_exists( "NS1" );
$c = is_a_namespace_class ( $NS1ObjString );
// ......
Best regards,
--
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: guilhermeblanco@[...].com
URL: http://blog.bisna.com
São Carlos - SP/Brazil
Thread:
Dmitry Stogov
Derick Rethans
Dmitry Stogov
Dmitry Stogov
dz
David Coallier
Guilherme Blanco
Stanislav Malyshev
Dmitry Stogov
Markus Fischer
Stanislav Malyshev
Stanislav Malyshev
Stanislav Malyshev
Giedrius D
Stanislav Malyshev
Giedrius D
Stanislav Malyshev
Giedrius D
Andrew Minerd
Stanislav Malyshev
David Coallier
Chris#
Dmitry Stogov
nicobn
Chris#
Chrish
Dmitry Stogov
Andrei Zmievski
Stefan Priebsch
Stanislav Malyshev
Richard Lynch
Dmitry Stogov
Stanislav Malyshev
Andrei Zmievski
Stefan Priebsch
Stanislav Malyshev
Stefan Priebsch
Richard Lynch
Stefan Priebsch
Jani Taskinen
David Coallier
Robert Cummings
Richard Lynch
Stanislav Malyshev
Lukas Kahwe Smith
Derick Rethans
Stefan Priebsch
Stanislav Malyshev
Derick Rethans
Stanislav Malyshev
Stanislav Malyshev
Stanislav Malyshev
Dmitry Stogov
Stefan Priebsch
Dmitry Stogov
Jeremy Privett
Stanislav Malyshev
nicobn
Tony Bibbs
Stanislav Malyshev
Stefan Priebsch
David Coallier
Rich Buggy
Stanislav Malyshev
Stefan Priebsch
David Coallier
Dmitry Stogov
Andrei Zmievski
Hans Lellelid
dz
Guilherme Blanco
Alexey Zakhlestin
Stanislav Malyshev
Jeremy Privett
Dmitry Stogov
Arpad Ray
Dmitry Stogov
Stanislav Malyshev
Markus Fischer
David Coallier
Stanislav Malyshev
Brian Moon
Dmitry Stogov
Stanislav Malyshev
Brian Moon
Stanislav Malyshev
Dmitry Stogov
Stefan Walk
Dmitry Stogov
David Coallier
Dmitry Stogov
Stefan Priebsch
Stanislav Malyshev
Stefan Priebsch
Larry Garfield
Dmitry Stogov
Larry Garfield
Dmitry Stogov
Derick Rethans
Dmitry Stogov
nicobn
Sebastian Bergmann
Dmitry Stogov
nicobn
Rasmus Lerdorf
Lucas Nealan
Stefan Priebsch
Rasmus Lerdorf
Stefan Priebsch
Sebastian Bergmann
Stefan Priebsch
Dmitry Stogov
Sebastian Bergmann
Stanislav Malyshev
davidc
Stanislav Malyshev
|