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

#1 User is offline   Müller 

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

Posted 22 March 2013 - 04:51 AM

I found this gist of samdark showing a base class of Yii2, and I notice the namespace names are in lower case, I hope this was abandoned. In IMHO namespace names should use the same convention as class names (StudlyCaps), i.e. SomeNamepace\SomeClass, like Symfony2 and other modern frameworks are using.

https://gist.github....samdark/2835928

Cheers.
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 March 2013 - 07:34 AM

Should it, why? :)
"Less noise - more signal"
0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 March 2013 - 07:43 AM

PHP encourages two naming conventions for namespaces, Camelcase and PASCAL case.
And since the names are single word, they should be all lowercase, like yii and base.

If the names were multi-names, then of course each word (after the first word) should be capitalized, like webComponent.

C++ encourages all lowercase names for namespaces (since it's not a type!).

I think the same goes for Python.

PEAR encourages pascal or camel cased namespaces. And Samdark (or in camel-case: samDark) uses the latter. ;)
"Less noise - more signal"
0

#4 User is offline   Müller 

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

Posted 22 March 2013 - 07:53 AM

View Postjacmoe, on 22 March 2013 - 07:34 AM, said:

Should it, why? :)


Because I think is prettier? <_<

and it would follow the PSR-1 standard.
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md#3-namespace-and-class-names


I may not agree with all proposed standarts in PSR-*, but it sure makes easier to maintain a source code well formatted and to contribute with Yii2, since even PHPStorm (which has been told is used by many Yii core developers), has a option to auto-format using these standards.
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 March 2013 - 07:55 AM

Because a namespace is not a type?

Camelcase is perfectly valid - and encouraged - by the PHP community.

What the heck is PSR-1 ?
"Less noise - more signal"
0

#6 User is offline   Müller 

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

Posted 22 March 2013 - 08:24 AM

View Postjacmoe, on 22 March 2013 - 07:55 AM, said:

Because a namespace is not a type?

Camelcase is perfectly valid - and encouraged - by the PHP community.

What the heck is PSR-1 ?


https://github.com/p...g/fig-standards
1

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 March 2013 - 08:33 AM

That guide doesn't actually dictate how namespaces are named, just that 'Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case'. :)
It does dictate how class names and class constants should be named. Namespaces should just follow psr-0.
"Less noise - more signal"
0

#8 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 22 March 2013 - 08:34 AM

Thanks for the link, btw. :)
Looks like a great guide.
"Less noise - more signal"
0

#9 User is offline   samdark 

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

Posted 22 March 2013 - 02:51 PM

PSR-0 is a good one. PSR-1 and PSR-2 are good as well but only as a base for your own standard since these are very subjective.
Yii 1.1 Application Development Cookbook

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

#10 User is offline   Suralc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 10-January 12
  • Location:Germany

Posted 22 March 2013 - 08:10 PM

While we are looking at standards:

I assume Yii will have a built in logging functionality. Will it follow PSR-3 or wil it have its own interface?

https://github.com/p...er-interface.md

If yii follows psr-3 and uses composer I hope that we will get the "real" interface aviable:
https://github.com/php-fig/log
0

#11 User is offline   samdark 

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

Posted 24 March 2013 - 07:40 AM

Its own.
Yii 1.1 Application Development Cookbook

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

#12 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 24 March 2013 - 08:20 AM

Any reason for this? Anything you plan to implement that couldn't be done following the PSR? Or is there anything you don't like about it?

To me, it looks very similar to the current CLogger (looking only at the interface).
  • the log level specific helpers are missing in CLogger
  • they define other log levels
  • the context array is missing in CLogger, but shouldn't be hard to implement. The interpolation it provides seems handy, I often find myself writing log messages like "Something happened, reason was: '{$reason}'."
  • the category is missing in the PSR. Not sure how this can be solved, maybe by using several logger instances (one per category).

Don't like ads in my sig...
0

#13 User is offline   samdark 

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

Posted 24 March 2013 - 09:22 AM

The category is the main showstopper here.
Yii 1.1 Application Development Cookbook

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

#14 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 25 March 2013 - 08:16 AM

Did you already decide how to access the logger functionality? Will it remain a static helper, or will there be instances? A quick search yesterday showed, that both log4php and monolog support a concept similar to categories (not sure if they can be nested though) and support or plan to support PSR-3.

Even if you don't plan to use PSR-3 interfaces directly, it might be worth using an abstract logger class or an interface, so one can easily implement an adapter to a PSR-3 compatible logging framework.
Don't like ads in my sig...
1

#15 User is offline   qiang 

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

Posted 25 March 2013 - 10:08 AM

The design of the logger is already finalized and implemented. We will not follow PSR-3.
Our logger is not a static helper (similar as in Yii 1.1). It just happens that the logger interface is exposed via Yii like static methods.
0

#16 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 25 March 2013 - 10:57 AM

Sure, sorry for that inaccuracy. ;)

In fact, I very much like the way yii allows us to configure log routes, filters and stuff. Not sure if I would switch to another logging framework even if I could. Also, it's hard to argue without knowing what you're coding.

And after reviewing how the logging currently works, I think it would be even possible to inject a 3rdParty logging framework in Yii 1.1. It's basically the LogRouter that needed to be exchanged with an adapter.
Don't like ads in my sig...
0

#17 User is offline   qiang 

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

Posted 25 March 2013 - 11:26 AM

Thank you for understanding. If you have specific improvement suggestions, please let us know.
0

#18 User is offline   schmunk 

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

Posted 03 April 2013 - 12:50 PM

Hi Qiang and Alex,

I've read through this thread and found that the OP's question is not really answered.

As PSR-0 does not dictate to use uppercase first letters for namespaces, but virtually every PHP project with namespaces - I've looked so far - uses UpperCase\FirstLetters, I really would like to know if \Yii ;) will adopt this format also?

I would also suggest it, because it's like an unwritten convention now.


Best regards,
\Schmunk
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
0

#19 User is offline   qiang 

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

Posted 03 April 2013 - 02:05 PM

I'm actually debating about both choices. If we choose to use CamelCase, how should we name the Yii static class? We would like it to be \Yii, which would confuse users with the \Yii namespace.
0

#20 User is offline   schmunk 

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

Posted 03 April 2013 - 02:54 PM

If I get it right like, you'd have something like:

echo \Yii:t()
$obj = new \Yii\Base\Object();


Why would it confuse users? I would say the syntax prevents misuse.
I'd actually like it ;)

How do others deal with it?

I mean the options aren't that much, it would have to be either \YII or \yii if not the above.
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
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