Git Product home page Git Product logo

Comments (9)

evantishuk avatar evantishuk commented on July 1, 2024

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.

dseguy avatar dseguy commented on July 1, 2024

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.

philsturgeon avatar philsturgeon commented on July 1, 2024

So remove it! πŸ‘

from clearphp.

auroraeosrose avatar auroraeosrose commented on July 1, 2024

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.

weierophinney avatar weierophinney commented on July 1, 2024

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.

philsturgeon avatar philsturgeon commented on July 1, 2024

Β (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.

dragoonis avatar dragoonis commented on July 1, 2024

Trailing commas for the win πŸ‘

from clearphp.

jrfnl avatar jrfnl commented on July 1, 2024

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

dseguy avatar dseguy commented on July 1, 2024

OK. Rule removed.

from clearphp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.