4 ms·
My beef with PHP is not so much the language itself, but the weird community that surrounds it. The FIG standard that forbids TAB for indentation (which is per
by pdenton 5y ago
My beef with PHP is not so much the language itself, but the weird community that surrounds it.
The FIG standard that forbids TAB for indentation (which is perfectly legal in PHP), the notion that classes should be either abstract or final, the micro-optimizations (thou must use single quotes, things like that).
I don't think anyone can tell anyone how to write PHP, because nobody knows how to get it right (myself included). Yet in my many years of coding in PHP, there's been more and more tooling and so-called "standards" that do exactly this.
- timw4mail 5y agoI'm a fan of PHP in general, but I've never liked the FIG coding standards. Common interfaces for logging, caching, and the like are useful, though, so I don't think the PSRs are all useless. After using more languages with a distinction between strings and characters, a string in single quotes starts to look weird. Although there are several questionable "best practices" in general, I have found that stricter typing in PHP has generally been a plus.
- deleted 5y ago[deleted]
- rtheunissen 5y agoIf you look at a language like Go, it's rare to find a project not using the standard gofmt. PSR-12 states that "the benefit of this guide is not in the rules themselves but the sharing of those rules". The guidelines to use single quotes and tabs vs spaces exist for the sake of consistency, to remove that subjective argument from the conversation.
- hparadiz 5y agoIt's just a linting standard. You're free to use it or not and some linters support the entire specification as-is but with tabs instead.
- kijin 5y agoPHP's chaotic developer community, as well as the "there are 1000 ways to do the same thing" philosophy that it inherited from Perl, is fertile ground for those who wish to say that they know better than others. This occurs in every level, from which quote character to use, all the way to how to arrange your namespaces. The PSR's also reflect this tendency. They're a mix of extremely useful standardization (e.g. PSR-4) and hardcode nitpicking about whitespace (e.g. PSR-12). Take what you need, focus on maintainability and interoperability, and ignore the noise.
- pdenton 5y agoThank you so much, this is good advice and it's what I'm doing right now. Much like how a carpenter carefully picks the right tools to work with. Writing code isn't an exact science and much like in probably any other profession, this requires us to twist and bend or even break the rules in order to create something beautiful. As a programmer, it's desirable to adhere to SOLID principles but without freedom of expression this is pretty much impossible. A good mix of constraints and creativity can take years to develop and should probably keep developing over time as one exercises the art.
- larzang 5y agoFIG standards are explicitly interoperability standards. They make it easy for anyone to jump into a new company or open source project with minimal friction and minimal bikeshedding. If you or your team don't care about that and want to do something different, there's nothing stopping you. Even the Symfony team, who contributed to these standards and largely follow them, have gone their own way when they thought it was worth the trade-off.
- nine_k 5y agoFWIW, I think the rule about classes being either abstract (like interfaces) or final makes sense. Inheritance is the biggest OOP anti-pattern, producing most headache and bugs. It cannot be completely removed from an OO language like PHP, but can be nicely replaced with composition using interfaces / abstract classes and traits.
- Lazare 5y agoFIG stands for Framework Interop Group. At its peak, it was a place for representatives of the major PHP frameworks and libraries to hash out ways for their projects to cooperate more effectively, and some of the standards - such as PSRs 3, 4, and 7, have been extremely useful. If you're not writing a framework or library for others to use, nothing the FIG says is necessarily relevant to you. And in fact, even if you are, Doctrine, Guzzle, Laravel, and Symfony have all left the FIG, so it has even less relevance now. So...it's a group that used to make standards for a very specific audience, and now mostly doesn't, in part because all of the most important members of that audience got fed up and left. That's your biggest beef with PHP? Just adopt whatever standards you like.
- conradfr 5y agoI never heard of the abstract/final thing, except maybe from one or two coworkers that don't produce much but talk about the language all day and will berate you about protected/private or ordering your "use" alphabetically. It's true that the PHP community has a bit of an inferiority complex which result sometimes in abuse of patterns, like suddenly someday everyone wanted to do refactor everything with DDD/CQRS/etc for no good reason.