Lowercase or CamelCase namespaces?

Till what time this poll will remain open? I mean to say when can we see the finally accepted way for namespace

Decision is not going to be made by the poll result, poll should only give an idea of overall preference. Decision should be made based on arguments given.

6 Likes

I think most of packagist packages use CamelCase namespaces, not lowercase.

1 Like

I personally prefer lowercase (or snake_case) everywhere it is possible for its better readabilty and ease of typing

As said before, lowercase directory names and namespaces make it much easier to distinguish what’s a namespace and what’s a Class.

8 Likes

CamelCase for consistency with other popular packages & frameworks, and because snake_case for multiple words is ugly.

1 Like

this may not be as important, but php docs also uses camel case in its examples, so it may be a bit confusing for new yii adopters, also concerning multiple word I am in favor of camel case

I’d like to keep lowercase for namespaces. For ease to use and PSR conformity.
That the PHP website uses CamelCase is their problem :slight_smile: They probably did it before lowercase became the thing, and then keep doing it because they didn’t think to change it.

If Yii goes with CamelCase, then we’ll see naming conflicts, making it both more cumbersome to type and to use.

3 Likes

I’d prefer CamelCase because

  • most of packagist.org packages use it
  • it’s MuchMoreReadable than somecoolnamespace
2 Likes

The alternative is someCoolNamespace - it should not be less readable than CamelCase since (probably) most of names in your code already follows this convention.

Both lowercase and CamelCase are PSR-compatible. Also I think that CamelCase is used more than lowercase nowadays.

1 Like

Well, muchmorereadable would be the namespace for MuchMoreReadable. Isn’t that great? :smile:
That way we can tell what’s what at a glance.

But, I don’t feel too strongly about it.
Lowercase for namespaces just matches my policy of always keeping the folders/directories all lowercase for maximum ease of use / cross platform goodness.

1 Like

First of all I propose to refresh definitions:

So it is necessary to distinguish:

  • camelCase
  • PascalCase

IMHO it is not reasonable to make such a huge change just because of other packages preferred more capital letters.

I vote for taking best of two worlds - camelCase which allows to keep most of the namespaces untouched while fixing readability of multiword names e.g. activeRecord.

9 Likes

This is already current convention for Yii 2: https://github.com/yiisoft/yii2/blob/master/docs/internals/core-code-style.md

  • prefer single word namespaces
  • if single word isn’t suitable, use camelCase
5 Likes

Wouldn’t that technically be dromedaryCase and CamelCase ? :blush:

2 Likes

I would prefer CamelCase! Because i found my self searching for weird namespaces alias names in order to prevent using two words.

I’m sold with this approach.

3 Likes

Sounds reasonable to me, too.

camelCase is more natural for classMethodNames and classPropertyNames. For class names and their namespeces I would use PascalCase.

2 Likes

Personally I prefer lower case or the camelCase (not PascalCase). But there is an ugly but important point I want to raise is the ease of adopting for new comers. Laravel took a lot of the focuses these years and they used PascalCase. If Yii use PascalCase and when people are sick of Laravel or they simply just want to explore what’s available then Yii will have the edge over those not using because these people will find Yii more familiar.

I know people don’t switch over just because of namespace naming convention and I quite hate to say one framework has to live under the shadow of another framework but small things like this will build up to it’s ‘friendliness’ to the users.

In the end it is namespace we are talking about. It should be relatively easy just to refactor the namespace path during an upgrade and people are expecting changes from Yii 2 to Yii 3 anyway.