Do any projects use lowercase or camel case names for namespaces? As far as I can tell it is allowed by PSR-0 and it doesn't look like PSR-1 makes any recommendation on the issue — as far as I can tell it only addresses the class name (studly caps).I ask because I don't think I've run into any code (other than my own) that uses anything other than studly caps for namespaces. I'm wondering if this is a universal thing (and should work on adjusting any new code to follow this unstated agreed upon standard) or if it isn't the only way people do it (and I haven't looked hard enough and that I should feel OK continuing to do namespaces however I like as long as they follow PSR-0).I ask also because it is possible I missed something big in PSR-0 or PSR-1 and it does actually address this. If so, please help me see where it is as I've looked a few times and it has never popped out at me. :)
--
You received this message because you are subscribed to the Google Groups "PHP Standards Working Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/php-standards/-/snhzGk4Q0SAJ.
To post to this group, send email to php-st...@googlegroups.com.
To unsubscribe from this group, send email to php-standard...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/php-standards?hl=en.
> Do any projects use lowercase or camel case names for namespaces?
The Lithium guys use lowercase; Aura used to, but switched to StudlyCaps. There may be others.
> As far as I can tell it is allowed by PSR-0 and it doesn't look like PSR-1 makes any recommendation on the issue — as far as I can tell it only addresses the class name (studly caps).
This is correct. PSR-0 uses both lowercase and StudlyCaps examples, and makes no recommendation either way. PSR-1 defers to PSR-0 on namespaces, but does formalize the class naming conventions. Class names in all the ancestor standards (notably PEAR) were all StudlyCaps, and as such seems to be the supermajority practice.
> I ask because I don't think I've run into any code (other than my own) that uses anything other than studly caps for namespaces. I'm wondering if this is a universal thing (and should work on adjusting any new code to follow this unstated agreed upon standard) or if it isn't the only way people do it (and I haven't looked hard enough and that I should feel OK continuing to do namespaces however I like as long as they follow PSR-0).
StudlyCaps isn't the *only* way people do it, but it does seem to be the way the vast majority are doing it. I used to use lowercase for namespaces, but after seeing that practically the rest of the world was using StudlyCaps, the decision to switch was easy. In a lot of ways, StudlyCaps is an easier transition when moving away from PEAR_Style_ClassNames to Name\Space\ClassNames: replace the _ with \ and you're done.
> I ask also because it is possible I missed something big in PSR-0 or PSR-1 and it does actually address this. If so, please help me see where it is as I've looked a few times and it has never popped out at me. :)
As far as I can tell, you have missed nothing. :)
-- pmj
Chisimba pre v4 used to use lower case, but has since changed. IMO there
is no real big deal, but studly does actually read a little better now
that I am using it across the board.
-- Paul
--Larry Garfield
On 04/12/2012 05:11 PM, Beau Simensen wrote:
> Do any projects use lowercase or camel case names for namespaces? As
> far as I can tell it is allowed by PSR-0 and it doesn't look like
> PSR-1 makes any recommendation on the issue � as far as I can tell it
> only addresses the class name (studly caps).
>
> I ask because I don't think I've run into any code (other than my own)
> that uses anything other than studly caps for namespaces. I'm
> wondering if this is a universal thing (and should work on adjusting
> any new code to follow this unstated agreed upon standard) or if it
> isn't the only way people do it (and I haven't looked hard enough and
> that I should feel OK continuing to do namespaces however I like as
> long as they follow PSR-0).
>
> I ask also because it is possible I missed something big in PSR-0 or
> PSR-1 and it does actually address this. If so, please help me see
> where it is as I've looked a few times and it has never popped out at
> me. :)
--
You received this message because you are subscribed to the Google Groups "PHP Standards Working Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/php-standards/-/cODWxVZNU6kJ.
> Lower-case namespaces are a way to differentiate between namespaces and classes.But, do you need to know?
>
> use Assetic\Util\Process;
> use Assetic\Filter\GoogleClosure;
>
> In this example, Process is a class, GoogleClosure is a namespace. Without prior knowledge, there is no way of knowing.
How do you solve the problem that occurs when Assetic\Util\Process
becomes a namespace, i.e., when classes are added, e.g. a different
implementation is created, commonalities are abstracted, etc.?
Best regards,
Andreas
--
You received this message because you are subscribed to the Google Groups "PHP Standards Working Group" group.
Hi,2012/6/13 Andreas Möller <a...@softe.is>> Lower-case namespaces are a way to differentiate between namespaces and classes.But, do you need to know?
>
> use Assetic\Util\Process;
> use Assetic\Filter\GoogleClosure;
>
> In this example, Process is a class, GoogleClosure is a namespace. Without prior knowledge, there is no way of knowing.
But is there a reason, why one should _not_ know? I can't find a valid reason, why there is no distinction between classes and namespaces and this distincintion would make the difference obvious at all. At least: Why should FIG _prohibit_ anyone from taking the opportunity to _make_ a distinction? In my oppinion it should encourage to take this opportunity (not "enforce", because looking at all the existing frameworks/libraries this would be a really ugly mess :D)
How do you solve the problem that occurs when Assetic\Util\Process
becomes a namespace, i.e., when classes are added, e.g. a different
implementation is created, commonalities are abstracted, etc.?What problem? 'Assetic\Util\Process' (lets name it 'assetic\util\Process' for this short paragraph) itself couldn't become a namespace, because the correspondin namespace would be 'access\util\process'. Because this namspace didn't exists before it cannot collide with existing code. The class 'assetic\util\Process' remains as it is, so it doesn't break anything too. Everything works fine, so where is a problem?
use assetic\util\Process;use assetic\util\process;$some_var = process\some_func(new Process());
On Wed, Jun 13, 2012 at 7:53 AM, Sebastian Krebs <kreb...@googlemail.com> wrote:Hi,2012/6/13 Andreas Möller <a...@softe.is>> Lower-case namespaces are a way to differentiate between namespaces and classes.But, do you need to know?
>
> use Assetic\Util\Process;
> use Assetic\Filter\GoogleClosure;
>
> In this example, Process is a class, GoogleClosure is a namespace. Without prior knowledge, there is no way of knowing.
But is there a reason, why one should _not_ know? I can't find a valid reason, why there is no distinction between classes and namespaces and this distincintion would make the difference obvious at all. At least: Why should FIG _prohibit_ anyone from taking the opportunity to _make_ a distinction? In my oppinion it should encourage to take this opportunity (not "enforce", because looking at all the existing frameworks/libraries this would be a really ugly mess :D)It is not true that you don't know. You can still determine just as easily programmatically if the class exists, and you should know whether it exists when you are using it in the first place. The distinction in capitalization does nothing in this regard.
How do you solve the problem that occurs when Assetic\Util\Process
becomes a namespace, i.e., when classes are added, e.g. a different
implementation is created, commonalities are abstracted, etc.?What problem? 'Assetic\Util\Process' (lets name it 'assetic\util\Process' for this short paragraph) itself couldn't become a namespace, because the correspondin namespace would be 'access\util\process'. Because this namspace didn't exists before it cannot collide with existing code. The class 'assetic\util\Process' remains as it is, so it doesn't break anything too. Everything works fine, so where is a problem?In this case you are required to execute two use statements, e.g.use assetic\util\Process;use assetic\util\process;$some_var = process\some_func(new Process());
As namespace names and class names don't occupy the same... namespace, they can overlap without any problem and so I can't see the meaning behind making the distinction between namespaces and classes.
Sebastian,
One point that I think is worth considering is that to the runtime,
there is no such thing as a namespace. It's a compiler aided string
replace. That's it. There's no namespace construct in the code.
There's no logic based on namespace name at runtime. The classes name
literally becomes "\Foo\Bar\ClassName".
Based on that, shouldn't it follow the same rules for class names,
seeing as that's how it's going to resolve anyway?
And who cares if there is a collision between a class name and a
namespace?
It would allow me to do:
\Foo\Bar\Cache - The interface to resolve
\Foo\Bar\Cache\Apc - A class implementing the interface
And who cares if there is a collision between a class name and a
namespace? It would allow me to do:
\Foo\Bar\Cache - The interface to resolve
\Foo\Bar\Cache\Apc - A class implementing the interface
And who cares if there is a collision between a class name and a
namespace? It would allow me to do:
\Foo\Bar\Cache - The interface to resolve
\Foo\Bar\Cache\Apc - A class implementing the interfaceActually the better way is this\Foo\Bar\Cache\CacheInterface - The interface to resolve\Foo\Bar\Cache\Apc - A class implementing the interface
Or even better:\Foo\Bar\Cache\ApcCache - A class implementing the interface
Good examples are with controllers.Basically the idea is to prefix the class name with Abstract if it's abstract, and suffix with Interface if a interface and in other circumstances where there may be lots of common class names, to write what it is since in the code with namespaces, we are only using the class name. It's much more readable to have $controller = new AdminController() than $controller = new Admin(). Generally, suffixing classes with what they are helps a lot with readability.