Yii Framework Forum: Namespaces in Yii 2.0? - Yii Framework Forum

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • This topic is locked

Namespaces in Yii 2.0? Rate Topic: -----

Poll: Namespaces in Yii 2.0? (140 member(s) have cast votes)

will use of namespaces make better Yii?

  1. yes (101 votes [72.14%])

    Percentage of vote: 72.14%

  2. meaby (18 votes [12.86%])

    Percentage of vote: 12.86%

  3. no (11 votes [7.86%])

    Percentage of vote: 7.86%

  4. how will it help? (will learn it) (10 votes [7.14%])

    Percentage of vote: 7.14%

Vote

#1 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 20 December 2010 - 04:51 PM

will Yii 2.0 use Namespaces?

http://www.php.net/m...s.rationale.php
0

#2 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 21 December 2010 - 08:30 AM

that was an obvious question.
0

#3 User is offline   jacmoe 

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

Posted 21 December 2010 - 08:45 AM

It was! :lol:
I can't find it right now, but I am fairly certain that namespaces is one of the major things in Yii 2.
Also the reason why it won't run on anything else than PHP 5.3 +
"Less noise - more signal"
0

#4 User is offline   samdark 

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

Posted 21 December 2010 - 07:25 PM

Namespaces are already supported since 1.1.5.
Yii 1.1 Application Development Cookbook

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

#5 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 22 December 2010 - 08:09 AM

View Postsamdark, on 21 December 2010 - 07:25 PM, said:

Namespaces are already supported since 1.1.5.


The main thing that its not just supported, but uses it.
0

#6 User is offline   jacmoe 

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

Posted 22 December 2010 - 10:33 AM

Since Yii 2.0 will require PHP 5.3 + that's not going to be a problem there.
All the PHP 5.3 goodness is not backwards compatible.
Like reflection, namespaces, ...
Hence the major version.
"Less noise - more signal"
0

#7 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 23 December 2010 - 05:50 AM

View PostUlten, on 22 December 2010 - 08:09 AM, said:

The main thing that its not just supported, but uses it.


What's the big deal here? As long as you don't have classes like "CController" in your other code (which i guess is not very likely, due to the "C" prefix) you won't gain much.
0

#8 User is offline   samdark 

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

Posted 23 December 2010 - 03:36 PM

I don't see any benefit either.
Yii 1.1 Application Development Cookbook

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

#9 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 26 December 2010 - 08:03 AM

View PostMike, on 23 December 2010 - 05:50 AM, said:

What's the big deal here? As long as you don't have classes like "CController" in your other code (which i guess is not very likely, due to the "C" prefix) you won't gain much.



View Postsamdark, on 23 December 2010 - 03:36 PM, said:

I don't see any benefit either.



Are you kidding?
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#10 User is offline   jacmoe 

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

Posted 26 December 2010 - 03:24 PM

Coming from C++, I am a bit surprised.
In the world of C++, a framework which pollutes the global namespace is a bad framework.
I am embracing namespaces in PHP.
And in Yii.
"Less noise - more signal"
0

#11 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 December 2010 - 03:34 PM

The problem is, that namespaces lift the requirements up to PHP 5.3 and thus would lock out a lot of users. To me that's a much bigger issue than being able to have a framework class called "Controller" instead of "CController". I never had any clashes with other classes and i don't know of any other project that also uses the "C" prefix for their classes.

Still i wonder, what else would be the benefit of using namespaces? Better performance? I don't think so. Easier code? Not really much, at least not in the application code.

