What has this to do with users? Users don’t care about code.
In large companies, a lot of developers work on the same piece of code over the time. In large companies, only few (most likely nobody) know every single line and why it’s there. Developers have to fix code of others, fix code that no one knows about. Old developers depart and take their knowledge with them. New developers come and have to understand what’s going on.
Absolutely the same with open-source projects. In fact, these problems are even more important in open-source projects, because you can’t just walk to a senior developer a few meters away and ask about some piece of code. It’s important as ever to make it easier for people to understand code.
We aren’t talking about yii developers only, but about all developers how write applications using it, extensions for it etc. More likely than not, most developers look at the code to understand details, some of which aren’t covered in the documentation.
Hahaha. Remove “extends Controller” from any of your controllers and see the result. You’ll see a generic error “Unable to resolve the request “controller/action””. It’ll take ages to understand what you’ve forgotten. (Silently returning null in these important cases is a bad design decision.)
I named users — framework users. So end-user applications is applications writing using this framework.
I know what standards of work adopted in large companies. We talking about Yii. Where team is carefully selected. And please note that it’s core developers is not ordinary programmers, so thay can without any problems understand whats going on in createController() methods without splitting it’s code to few unusable methods.
Never had a problem with understanding the code of Qiang. Never. Moreover, for several years of study for a framework I discovered techniques that do not exist anywhere else, as well as an excellent style of writing code that has become my family and I use it to write applications, as well as extensions of the framework.
Once again you bring fantastic situations. And there is another part of philosophy. It does not handle fantastic situations. This FW is not like some paranoid FWs:
$a=5;
if(!is_int($a))
throw new Exception('Holy hell, things going bad <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />');
This is of course joke, but some other FWs do things as shown.
Framework files.
I’m sorry, but I reviewed Symfony 2 far and wide. I’m afraid seem rude. But in addition to <very bad word> i don’t know what to say. Symfony 2 VS Yii is like a street fighter VS proffessional ninja. Sorry for this compare, no one wanted to offend, just my opinion
Not ordinary programmers who can analyse hundred lines per second? I don’t know what to reply to this, really.
Just curious, you’ve never put spaces after “if” and between operators, of have you erm… adopted this excelent style?
So, you’re an extraordinary programmer too, who never makes mistakes like forgetting “extends Controller” when adding a new controller or making a typo in a controller’s class name?
I’m a bad programmer. Because I make mistakes. Every day. Every single day. Numerous, numerous typos! I can’t write a hundred lines without mistakes before executing. I can’t understand a method with five levels deep statements just by looking at it for ten seconds. It becomes hard for me even with four levels of nesting! I don’t remember names of all classes and methods and functions. I have to rely on code completion! And the worst thing is… When I write code, I rely on tests. They check results for me! No. I’m a terrible programmer. Maybe I should’ve chosen a different profession. A gardener or something.
…I’m still waiting for a list of disadvantages of splitting methods anyway.
You overdid things, not the first time. Where there hundred lines??? What are you talking about?
Yes, never put space after control structures and between operators. And no problem. Readability of this style for me, even higher than for example the readability of any other styles(like in Zend, like in Symfony). Because after a while it gets into your blood. This is a figurative expression, but you get idea.
So use GII and stop complaining about life
I say G-I-I
There is no so deeply statements, you overdid things again.
Try to reduce the depth. It’s simple.
Someone said that TDD is a bad thing?
If rely on example of the separation that you have led, then all simple. Unreusable methods. This is enough.
I got your point. Private methods must only be used if called more than one time.
[spoiler]Мой препод в универе таких программистов называл программистами «от сохи». Это когда в голове много практики, но ноль теории. Дельный совет в своей области ты дать можешь, но в команде с тобой я бы не работал под страхом смерти. И дело совсем не в пробелах после if. Писать мозговыносящие конструкции я тоже могу, и получать удовлетворение от того, что я такой избранный, что могу это понять — тоже могу (привет #define в C). Но в хорошей команде так не делают.[/spoiler]
Um, okay. Enough is enough. There’s no point in sarcasm if people can’t tell it away from serious discussion.
You do not agree? (and don’t forget we talking about framework)
[spoiler]Если «от сохи» связано с отказом от определения нереюзабельных приватных методов, то у вас был преподаватель «от сохи». С вами в комманде я также работал бы под страхом смерти и дело совсем не в том, что вы не понимаете что такое рефакторинг. Писать идиотский нереюзабельный (но читаемый код) я тоже могу, но получать от этого удовольствие — нет. Что касается пробелов, то есть конвенции (это про отсутствие пробелов после if, управляющих структур, операторов, но это только 1% общей картины). В хорошей комманде — понимают что такое конвенции.
Что касается мозговыносящих конструкций. Как я понимаю речь о методе createController() (о других мы не говорили). Если вы по преждему считаете его мозговыносящим и требующим разделения, то я бы пересмотрел взгляд о вышеприведенной шутке: «Maybe I should’ve chosen a different profession. A gardener or something.»
Maybe
P.S. Засунуть текст с оскорблениями в спойлер это так по «русски». Не нужно так делать, пиши на международном, чтобы все могли оценить «большой ум».
Guys, let’s calm down a bit since it becomes a holywar instead of a productive discussion. You both made some good points but some points are a bit extreme.
In Yii framework we’re trying to get a well-balanced solution and that’s why we aren’t running to extremes like “make everything public”, implementing everything in a single method or extracting methods too much.
Very long time I thought so too. After 1 january 2009 things changed. For one month from 1 december 2008 i looked Yii and tryed to understand why. When I realized I was enlightened. Qiang is a unique person and unique way of thinking, a brilliant mind. I decided to do experiment: I took my code style, and threw it at the other end of the universe. After a while I felt The Power. It is impossible to explain it beyond syntax. You can just try it and make decision.
Golden words. Rather than resist just try to understand: «Why»
Note to self: How to start a flame war on any open source project:
Question the coding style of the project. No matter how successful the project is, there’s always something you can find, that annoys you. Ignore the amount of spare time work and instead be very specific about bits and pieces and never forget to mention, that the current coding style sucks.
On the other hand if you are a long time member and someone questions the coding style: no matter how right he may be, be as loyal as you can. Defend what you have and don’t miss any oportunity to denounce any criticism.
But no matter which side you take: Be as pathetic and dramatic as you can. It’s not about something - it will affect how you live the rest of your life! If that’s not worth fighting for then what is?
… and of course i personally will hate the extra spaces an brackets …
There is the coding standards, even if it’s not documented.
What does the weakness? I just want to say that current coding standarts is good for me. And i’m sure not only for me. Moreover, I am sure that most of us, beacuse if not this thread would be with at least 100 pages, but we at 4 now Saying «True Power» I just want to say how they cool. You are mistaken, there is no analogy with religion. I just feel sorry for people who are not able to understand the current framework standards.
But that doesn’t mean that Yii shouldn’t have a coding standard.
It should be written down so that it can be adhered to when Yii is moved to Github.
Because the Yii team should concentrate on coding instead of fixing contributers code.
And because it would be better to have a consistent code base instead of a weird mix of all kinds of standards.
A consistent code base is also extremely important for you and me because it makes it easier to read the code, and perhaps modify and even contribute back to the project.
Streamlined code means that we can concentrate on what it does instead of what it looks like.
However, the only people who can decide on that is the Yii team.
So they need to sit down and write a set of guide-lines.
Like Google, Qt, Zend, PEAR, EZ Components, …
If you feel that the code is great as-is, then it should be written down in what way it’s great so that we can have a standard.
Guys, please calm down. I will lock up this thread as it won’t lead to anywhere.
As Alex said, for Yii 2 we will adopt some prevailing code styles. The following is a snippet in the yii2 code base:
public function attachBehavior($name, $behavior)
{
if (!($behavior instanceof Behavior)) {
$behavior = \Yii::createComponent($behavior);
}
$behavior->attach($this);
return $this->_b[$name] = $behavior;
}
So spaces will be inserted to make things less clustered, and we will add brackets for single line of control statement.
Whether you accept it or not, I think code style is mainly a habit. You will get used to it (whether writing or reading the code) after some time. The more important thing is that we should use consistent code style.
Also, we try to make each function not too long. Sometimes this may not be very easy to achieve when considering other factors. However, we are open to suggestions to improve and refactor the code if you point it out.