Yii Framework Forum: PSR-12 coding style - Yii Framework Forum

Jump to content

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

PSR-12 coding style Rate Topic: -----

#1 User is offline   samdark 

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

Posted 18 January 2016 - 06:51 PM

As part of PHP-FIG along with Michael Cullum, Korvin Szanto and Robert Deutz we're working on the next coding standard. PSR-12. The idea is to fix PSR-2 minor issues and add up-to-date PHP stuff into it.

Here it is: https://github.com/p...-style-guide.md
And here's thoughts behind it: https://github.com/p...e-guide-meta.md

What do you think? Anything to add/remove/fix?
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
2

#2 User is offline   jacmoe 

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

Posted 18 January 2016 - 09:37 PM

I don't have anything to add at the moment but I really like it. :)
"Less noise - more signal"
0

#3 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 19 January 2016 - 04:33 PM

Use statements should be in alphabetical order - it is really useful when we have many of them.
1

#4 User is offline   samdark 

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

Posted 20 January 2016 - 07:45 AM

We had that previously but it's too strong requirement for people without IDEs. And there are many.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#5 User is offline   samdark 

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

Posted 31 July 2016 - 08:59 AM

Some progress on the document: https://github.com/p...a3af4df9e3b909c
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#6 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 31 July 2016 - 09:29 AM

View Postsamdark, on 20 January 2016 - 07:45 AM, said:

We had that previously but it's too strong requirement for people without IDEs. And there are many.


After half a year I must disagree with that.
1. I often change the order of use statements and it is really easy to make it alphabetical.
2. Unordered use statements is a nightmare...
3. Coding standard PSRs are mostly for automated tools and it is hard to follow any standard without them - it is easy to miss some space or put the bracket in wrong place. Also, there are separated tools for fixing CS (https://github.com/F...P/PHP-CS-Fixer/), so you don't need use IDEs for automatically fixing some CS issues.
0

#7 User is offline   samdark 

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

Posted 31 July 2016 - 09:35 AM

1. Not without a tool.
2. Why? I don't see any issue with that. Additionally, I saw some people are grouping but not alphabetically such as domain stuff is separated from infrastructure.
3. I'm following coding standard w/o tools same as many other developers.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#8 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 31 July 2016 - 01:04 PM

1. I'm doing that without a tool and it is easy - you just need to know the alphabet. :)
2. It is much harder to find anything if use statements are in random order. Couple times I even try to add a statement, that already exists, because I can't find them at first look. This is much more annoying than missing space after control structure or bracket in wrong place.
3. I can sort use statements alphabetically without any tool. More often I omit some spaces after control structures, so from my point of view, the PSR already has rules which are difficult to follow without tools for fixing CS, and refuse to add a rule which is not problematic at all.
0

#9 User is offline   samdark 

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

Posted 31 July 2016 - 02:49 PM

Sorting is easy for 1st letter only. After 2nd letter match it becomes a nightmare to maintain w/o a tool. Anyway, that's my personal opinion and I'm not the only who's behind PSR-12: there are editor and sponsor + many projects to vote for it. I think it's a good idea if you'll post to mailing list about it https://groups.googl...!forum/php-fig. Don't forget to prefix your topic with [PSR-12].
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#10 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 01 August 2016 - 02:44 AM

View Postsamdark, on 31 July 2016 - 02:49 PM, said:

Sorting is easy for 1st letter only. After 2nd letter match it becomes a nightmare to maintain w/o a tool.


Why? Sorting by the second and the next letters looks the same as sorting by first letter - you just sort the smaller group with the same prefix. It actually should be easier than sorting by first letter because you have less items to sort.
0

#11 User is offline   samdark 

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

Posted 01 August 2016 - 05:17 AM

I don't know. My eye doesn't like doing that. I'd better leave it messy than do it by hand.

I never actually looking at imports. IDE solves it for me via quick info boxes which show fully qualified names and navigation which goes straight to implementation. Also it adds them automatically.

Overall there are two goals for the coding standard:

1. Make it human-readable.
2. Make merge fail less w/ nicer diffs.

As for #1, as I've mentioned, I saw imports grouped logically, not alphabetically and that makes more sense in some cases. Especially when domain layer is big and you're working with more than a single bounded context. If we add the rule that everything should be sorted alphabetically we're basically eliminating an ability to group imports in any other way.

As for #2, re-ordering or imports may affect diffs but it doesn't really matter if these are ordered by name or not.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#12 User is offline   rob006 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 159
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 01 August 2016 - 05:46 AM

View Postsamdark, on 01 August 2016 - 05:17 AM, said:

I never actually looking at imports. IDE solves it for me via quick info boxes which show fully qualified names and navigation which goes straight to implementation. Also it adds them automatically.


I thought that we are talking about the people who do not use the IDE. In your case, if the IDE manages imports it might as well sort them alphabetically. For people without IDE random order of imports is a problem because they must read them and manage by hand.

Quote

As for #1, as I've mentioned, I saw imports grouped logically, not alphabetically and that makes more sense in some cases. Especially when domain layer is big and you're working with more than a single bounded context. If we add the rule that everything should be sorted alphabetically we're basically eliminating an ability to group imports in any other way.


Namespaces should represent the structure of the application. In that case, alphabetic order naturally groups imports by domain and purpose of objects.
0

#13 User is offline   samdark 

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

Posted 01 August 2016 - 08:36 AM

Well, seems I can't really provide strong arguments against it :) Personally I'm not fond of it but I think you have a chance to have it in the PSR. Post to mailing list as I've suggested and I think it will be included in the style guide poll (other guys working with me are putting it together).
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#14 User is offline   samdark 

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

Posted 17 October 2016 - 01:20 PM

Survey launched: https://groups.googl...fig/beBQqv6PEyc
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#15 User is offline   Bizley 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 922
  • Joined: 29-July 14
  • Location:Wrocław

Posted 20 October 2016 - 02:18 AM

I agree with most of the propositions here.

Looks like I have to teach myself to write brackets at the end of $model = new Model; :lol:
http://bizley.pl ʕ•ᴥ•ʔ
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