Yii Framework Forum: Namespaces Naming Convention - Yii Framework Forum

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Namespaces Naming Convention

#41 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 574
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 05 April 2013 - 05:27 PM

Just thinking loud ...

use \yii\base as \Yii\Base;
use \yii\web as \Yii\Web;
...

How much Performance would that cost and would it affect auto-loading?
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
1

#42 User is offline   Müller 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 23-June 12
  • Location:Netherlands

Posted 05 April 2013 - 06:53 PM

@Cebe

My example was a lazy one, without much thinking. I came up with this one later:
Attached File  php-app-structure-proposal.png (557.29K)
Number of downloads: 28

I posted the link in this topic before. Here it comes again:

https://github.com/a...ucture-proposal

The convention for directories is the singular form.
For directories containing non classes files the convention is all lower-case separating words with a dash.
For namespaces directories containing classes files the convention is StudlyCaps.

The examples I see here are with namespaces with just one word which doesn't look awful. IMO, it doesn't look good when you start to have mixing cases.

$demo = new \MyApp\TestDrive\SuperDemo();


$demo = new \myApp\testDrive\SuperDemo();


I don't see how camelCase can avoid problems when deploying in file systems that are case sensitive. I saw people doing this kind of mistakes with whatever convention we may think of. Unless we introduce a new convention where everything is lowercase and write a super new awesome autoloader from the ground.

And we should also avoid arguments making use of the excuse of less tying. I think we all agree that any code is clearer when written the closest to a human readable language even though we are writing for a machine interpretation.

Tá combinado? ;)

P.S. It is hard to debate in your non-native language :huh:
1

#43 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 07 April 2013 - 03:24 AM

Two different styles seem inconsistent.

What is the advantage? I don't see it.. Don't you also know if a file contains PHP classes by the directory structure?
0

#44 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 574
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 09 April 2013 - 05:38 AM

Guys, count me in on the pro-lowercase side.

I just stumbled upon this code:
namespace Codeception\Module;
class WebHelper extends \Codeception\Module

And as @Qiang mentioned, it is really confusing. ::)
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
3

#45 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 April 2013 - 06:54 AM

Good that you are convinced by yourself. :)
2

#46 User is offline   qiansen1386 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 03-May 13

Posted 22 October 2014 - 09:57 AM

@Alexander
But, I think they must put it as "MUST BE" for a reason, if it is not necessary, then it should be put as "SHOULD" not "MUST". I wonder why they do so. Since we are also a member of FIG, maybe we could propose to change this rule, if the rule does not make sence.

But I somehow feels like that we should follow the law, when the congress has not modify it.

Sorry to bring this ancient topic up, just because that a few developers keep pointing this out.
0

#47 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,865
  • Joined: 17-January 09
  • Location:Russia

Posted 22 October 2014 - 10:05 AM

Which MUST BE you're referring to? PSR-1 says namespaces should follow PSR-0 which says: "Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.".
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#48 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 538
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 23 October 2014 - 07:36 PM

Quote

Sorry to bring this ancient topic up, just because that a few developers keep pointing this out.

When pointing this out, please point to and quote what you are referring to, otherwise a discussion is impossible.

There is NO PSR telling to use camel case.
0

#49 User is offline   qiansen1386 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 03-May 13

Posted 23 October 2014 - 11:05 PM

The last time I saw this discussion here: 7 Reasons to Choose the Yii 2 Framework started by Peter Petermann

Yes, I know there are no PSR says anything about using camel case in namespaces, it is referring to Class Name.

However, He said that:

Quote

namespaces are part of a full qualified classname, that implicitly includes namespaces.


That's why I think it maybe a misunderstanding? But on the other hand, the PSR-1 also do not clarify this well.

LOL, according to https://github.com/p...r.md#3-examples
The author does prefer to using camel case in namespaces, and does lead to an inconsistent folder structure. Don't you think it is a bit wired? ;)
0

#50 User is offline   Alkis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-December 14

Posted 05 December 2014 - 10:33 AM

schmunk, your point I think is quiet correct.

Except for that, Consider also the following scenario:

use Name1\Name11\Name111;
use Name2\Name21\Name211;

Where in the first line we are importing a Class name (Name111), while on the second, a namespace (Name211).

It is obvious that by reading these two lines, you cannot figure out where's the class and where's the namespace. And imagine the case of more "use" statements. This is a completely wrong approach in my opinion, which also makes even coding a bit harder. Not to mention that having two different types so close they must be named in a different way.

I see a lot of frameworks following the PascalCase practice for namespaces, but I still haven't found any real reason for doing this ("Because they do it" of course is not a reason). I would not have problem following them, but as I see there are REAL reasons for NOT doing it.

For easier coding and reading, lowercase in namespaces is the right way for me also.
0

Share this topic:


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users