Yii Framework Forum: Coding Standard tools - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Coding Standard tools Help to develop yii standard application

#1 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 08 February 2012 - 08:51 PM

I dont think that now exists a file to do coding standard for Yii. I hope in Yii2.0 exists.

Now I am creating a project on github. I want to write in yii coding standard. But ... I have to define all yii standard by hand!!! I dont know if you use PHP_CodeSniffer. It can control al your code and tell you if your application is written in a specific standard. Symfony2 and Zend has this feature. Yii has not?
0

#2 User is offline   CeBe 

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

Posted 09 February 2012 - 04:22 AM

As I remember from past discussions there is no strict coding standard for yii so it would not be possible to run a PHP_CodeSniffer on the code since not everything is defined in detail.
0

#3 User is offline   samdark 

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

Posted 09 February 2012 - 08:59 AM

Well, we're sticking to some kind of silent agreement on coding standard. At least for core so it's possible even for Yii 1.1. The bad part is that you have to write definition file yourself. I can help answering questions about how Yii core is formatted.
Yii 1.1 Application Development Cookbook

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

#4 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 09 February 2012 - 02:02 PM

Ok, someone want help me to write yii coding standard?
0

#5 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 09 February 2012 - 03:21 PM

Does these "coding standards" include number of spaces inside different expressions? Yii developers prefer "spaceless" (sorry, dunno how to call it right) style:

public function save($runValidation=true,$attributes=null)
{
    if(!$runValidation || $this->validate($attributes))
        return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
    else
        return false;
}

I would write (and I think many people too):

public function save($runValidation = true, $attributes = null)
{
    if (!$runValidation || $this->validate($attributes))
        return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
    else
        return false;
}

0

#6 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 09 February 2012 - 03:25 PM

always braces

public function save($runValidation = true, $attributes = null)
{
    if (!$runValidation || $this->validate($attributes)) {
        return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
    } else {
        return false;
    }
}

0

#7 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,986
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 09 February 2012 - 06:31 PM

I dont care about braces. I care about standard. Any standard. But standard.
0

#8 User is offline   jacmoe 

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

Posted 09 February 2012 - 06:40 PM

This is religious - and we had the discussion before - with a locked topic as the final result. Posted Image

No, the team is not willing to write a coding standard. That was the very clear message we got back then.

However, I prefer spaces between operators, like Andy_s, and braces - even for a line line code block - as Mbi.
I also prefer 4 spaces instead of a tab (spaces instead of tabs).
"Less noise - more signal"
0

#9 User is offline   jacmoe 

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

Posted 09 February 2012 - 06:42 PM

That brings me to a feature request:

Could the Gii tool have a configuration option for tabs versus spaces, please?
Basically, what to insert: a tab (\t) or 2-4 spaces.
My editor of choice would be grateful.

That goes for the migration tool as well.

A configurable option would be great.
"Less noise - more signal"
0

#10 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 10 February 2012 - 04:11 AM

IMO that feature is better left to the editor... all modern editors has the ability to convert tabs to spaces and vice-versa.
Find more about me.... btw. Do you know your WAN IP?
0

#11 User is offline   ekerazha 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 526
  • Joined: 10-October 08
  • Location:European Union

Posted 10 February 2012 - 04:24 AM

View Postsensorario, on 09 February 2012 - 06:31 PM, said:

I care about standard. Any standard. But standard.


I agree.



Still I prefer
- no braces for single line statements (braces exist in order to group multiple lines, no multiple lines no braces)
- space after conditions (they are not functions like f(x) )
;D
Yii user #37
0

#12 User is offline   samdark 

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

Posted 10 February 2012 - 04:50 AM

Looks like this topic is turning into the same direction as the one jacomoe mentioned.
Yii 1.1 Application Development Cookbook

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

#13 User is offline   ekerazha 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 526
  • Joined: 10-October 08
  • Location:European Union

Posted 10 February 2012 - 03:41 PM

View Postsamdark, on 10 February 2012 - 04:50 AM, said:

Looks like this topic is turning into the same direction as the one jacomoe mentioned.

http://www.thefreedictionary.com/joke
Yii user #37
0

#14 User is offline   jacmoe 

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

Posted 10 February 2012 - 04:04 PM

View Postmdomba, on 10 February 2012 - 04:11 AM, said:

IMO that feature is better left to the editor... all modern editors has the ability to convert tabs to spaces and vice-versa.

That's what I have to do now: each time I use the migration tool or the gii generator I have to convert it.
A configurable option would be far better.
Could default to a tab character or 4 spaces, as long as I can configure it. :)


"Less noise - more signal"
0

#15 User is offline   samdark 

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

Posted 11 February 2012 - 06:19 AM

Yes, I think that's possible. Since we don't care about Gii performance much, I think there's no problem making it feature rich and configurable. Once Yii2 code will be at GitHub you'll have an opportunity to help us implement all these useful features.
Yii 1.1 Application Development Cookbook

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

#16 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 11 February 2012 - 06:43 AM

Er... doesn't gii already feature templates? What's wrong with modifying those?
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#17 User is offline   samdark 

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

Posted 11 February 2012 - 07:13 AM

Nothing wrong with it. Maybe it's a better way actually.
Yii 1.1 Application Development Cookbook

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

#18 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 11 February 2012 - 10:42 AM

[OT]

I was planning to have a repository of user-submitted templates for giix. Had no time to work on it yet.
Combining this (or the new approach for this in Gii) with Yii 2.0 packages can be very useful.
0

#19 User is offline   choiceerp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 24-April 10
  • Location:EUROPA - France - Paris

Posted 01 March 2012 - 12:59 PM

View Postekerazha, on 10 February 2012 - 04:24 AM, said:

I agree.

Still I prefer
- no braces for single line statements (braces exist in order to group multiple lines, no multiple lines no braces)
- space after conditions (they are not functions like f(x) )
;D


I agree to, if it's not necessary to fix everythings, but just some rule to make the code more readable. If in 2 or 3 year I should get an old application with no rule, I whant not must be say; "put your work at trash and restart on another framework".
In same time if i get the same project but from Symfony2 and is writted on the same way, I can't say same and that just because Symfony2 have set writting rules and if the developper don't follow and if the code isn't readable, that mean the project manager is null and I put him in trash.

example of few rule:
- no braces for single line statements (braces exist in order to group multiple lines, no multiple lines no braces)
- space after conditions (they are not functions like f(x) )
- private menber start by _ and not static member start in minus
- indentation (space or tab, not problem but indent)
- presence of doc generated automaticly (@param and @return minimum)
and that all (and i think that the minimum)
knowledge is valid only if it is shared ;-)
0

#20 User is offline   jacmoe 

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

Posted 01 March 2012 - 01:06 PM

I think it would be very helpful to have an official code layout definition file (or what it is called) that you run through a tool.
As long as the def file is approved (and maintained by) the Yii team, it would simply remove any further need to discuss braces, spaces and whatever.
Just run the tool, and that's it. :)
"Less noise - more signal"
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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