So in my opinion Yii 2.0 might be too early to introduce namespaces. But i might miss some other big advantage (like maybe class loading - i admit i didn't look closer to that yet).
1

#12 User is offline   Ulten 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 04-October 10

Posted 27 December 2010 - 07:21 PM

View PostMike, on 26 December 2010 - 03:34 PM, said:

The problem is, that namespaces lift the requirements up to PHP 5.3 and thus would lock out a lot of users. To me that's a much bigger issue than being able to have a framework class called "Controller" instead of "CController". I never had any clashes with other classes and i don't know of any other project that also uses the "C" prefix for their classes.

Still i wonder, what else would be the benefit of using namespaces? Better performance? I don't think so. Easier code? Not really much, at least not in the application code.

So in my opinion Yii 2.0 might be too early to introduce namespaces. But i might miss some other big advantage (like maybe class loading - i admit i didn't look closer to that yet).


What about developing or using code that doesn't belong to Yii at all, and at some point it happens so, the next you find out that general programmer use conventional words like controller,view,model,test,index,main,all, in all parts of big program it should mean in context.

second idea is that would have more easily develop flow when you can have 2 namespaces one for debugging/development and other for production,productivity and speed.

generally using namespaces will help create bigger applications and use other code.
0

#13 User is offline   qiang 

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

Posted 27 December 2010 - 07:50 PM

The prefix 'C' can be considered as a namespace for all Yii core classes (just like yii.* if we use namespace).

In general, it is the application code that needs namespace the most, if it wants to be organized well and avoid naming conflicts with its code in different modules or integrated 3rd party code.

Since Yii 2.0 will raise the basic requirements to 5.3+, it is certain that we will use namespace for the core classes. However, namespace is not the main driven force for us to rewrite Yii.
4

#14 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 10 March 2011 - 08:11 AM

View Postjacmoe, on 26 December 2010 - 03:24 PM, said:

Coming from C++, I am a bit surprised.
In the world of C++, a framework which pollutes the global namespace is a bad framework.
I am embracing namespaces in PHP.
And in Yii.


I disagree.

I embrace namespaces in PHP, but I don't see it adding any value to Yii's standard package of framework components.

Yii was already "namespaced" since it's inception - which at the time meant using a convention, a class-name prefix. Yii chose a short class-name prefix "C", but it still reduced the chances of namespace collisions enough to make your concerns pretty much irrelevant - I don't think you've ever actually run into a situation where a Yii class collided with a third-party class?

The namespace feature in PHP is very "bread and butter" in the first-place - it's really not much more than syntactic sugar, and as such, doesn't really solve the problem any better or any worse than convention-based approaches, such as used by the Zend framework, PEAR and others. It doesn't really bring any of the convenience or practical aspects found in other languages like C# or Java.

In my opinion, with existing support for namespaces in third-party libraries, or in your own codebases, Yii's part of the job is done. If you want to use namespaces in your own applications and libraries, you're good to go.

On another note, Yii relies on a number of third-party components, which do not use namespaces.

And finally, for framework components, which naturally get used a lot, I think there's a convenience factor - "CJSON" is just easier to type (and easier on the eyes) than "Yii\web\helpers\JSON". Yuck.

If it ain't broken, don't fix it :-)
4

#15 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 10 March 2011 - 08:14 AM

On a related note, namespaces would be of great value for third-party modules and components, as they would largely eliminate the risk of collision. If a Yii-module was required (or at least strongly encouraged) to use a namespace, I think that would be a sensible convention.
3

#16 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 18 April 2011 - 04:47 AM

As more and more frameworks (Doctrine2, Symfony, Zend) take to rewriting their core and adopt 5.3 namespaces, it only makes sense to adopt namespaces for Yii version 2+. With current support for namespaces in application code, i'm already writing in this way so I don't feel the urgent need for the core framework to be namespaced.

Yii 2+ in my opinion is more about design patterns, ideas and improvements than namespaces alone.

EDIT:
Just to add, I think I would like to see a better coding standard in Yii 2. The source code is difficult to read in parts :-)

This post has been edited by kevinb: 18 April 2011 - 05:11 AM

0

#17 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 18 April 2011 - 07:09 AM

View Postkevinb, on 18 April 2011 - 04:47 AM, said:

EDIT:
Just to add, I think I would like to see a better coding standard in Yii 2. The source code is difficult to read in parts :-)


like where?

I think this is probably the most legible, and easily one of the most well-commented, codebases I've ever seen.
0

#18 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 18 April 2011 - 07:15 AM

Before the old coding standard discussion starts again, please read here:
http://www.yiiframew...coding-standard
0

#19 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 18 April 2011 - 07:17 AM

View Postmindplay, on 18 April 2011 - 07:09 AM, said:

like where?

I think this is probably the most legible, and easily one of the most well-commented, codebases I've ever seen.


Things like implied true|false, non-bracketed statements on single lines, no spaces between operators etc. E.g.

//.. YiiBase:193
if(($n=func_num_args())>1)

//.. YiiBase:190
if(!class_exists($type,false))

//.. YiiBase:395-404
if(strpos($className,'\\')===false)
	include($className.'.php');
else  // class name with namespace in PHP 5.3
{
	$namespace=str_replace('\\','.',ltrim($className,'\\'));
	if(($path=self::getPathOfAlias($namespace))!==false)
		include($path.'.php');
	else
		return false;
}


Things like this (in my opinion) just make it harder to read and understand on first glance. Especially for people new to the Framework who want to understand the workings of the framework.

Yii Developers: I love this framework, so don't take it as a negative criticism, just an observation on a personal preference.
2

#20 User is offline   Ali Borjian 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 369
  • Joined: 19-January 11

Posted 17 May 2011 - 01:04 PM

I am a .NET developer and there r a lot of ideas.
one of them is using namespaces.
I can easily access my references via a simple code.
By the way in Visual Studio it supports namespaces by Intellisense Tools.

I agree to develop namespaces everywhere in Yii

0

Share this topic:


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • This topic is locked

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