Yii Framework Forum: Naming Conventions And A Few Other Thoughts - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Naming Conventions And A Few Other Thoughts

#1 User is online   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 23-October 10
  • Location:Romania

Posted 28 March 2014 - 10:23 AM

I know i am late to this party and yii2 is where it is right now, but there's some things that i can't just help to say something about.

I am looking at namespacing and i see things like:
namespace app\controllers\Controller;

or 

new app\models\MySuperModel();

or

return \yii\helpers\Json::encode($items);


Why are you using lowercase namespaces while the class itself is camel case?
Wouldn't the below look better:
namespace App\Controllers\Controller;

or 

new App\Models\MySuperModel();

or

return \Yii\Helpers\Json::encode($items);


All the other big frameworks use a consistent convention, but this one in yii2 is very weird, what is the rationale behind it? Is there a chance to be consistnt with this?

Also, i haven't moved to yii2 because 1.1.x suffice my needs now and also i have multiple projects already in that version, but yesterday i took a look at the github code, and what struck me as a bit odd was the usage of array_key_exists() function. It is used in so many places when a simple isset($array[$key]) would suffice.
Why is that? Is like you are trying to make the framework eat more memory.

Please note that i am just trying to understand things, i don't want to make anybody feel bad, it's just i don't understand and if i am going to switch to yii2 i need to know what's under my code and why.

Thanks.
0

#2 User is offline   CeBe 

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

Posted 28 March 2014 - 10:46 AM

View Posttwisted1919, on 28 March 2014 - 10:23 AM, said:

Why are you using lowercase namespaces while the class itself is camel case?


We had that discussion before and came to the conclusion that lower case for namespaces is just like we use lower case for directories. You see what part is the namespace and what part is the class. Did not find the forum topic about it, you may search yourself.

Quote

Also, i haven't moved to yii2 because 1.1.x suffice my needs now and also i have multiple projects already in that version, but yesterday i took a look at the github code, and what struck me as a bit odd was the usage of array_key_exists() function. It is used in so many places when a simple isset($array[$key]) would suffice.
Why is that? Is like you are trying to make the framework eat more memory.


can you give an example? We normally use array_key_exists, when the array item may be null because isset would fail in this case.
0

#3 User is online   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 23-October 10
  • Location:Romania

Posted 28 March 2014 - 11:22 AM

Hi CeBE, thanks a lot for your reply.

For #1, okay i see the point but is that decision final?
Why not rename the dirs to start uppercased, zend does it, symfony does it too, so i don't think is wrong at all, and this would be even better when we will mix Yii with zend or symfony components, it just makes sense to be so.

For #2: https://github.com/y...i/Container.php at
line 143 you do a "if (isset($this->_singletons[$class])) {"
and at
line 173 you do a "if (array_key_exists($class, $this->_singletons)) {"
I mean in this case, how could the class param be null, doesn't really make sense to be so, albeit the first isset call.

This is just an example i found in a few seconds, i am sure that more search would reveal more of this kind of usage.
0

#4 User is offline   CeBe 

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

Posted 28 March 2014 - 11:34 AM

For #1: No, we will not change it. There is no reason to try being equal to others. We already adopted PSR standards, thats enough imo. If we would take everything from other frameworks, why do you need Yii then?

For #2: Check https://github.com/y...tainer.php#L268 there is a good reason for using array_key_exists in this case.
0

#5 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 629
  • Joined: 29-August 12

Posted 28 March 2014 - 11:47 AM

View Posttwisted1919, on 28 March 2014 - 11:22 AM, said:

For #2: https://github.com/y...i/Container.php at
line 143 you do a "if (isset($this->_singletons[$class])) {"
and at
line 173 you do a "if (array_key_exists($class, $this->_singletons)) {"
I mean in this case, how could the class param be null, doesn't really make sense to be so, albeit the first isset call.

If you want to check both (depends on the need): 1) if not set and 2) null/empty , this is shorter:
if (!empty($this->_singletons[$class])) {
}

0

#6 User is online   twisted1919 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 23-October 10
  • Location:Romania

Posted 28 March 2014 - 11:48 AM

#1 - Okay, i just wanted to know. It's not about taking everything from the other frameworks, it's just some code doesn't look standardized, like the below:
namespace yii\di;

use Yii;
use yii\base\InvalidConfigException;


#2 - Yes it makes sense, thanks :)

Anyway, if naming convention isn't going to change i assume we must live with it.

Thanks for your time.
0

Share this topic:


Page 1 of 1
  • 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