Comments (9)
I am in agreement with @philsturgeon. While strictness is generally admirable, it's decidedly lame in this situation. Trailing commas don't degrade the readability of code whatsoever. A stricter policy only creates unnecessary obstacles and gotchas. I routinely thank PHP's syntax when I can effortlessly copy or re-order lines of key/val pairs without having to worry about that trailing comma. When I have to switch to coding in JS I curse it's strict nature.
from clearphp.
Changing all arrays to remove them is futile : I'd classify this as coding convention, rather than less bug-prone code.
Out of 200 PHP projects, a very small minority followed this.
I don't like that rule too much myself. :)
from clearphp.
So remove it! π
from clearphp.
I'm +1ing the "Remove it" - this is exactly the OPPOSITE of most coding standards and against the advice I give people when coding in PHP - it's far less error prone to always have a trailing comma after array entries - causes fewer merge conflicts and far fewer parse errors when you add/remove entries :)
from clearphp.
A clarification to the comment from @philsturgeon β the most compelling reason I've seen stated for keeping the trailing comma on multi-line array definitions is for simplifying diffs associated with version control. Essentially, adding or removing an array entry only changes that line, and no others; if you require that the last entry MUST NOT have a comma, then:
- removing the last entry ALWAYS results in a two-line diff, as the previous line must now change to remove the comma
- adding a new entry at the end ALWAYS results in a two-line diff, as the former last entry now must add a comma
- re-ordering that involves the last entry ALWAYS results in N+1 lines of diff (again, because whatever the new last entry is must also remove the comma)
Essentially, trailing commas simplify diffs and reduce merge conflicts. I only wish JavaScript allowed it! (I've become so accustomed to doing it in PHP that I've introduced errors in my JavaScript and JSON by keeping the trailing commas!)
from clearphp.
Β (I've become so accustomed to doing it in PHP that I've introduced errors in my JavaScript and JSON by keeping the trailing commas!)
Real problem.
from clearphp.
Trailing commas for the win π
from clearphp.
+1 on trailing comma's, aka removing this rule.
It helps prevents parse errors from copy/paste actions, so should be considered a good thingββ’β
from clearphp.
OK. Rule removed.
from clearphp.
Related Issues (20)
- Do Not Include Closing PHP Tag In Example Code HOT 8
- Whitespace HOT 4
- avoid-those-slow-functions.md array_search duplicate HOT 1
- avoid-those-slow-functions.md: Add the uniqid function HOT 1
- Mess with code example in Avoid Redefining Properties HOT 2
- duplicate pages in the Performances group? HOT 1
- Error text in Imported collision HOT 2
- avoid-those-slow-functions has some bad replacements HOT 4
- Suggestion: Add scrutinizer CI to tools and add tools page to annexes HOT 2
- Two rules which are essentially the same ? HOT 2
- Rule copied, but not adjusted HOT 1
- Avoid direct include or require in spl_autoload_register HOT 2
- no-hardcoded-credential - suggest solutions HOT 2
- No Eval HOT 4
- no-double-quote
- Assigning to array with list has changed in PHP 7. HOT 1
- Always Ha(ve|s) Visibility and Interfaces HOT 6
- One Tool HOT 1
- no-letter-logical exemple is wrong
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clearphp.