Lowercase or CamelCase namespaces?

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.

As comments @cebe these aspects are the decision of the team of developers, who must clearly define the Core Framework Code Style before continuing with the development and thus be able to follow the recommended guideline.

And answering the poll vote for camelCase.

I always felt Yii is a bit retarded related to the lowercase aspect of namespacing, never understood why it went with it in the first place, but hey, we adapt…

This is visible especially when you are using lots of 3rd-party libraries, i.e:

<?php declare(strict_types=1);

namespace extensions\storagemanager\common\models;

use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use yii\helpers\ArrayHelper;

Which looks weird, as opposed to:

<?php declare(strict_types=1);

namespace Extensions\StorageManager\Common\Models;

use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use Yii\Helpers\ArrayHelper;

Which clearly looks much better and compatible with the other libraries definitions.

I’ll vote for changing into camel case, or whatever most of PHP libraries are using now. See php league, laravel, symfony, cake, etc, and follow that, we really don’t have to be different here.

4 Likes

remember that old discussion

nowadays the main argument against lowercase namespace is because of other libriaries using PascalCase

1 Like

I used to understand if smthng is a class by looking for a backslash after its name. IMHO :slight_smile:

Yes, thnx :smiley:
If we can choose between three variants, I’d prefer camelCase. PascalCase is on the second place for me.
There is no any logical reason, just I see camelCase a bit prettier.

1 Like

I see the main argument is unreadability of lowercase namespaces.

There’s no such issue. We prefer single word namespaces but current rule is to write them suchAs\this\.

There is only a single argument for using uppercase first letter SuchAs\This\ — adoption by majority of nowdays packages.

PascalCase looks nice and all, but I’m not a fan of it for namespaces. Using camelCase for the namespace seems more fitting.

If major packages died, should Yii die? LOL!
Ultimately it’s whatever. As long as we can import and clearly read what’s being imported then I don’t care as much.

1 Like

Likely. That would mean PHP funeral :slight_smile:

2 Likes

Well, yes, but my point is that if your friends jump off a bridge you don’t have to jump too. LOL

1 Like

I also prefer lowercase namespaces. I remember when I used Guzzle for the first time. They provide a number of helper functions in the ǹamespace GuzzleHttp\Promise. A typical usage in PHP looks like this:

<?php

use GuzzleHttp\Promise;

// [...] Some code

Promise\unwrap($promises);

// [...] more code

When I first worked with Guzzle, I remember having a hard time to understand how the above code works since I always assumed that Promise is a class as opposed to a namespace. In Yii we wrap helper functions as static methods of a class — so that problem wont arise. But I think thats definitely a reason against PascalCase for namespaces (like @schmunk already wrote)

This is probably best approach - camelCase not CamelCase.