-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated PSR-1 expansion #16
Conversation
Minor spelling corrections
…e' per line, instead of one 'use' and multiple lines (per gnugat)
…e' per line, instead of one 'use' and multiple lines (per gnugat) ... also remove prefix/suffix requirements, per discssion with klaussilveira
…ants as a fallback
…ead of disallowing
…apter to say only E_ALL
Please be more explicit than "Note the placement of parentheses, spaces, and braces." Some of the spec has this, in 0700 and 0800 the phrase is used a few times. |
@Drak +1 |
@nateabele Let me make sure I have this right. You would agree to the PSR as currently written for these items mentioned by @Drak? "The main important stuff is no white space, 4 spaces for indentation, no short php open tag, no PHP close tag, namespace and use declarations placement, defining where braces are placed, visibility on class methods and lastly camel casing on class names and methods (leaving functions out of the mix). " |
@pmjones Sorry, should have clarified. I was agreeing with his point about splitting them up into multiple RFCs, especially the docblock one, which definitely deserves to be its own thing (tangent: I think we could really use some innovation in the docblock department). From @Drak's list, the things I'd agree to off the bat are: (1) no [trailing, I'm guessing?] whitespace, (2) no short open tag, (3) I still think underscores make sense for private and protected methods/properties for various reasons, and leaving off PHP close tags deeply offends my very strong preference for symmetry. Call me crazy. :-) (And lets be honest, the benefits of omitting them are overstated unless you're really lazy). Finally, tabs vs. spaces belongs in a style guide, not a standard. |
Thanks for clarifying; I thought as much but needed to make sure. An FWIW, this is a style guide. |
@nateabele I would say one of the most important things to get standardised is the whole tabs vs spaces thing. Overall, real tabs are pretty much frowned upon by most, people favoring x spaces. Given one of the goals here is interoperability, 4 spaces per indentation is a pretty necessary rule. This is not a matter of style, but necessity when working with a variety of libraries. As for docblocks, personally I think they are very very necessary, but one could defer this to a separate PSR just for docblocks because there are those who bother about docblocks, and those who don't. Those who are strict can follow the PSR, and those who tend to write a few docblocks only when they feel it's necessary, can simply do their own thing. It'd be a simple thing to get ratified too because basically docblocks require a basic minimum ( |
Docblocks should definitely be a seperate PSR. We (me and one of my friends) already started to write it. |
@Drak Again, spaces vs. tabs actually has nothing to do with technical interoperability. Autoloaders see them the same. Docblock parsers see them the same. Package managers see them the same. I don't understand why we're talking about this. For that matter, is anyone even able to give a practical, technical reason why we need this? |
…e' block and the class
@Drak: I have put together a "reduced" PSR-1, noting only the items you listed, and stripping out all the others. Looking at it now, I think it's not too bad. I'd rather see more, but I think you did hit the minimal useful points, without making it too minimal. Take a look at https://github.com/pmjones/fig-standards/tree/psr-1-reduced/proposed/psr-1-coding-style-guide. )I would argue that since it has been reduced so dramatically, that there should be less flexibility in deviating from it, but that's a separate topic.) |
@pmjones Yes it does look much more doable. I wonder if you could see yourself softening the wording surrounding the 80 limit because I thought I'd configure Netbeans line limit to 80 and look over some Symfony2 code. NetBeans draws a red line down the screen at the limit. What was interesting to see is that where the code was longer than 80, it was very minimally so and splitting the lines doesnt look right in those cases. What became clear is if there is a some complex logic, for example an if statement with a few conditions, even without taking line limits into consideration, it's just much more readable by splitting the line. The other consideration is that, since most code is OO based these days, the actual available characters in a method is just 72 (since there are two indents, 4+4 to the actual code in the method). If you look, your vision is actually centered to where you are looking, so you an see, the 80 characters width is from the left of what you are reading, and not from the left of the screen or window. But given we count from the left of the text area, we need to take that into account. Here are some examples that are just over the 80 limit that would not be good to split (remember these are colour coded too by the editor) over by 5 (but actually it's just 77 long)"
this is 87 long but you'd need to split it at either the comma or the bracket, it's sort of too much.
The following is way over, at about 100. But even splitting this it would still be way over. However, it's not unreadable because the IDE colours the string.
split and it's still over the 80 limit (remember these examples are all inside methods which are already indented 4+4). I this case it's actually 88 (from the left of the editor window) after being split onto separate lines.
So what I'm showing is that we need to soften the wording a little. This rule will definitely become a PHPCS sniffer rule and we need to at least be able to set hard and soft limits. I'd personally set the soft limit at something like 90-100, and the hard limit at 120. PHPCS violations get marked and graphed (as warning or errors) so we need to be able to distinguish. Being able to recommend as well as flag a violation is particularly useful. The use of automated tools for styling is very much on the increase and it's the only way to really audit a large codebase anyhow. See the example at http://ci.zikula.org/job/Zikula_Core-1.3.3/violations/ where is reads (check style). My main two points are this:
Do you see my point? On another note, I think we might have missed another very important think - line endings. Line endings should probably be just LF. It's generally less of a problem these days because at least with GIT, that's handled at checkout if you have the right settings, but overall, almost everyone demands that files in the repo are stored with LF line endings. That means the editors/IDEs should be configured to use LF. |
Maybe we can do the following in https://github.com/pmjones/fig-standards/blob/psr-1-reduced/proposed/psr-1-coding-style-guide/0200-indenting-and-lines.md add
And regarding the line endings use how nice does this look?
The use of 90 here takes into account the potential lost characters from indentation of class methods (4+4). It means we can safely create PHPCS rules that will not generate huge reports and can generate warnings and errors with automated checking tools. |
@Drak 👍 I can get behind 80-90 / 120. |
Just my 2 cents: 0100-php-tags.md 0200-indenting-and-line-length.md 0300-namespace-use-and-class.md 0400-constants.md 0600-variable-and-property-assignment.md 0700-function-and-method-declarations.md 0900-control-structures.md |
Closing after subsequent edits; will open another one as needed. |
Updated LEAME.md
@nikic has pointed out several shortcomings to the ABNF for types, his suggestion is a solid improvement to the BNF and has been used. One modification has been made; the 1*SP in the generic definition has been replaced with *SP to allow zero spaces as well.
Cache stampede prevention - CacheItem::isRegenerating()
Fix references to classes and interfaces to include traits, fix typo
* Added note about immutability. * Update http-client.md * Fixes * Removed "reference" * Added link to PSR7 * minor
This includes changes based on comments from the earlier (now cancelled) pull request.