Namespaces in Yii 2.0?
#3
Posted 21 December 2010 - 08:45 AM
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 +
#6
Posted 22 December 2010 - 10:33 AM
All the PHP 5.3 goodness is not backwards compatible.
Like reflection, namespaces, ...
Hence the major version.
#9
Posted 26 December 2010 - 08:03 AM
Mike, on 23 December 2010 - 05:50 AM, said:
samdark, on 23 December 2010 - 03:36 PM, said:
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.
#10
Posted 26 December 2010 - 03:24 PM
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.
#11
Posted 26 December 2010 - 03:34 PM
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).
#12
Posted 27 December 2010 - 07:21 PM
Mike, on 26 December 2010 - 03:34 PM, said:
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.
#13
Posted 27 December 2010 - 07:50 PM
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.
#14
Posted 10 March 2011 - 08:11 AM
jacmoe, on 26 December 2010 - 03:24 PM, said:
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 :-)
#15
Posted 10 March 2011 - 08:14 AM
#16
Posted 18 April 2011 - 04:47 AM
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
#17
Posted 18 April 2011 - 07:09 AM
#18
Posted 18 April 2011 - 07:15 AM
http://www.yiiframew...coding-standard
#19
Posted 18 April 2011 - 07:17 AM
mindplay, on 18 April 2011 - 07:09 AM, said:
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.
#20
Posted 17 May 2011 - 01:04 PM
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

Help

This topic is locked














