Yii Framework Forum: Coding Standard - Yii Framework Forum

Jump to content

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

Coding Standard Rate Topic: ***** 5 Votes

#61 User is offline   Athari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-October 11
  • Location:Kazan, Russia

Posted 26 October 2011 - 09:05 AM

Quote

In end-user applications, yes. This is framework, feel the difference.

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.

Quote

Sorry, but this is unreal situation. Absolutely imaginary.

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.)

Quote

Open fw files. There is no splitting like Athari show

What are “fw files”?

Let's look at our competitors. :)

https://github.com/s.../HttpKernel.php — pretty much only private functions, with comments
https://github.com/s...lerResolver.php — that's how they're getting controllers
etc.
“Today is the first day of the rest of your life”Personal website: Snow Lands
0

#62 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 26 October 2011 - 05:11 PM

Quote

What has this to do with users? Users don't care about code.

I named users — framework users. So end-user applications is applications writing using this framework.

Quote

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.

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.

Quote

It's important as ever to make it easier for people to understand code.

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.

Quote

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.)

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 :)');

This is of course joke, but some other FWs do things as shown.

Quote

What are “fw files”?

Framework files.

Quote

Let's look at our competitors.

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 :)
No good, no bad, only consequence.
0

#63 User is offline   Athari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-October 11
  • Location:Kazan, Russia

Posted 26 October 2011 - 07:16 PM

Quote

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.

Not ordinary programmers who can analyse hundred lines per second? I don't know what to reply to this, really.

Quote

as well as an excellent style of writing code that has become my family

Just curious, you've never put spaces after “if” and between operators, of have you erm... adopted this excelent style?

Quote

Once again you bring fantastic situations.

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.
“Today is the first day of the rest of your life”Personal website: Snow Lands
0

#64 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 26 October 2011 - 10:18 PM

Quote

Not ordinary programmers who can analyse hundred lines per second?

You overdid things, not the first time. Where there hundred lines??? What are you talking about?

Quote

Just curious, you've never put spaces after “if” and between operators, of have you erm... adopted this excelent style?

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.

Quote

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.

So use GII and stop complaining about life :)

Quote

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 say G-I-I :)

Quote

I can't understand a method with five levels deep statements just by looking at it for ten seconds.

There is no so deeply statements, you overdid things again.

Quote

It becomes hard for me even with four levels of nesting!

Try to reduce the depth. It's simple.

Quote

When I write code, I rely on tests. They check results for me!

Someone said that TDD is a bad thing? :)

Quote

I'm still waiting for a list of disadvantages of splitting methods anyway.

If rely on example of the separation that you have led, then all simple. Unreusable methods. This is enough.
No good, no bad, only consequence.
0

#65 User is offline   Athari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-October 11
  • Location:Kazan, Russia

Posted 27 October 2011 - 01:47 AM

Quote

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

Um, okay. Enough is enough. There's no point in sarcasm if people can't tell it away from serious discussion.
“Today is the first day of the rest of your life”Personal website: Snow Lands
1

#66 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 27 October 2011 - 06:56 AM

Quote

Private methods must only be used if called more than one time.

You do not agree? (and don't forget we talking about framework)

Spoiler

No good, no bad, only consequence.
0

#67 User is offline   samdark 

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

Posted 27 October 2011 - 09:18 AM

Athari, creocoder
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.
Yii 1.1 Application Development Cookbook

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

#68 User is offline   Luciano 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 20-September 09
  • Location:Buenos Aires, Argentina

Posted 27 October 2011 - 10:24 AM

Ok, going back to the topic, I really think putting spaces between operators and after commas would be great.
Is the way brain use to separate things when one reads something...is not that logical?

I would love to see braces in statements even when you have only one line.
Do yo guys have to save lines with this but then put al braces in a single line?? It lacks of consistency, sorry.

Anyway, I think this discussion is going anywhere because it can't seems like Qiang is going to change his mind about all we could argue about.
Is his framework, is his coding style, is his decision.
That sucks...
Company web site: pressEnter

Free as in "beer"...
0

#69 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 27 October 2011 - 11:15 AM

Quote

Is the way brain use to separate things when one reads something...is not that logical?

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.

Quote

Is his framework, is his coding style, is his decision.

Golden words. Rather than resist just try to understand: «Why»
No good, no bad, only consequence.
0

#70 User is offline   samdark 

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

Posted 27 October 2011 - 12:22 PM

Luciano
Check Yii2 discussion forum. There will be spaces and braces in Yii2.
Yii 1.1 Application Development Cookbook

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

#71 User is offline   Luciano 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 20-September 09
  • Location:Buenos Aires, Argentina

Posted 27 October 2011 - 12:43 PM

View Postsamdark, on 27 October 2011 - 12:22 PM, said:

Luciano
Check Yii2 discussion forum. There will be spaces and braces in Yii2.


samdark, you just made me happy...
This moment could be compared only with the moment my daughter was born (just exaggerating)...

Well, if this is not a joke, I am actually really happy!!! :)
Company web site: pressEnter

Free as in "beer"...
0

#72 User is offline   Mike 

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

Posted 27 October 2011 - 01:08 PM

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 ... ;)
2

#73 User is offline   jacmoe 

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

Posted 27 October 2011 - 01:55 PM

View Postcreocoder, on 27 October 2011 - 11:15 AM, said:

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»


That is so totally fucked up - yes, he is brilliant.

But he is not a God !!

That you are so weak that you throw all your judgments away and indulge in religious folly says a lot about you - or does it?

For Christ sakes (pun intended!) could you please sober up and get real. :lol:

Coding standards are necessary for code libraries with more than one developer / user.
Even if you have divine powers.

That's a fact.
Every framework - regardless of language - has a coding standard.
Gods or no gods.
"Less noise - more signal"
0

#74 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 27 October 2011 - 02:14 PM

Quote

Every framework - regardless of language - has a coding standard.

There is the coding standards, even if it's not documented.

Quote

That you are so weak that you throw all your judgments away and indulge in religious folly says a lot about you - or does it?

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.
No good, no bad, only consequence.
0

#75 User is offline   jacmoe 

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

Posted 27 October 2011 - 02:30 PM

He is a very talented guy.
With tons of experience.
One of my heroes.

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. ;)
"Less noise - more signal"
0

#76 User is offline   creocoder 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 204
  • Joined: 09-March 09
  • Location:*.php

Posted 27 October 2011 - 02:36 PM

Of course they should be documented. Did someone says the opposite?
No good, no bad, only consequence.
0

#77 User is offline   jacmoe 

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

Posted 27 October 2011 - 02:42 PM

View Postcreocoder, on 27 October 2011 - 02:36 PM, said:

Of course they should be documented. Did someone says the opposite?

You really like yanking peoples chains, don't you?
That's not very effective for having a healthy discussion.

View Postcreocoder, on 27 October 2011 - 02:14 PM, said:

I just feel sorry for people who are not able to understand the current framework standards.

And I feel sorry for people who just doesn't understand that you can indeed discuss the current framework standards.
Moses did not write them on stone tablets.. ;)

As a matter of fact - it's not written down anywhere.
"Less noise - more signal"
0

#78 User is offline   qiang 

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

Posted 27 October 2011 - 04:45 PM

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.
4

Share this topic:


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

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