27 ms·
PHP the Wrong Way
- artificialidiot 10y agoThe article pretty much applies to any comparable language, really.
- Olap84 10y agoWait, is this satire or not? Does it advocate people don't use frameworks? Loved the opening paragraph though
- syntex 10y agoIt's definitely not a satire. They are some valid points. It's not against using frameworks. I think it's more about finding the right solution for the problem.
- Olap84 10y agoWhat I take from is not to use PHP, which I do as it pays the bills, but why would anyone choose it for a new project baffles me. This article doesn't help it.
- fredleblanc 10y agoI love PHP. It feels like a complete toolbox to me, whereas other languages like Python or Ruby feel like I'm buying an entire Home Depot for every project. Sometimes you need the whole store. Most times I don't. I think the OP has some good points about reconsidering the standard answers that everyone gives to questions when asked. There are no silver bullets in web, but many things sure are treated like them. Maybe there are projects where PHP isn't right. There are probably tons. But that doesn't mean that it's always wrong. PHP is what got me into making web things in the first place. I loved (and still love) how utilitarian it can be. But perhaps that's where I differ from most people. I see myself as someone that makes web stuff. Most seem to see themselves as app creators or system builders. And they probably are. Sure, I do that too when the time comes, but if most of the time I'm building a front-end to a CMS, I'm hardly "engineering" anything. I'm mostly just trying to make specific art for other people. Anyway, I don't understand why PHP would immediately be ruled out from this article. It feels like the JavaScript of the server-side world to me. Use as little or as much as you want. You can do awful things with it, but also wonderful things.
- Olap84 10y agoWell I certainly agree with the right tool for the right job. And PHP has some roles. My point was more about the article, which would, imo, put programmers off PHP with its contrariness and smugness.
- yedpodtrzitko 10y agoI just skimmed the website, and I am still not sure if it's meant seriously or if it's some kind of joke? Feels a bit contradictory eg. "dont use framework" vs "make software secure by default". Isn't a security one of the gains of using frameworks, beside other things? You would need to be a security expert to cover all potential security issues when writing something from a scratch.
- bad_user 10y agoThe very existence of PHP is a contradiction, so I wouldn't sweat to much about it. But speaking of boolean logic, negating "always use a framework" does not yield your interpretation.
- throwaway1974 10y ago"The very existence of PHP is a contradiction" Uhm no for me coming from a C background I love PHP since its basically C with a lot of the boring/repetitive stuff abstracted away Good PHP code exists, it only got a bad name due to "web developers" with no formal programming education stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. PHP is a hammer, blaming the hammer is silly when the person using it might now know how to swing it safely.
- jlis 10y agothanks!
- roblabla 10y agoPHP (the interpreter) used to be filled with bugs, design flaws and incoherences. It got better lately, but IMO it still caries a huge mess of legacy stuff that shouldn't even exist (mysql_real_escape_string anyone?) In this case, both the hammer and the hammer's user can be blamed.
- Shanea93 10y ago
- paulgrimes1 10y agoThis reads to me as a parent saying to a kid (me) "Well, you could stick your hand in the fire, but.."
- iamd3vil 10y agoI generally agree with the view of keeping your application simple and not using big frameworks but after seeing so many PHP programmers write spaghetti and insecure code, I pretty much recommend frameworks now. You can say the problem is not with writing PHP without any framework but with the programmers, the problem lies with the low barrier for entry into PHP. Frameworks atleast teach you how to make your code modular and make your application secure (atleast sane defaults).
- phillu 10y agoIn my experience using a framework does not prevent spaghetti code.
- iamd3vil 10y agoIf you want to write spaghetti code, you can write it whichever approach you take. It's more about making it difficult to shoot yourself in the foot.
- pcunite 10y agoFrameworks allow you to shoot yourself in the foot with a Tank.
- deleted 10y ago[deleted]
- reitanqild 10y agoPerfect example. You nailed it! (Anyone close to familiar with tanks will know it will take quite some effort compared to any of the smaller alternatives ;-)
- TeMPOraL 10y agoBut you can easily get yourself crushed by a tank, and also "why oh WHY DID YOU DRIVE A TANK TO PICK UP OUR KIDS FROM THE SCHOOL?!?"
- paulgrimes1 10y agoIf every project had unlimited budget and only quality developers, this site would be a little bible. The reality is much different - communities exist so we can stand on the shoulders of our peers :)
- hthbh65 10y agobeat a dead horse, will ya
- tga 10y agoThere is a grain of truth in what they're trying to say, but the conclusions are outright misguided. My favorite is "The wrong way: Thinking of patterns when solving problems." -- textbook reinventing the wheel / NIH.
- pvdebbe 10y agoI don't think it's saying exactly that. One should think up a solution first, then see if one needs patterns to fit that solution into the code base in language of choice. PHP certainly doesn't need all of Gang of Four recipes due to dynamicity and other factors.
- jpnave 10y agoSo the author considers following PSR guidelines beyond 1 and 2 to be "the wrong way"? PSR-4 is the currently accepted best practice for autoloading and while it "may [have] a direct effect upon how you code your software," it's the optimal approach for 99% of projects I've encountered. Following community interoperability guidelines is what allows developers to move away from monolithic frameworks and compose projects based on the packages they need.
- stephenr 10y ago> currently accepted best practice for autoloading According to who? FIG? Are you aware that php has a built in auto loader that supports namespaces and is written in C? > compose projects based on the packages they need. Ah, the NPM/Composer golden brick road to development. Aka, the "I don't know what this is but I'm gonna lick it" approach to development, where you end up with 50 "micro-frameworks" or "utility libraries" each of which depends on a further 20 other libraries. I have some issues with this site but it's right that the FIG is a joke, and anyone who claims its "best practice" is not paying attention.
- mgkimsal 10y ago> Are you aware that php has a built in auto loader that supports namespaces and is written in C? What are you referring to?
- vlunkr 10y agoSo if I was starting a new project now, I shouldn't use a framework or any pattern too strictly, so.. what do I do? Following this logic will give me spaghetti code and reinvented wheels. If there are some basic patterns to follow they should be included here.
- corobo 10y agoMy feeling is I should just start coding with whatever I know and not bother getting involved in arguments about the underlying language. Time is money friend!
- laurent123456 10y agoThe problem is that companies that don't use frameworks end up re-implementing their own as complexity grows, and of course usually do so extremely poorly. No matter what, for any non-trivial application, you DO need a framework - the choice is either to use an existing one or to implement your own. The big advantage of existing ones, in my view, is that they are well documented and everybody can learn them. That pretty much never happens with bespoke frameworks.
- d3ckard 10y agoI do not want to be mean, but I honestly feel there is no 'right way' in case of PHP. There are communities that care about 'doing it right' and there are some that want just to 'get the job done'. I prefer the former, PHP always seemed to prefer the latter.
- Shanea93 10y agoThis is a massive overgeneralisation of a humongous amount of people and man-hours of work. Why do you feel this? Do you have anything to back up this statement? Anecdotally speaking, I'm a Senior Software Engineer working with Go and PHP. We use Go when working on performance critical code, because for us that's where it excels. We use PHP when we need simple interoperability with the legacy Magento site our company runs and for jobs like running a CSV importer or some other oft-visited-task. We both get the job done and care about doing it right. You can write some truly beautiful code in PHP if you have the correct level of patience, process and experience behind you.
- pc86 10y ago99% of people who get paid to write PHP do not have the requisite level of patience, process, or experience to write a fibonacci method let alone write "truly beautiful" PHP.
- Shanea93 10y agoIt's really easy to make up statistics on the spot with absolutely no source. I very much doubt that people would be getting paid to write any code if they couldn't implement a single for loop in their primary programming language.
- pc86 10y agoPHP was the first language I ever used professionally. The code I wrote - the code every single one of my colleagues wrote - was atrocious. We were paid bottom dollar ($30k in 2008) to write absolute shit code. The PHP community in my area was the same. All newbies, all paid barely more than a fast food manager, all writing code that could be taken down by a HS student with Fiddler. I'm sure different experiences exist, but the majority of folks who I speak to have experiences that match mine very closely. PHP is a ghetto.
- wehadfun 10y agoI didn't read it all but some people are do dogmatic about things it is stupid. I have dealt with plenty of co-workers who read some book and promptly beat everyone with it.
- ungzd 10y agoPHP community had always been anti-frameworks and anti-libraries. I worked at company where use of third-party libraries was entirely forbidden on most projects. I think it's because: - Quality of PHP frameworks is low (at least it was last time I used it) - PHP parses and evaluates whole libraries and framework code on each requests. There's proprietary commercial (lol!) software to enable at least caching of bytecode - Packaging just does not work (Pear, now there's Composer, not tried it, seems that it works) Overall, last time I used PHP i had sense of its community mostly being nihilistic and preferring cowboy programming. It's straight opposite to Java where you will be shamed for not using dependency injection and EJBs for page visits counter. In PHP world you are considered insane misfit if you're writing tests. For some things advice to just code and don't use unnecessary libs is useful. Recently I had that php/cgi feeling when I worked on small microservice in clojure: no OOP, no MVC, no ORM, no templates, no separating each 10 lines of code to module, just take Ring request and return Ring response which are simple associative arrays. This was a refreshing feeling.
- andyfleming 10y agoIf you haven't used PHP since composer became a standard in projects, you don't know modern PHP.
- fredleblanc 10y ago"Modern PHP" being one of the trigger words in the OP. That said, in terms of timeline, PHP has gotten better as a whole since then.
- spdionis 10y agoThe biggest problem in the modern PHP community is that you will be shamed for not using DI for a page counter so i don't know what you're talking about.
- mirekrusin 10y agoPaul Graham's quote in "Design Patterns" section actually says nothing or the opposite of what the author is trying to say - Paul says that when he's seeing in the code things (shapes <<of code>>) that repeat themselves, it's an indication to him that he's missing some macro definition that would build this shape for him so he doesn't need to repeat himself by manually creating it all the time - that he can reuse it (as macro). How does it relate to design patterns? Does it say not to use them? Absolutely not. It says the opposite, if anything - to recognise patterns in your code. "Design patterns" is just an idea that if you see your patterns repeating themselves (some of your macros tend to be very similar in different projects) then you should give it a name. This way when you explain system to your colleagues it's easier to communicate.
- fareesh 10y agoIMO one of the key missing points here that is not really considered, is that when you use a well documented and relatively mature framework, it greatly simplifies some of the non-programming related aspects of software development, particularly with regard to getting new developers up to speed, and ensuring that even your junior-most developers are able to contribute without having to become heavily acquainted with your specific implementation of authentication, file uploads, routing, etc.
- catuskoti 10y agoWell, I always write a command line (CLI) program first, without worrying at all, about what kind of user interfaces (UI) I may do later on. Frameworks do it the other way around. They generate a skeleton for a web user interface or a mobile app, and next, the real program gets unidentifiably shoehorned in. There are so many different ways to call a program function: by the user, by one of your own scripts that does it in batch, by an external program through an API, through a web user interface, by a mobile app, by a desktop app, ... Isn't the most stupid way of building a program, to shoehorn it into a web user interface? It pretty much guarantees that you will have to implement the same logic many times all over again. That kind of applications can never be consistent. Furthermore, my CLI programs are trivially easy to containerize properly with tools like docker. How can you do that with a monolithic framework monster?
- omginternets 10y agoIs it me or is the author confused about the distinction between a library and a framework? To me, a framework implies inversion of control: you don't call the framework's code; the framework's code calls your code. Granted, he skirts the issue with phrases like "A framework is a system that helps you build software, but at the same time it forces you to work within the limitations and restrictions of the framework itself", but this describes what a framework achieves, not what it is. Call me pedantic, but this I find this indicative of poor understanding, and this article raises a number of red flags along these lines, such as this gem: >PHP on the other hand was created from the beginning by Rasmus Lerdorf as a set of tools written in C that would enable you to easily and quickly develop dynamic HTML. As such PHP was, and still is, a framework in and of itself. Uh... what? Maybe I'm overstepping my bounds, but this article is furthering certain stereotypes about PHP-programmers.
- andyfleming 10y agoNo, you are correct. Most developers today would understand a framework includes your code, as where with libraries, your code includes them.
- nilved 10y agoI think that's generally a good heuristic but fails in a lot of cases. The distinction between frameworks and libraries is murky and mostly semantic.
- omginternets 10y agoI don't think it's murky, I think it's contextual. Code can be used as a library (i.e.: I call it), or code can be used as a framework (i.e.: it calls me). Some code can be used either way. Sure it's semantic, but meaning is rather important...
- ownagefool 10y ago> Maybe I'm overstepping my bounds, but this article is furthering certain stereotypes about PHP-programmers. You probably are. You'd make a better case if you were actually discussing http://www.phptherightway.com/ http://www.phptherightway.com/.
- Practicality 10y agoPHP is the very different from development in C# or Java. Anyone from those backgrounds pretty much automatically hates it. PHP will punish you hard for designs that would be fantastic in .NET or Java. It's also very different than Perl or Python. It tries to be specific to the web and that makes a lot of oddities that the more general languages do not have. OTOH you can make a fantastic design in PHP. It's just that there are very few people who know how to do that. Frankly, because it's not taught... anywhere. So, yeah, as much as I've learned how to use PHP (through 11 painful years), it's really hard to figure out how to use correctly. It's possible. The ideal PHP design (currently) is a hybrid between OOP and straight script that will look bizarre to anyone from, well, any other background. As others have mentioned you have to be very careful not to load too much into memory or you will come crashing down fast. I still use it, because now I know how, but, ironically, I wouldn't recommend it. It's so very different from anything else that I don't know that the skills transfer well to other languages (other than straight-up problem solving).
- michaldudek 10y agoAnd that's how Laravel was born... This website should be taken down. Wanna be back to the 2000's, are we?
- swalsh 10y agoPHP is certainly a unique community, a very pragmatic bunch they are, but that's why we love em'
- nercury 10y agoIt is near impossible to write "Modern" PHP and achieve good performance. On every request, PHP reads and parses every file that is referenced somehow. It is in direct contradiction to the language constructs the PHP itself provides - especially Exceptions, Interfaces and Inheritance. People want to use these features, because they help design better systems, where the concerns are separated, and features are plugins instead of hardcoded all over the place. Unfortunately, the required files for a request can pile up quite quickly, to the point where bytecode cache does not help, serving multiple requests per PHP load does not help, prewarming cache for frontend such as Varnish does not help, memory usage is over the roof because of trashed heap memory. So, to sum up, the author here is right: this is insanity, until PHP provides a module system that can handle PHP abstractions.
- CiPHPerCoder 10y ago> So, to sum up, the author here is right: this is insanity, until PHP provides a module system that can handle PHP abstractions. I suspect you're being downvoted because we have this: https://getcomposer.org https://getcomposer.org + https://secure.php.net/manual/en/language.oop5.abstract.php https://secure.php.net/manual/en/language.oop5.abstract.php
- nercury 10y agoI worked with PHP for 5 years and I am well aware of the composer; I am being downvoted because I said that author is right on some point.
- spdionis 10y agoAnd yet PHP mostly outperforms both ruby and python. You probably haven't even used opcache.
- qwertyuiop924 10y agoI'm not a huge fan of OO, but this gets the history of OO soooo wrong. I mean, really, this has to be a joke.
- gedrap 10y ago>>> The wrong way: Always use a framework on top of PHP I haven't been actively working with PHP for quite some time but... From what I've seen, I wish many people didn't take this advice (including the teenager me). It's similar to ORM. Often, if you don't use one, you end up building one, a very poor one. Yes yes I know there are exceptions and all but, in general, that's truth. Same with frameworks. If you don't use one, you end up writing a poor one, unless all you need is a page that outputs a result of a single SQL query, or something equally trivial. I've seen plenty of 10k+ LoC applications with home made frameworks, poorly replicating open source ones, just because. >>> In the world of Python and Ruby building websites from the ground up is tiresome because neither Python nor Ruby was originally created to build websites. As a result general purpose frameworks such as Django and Ruby on Rails quickly became popular for building websites in these languages. RoR, Django became popular because it's so simple to build basic CRUD apps, which most of the applications are. Most of the stuff is done for you. Can't say the same about plain PHP. The author largely ignores the reasons why the mentioned frameworks became popular. Yes, you could make a well engineered solution from scratch. But chances are that you will not, time constraints being one of the reasons. Sorry, couldn't read further than that.
- hazbo 10y agoYou make a fair point. I've seen this happen before and after a while, projects that have essentially turned into a poor framework, plus the application, can become somewhat of a pain to maintain. PHP has come a long way in the past few years and the amount of open source packages has become huge, especially since the adoption of composer. I think with that in mind, it is now easier to build and maintain PHP applications without a framework as such, but just with the components you specifically need. Like yourself, I haven't actively been working with PHP for a while either. But it's been interesting to watch what's been happening with it and it's community.
- willishq 10y agoI know what you mean, I once worked on a project which similar to what you describe, the problem in these instances is when the people involved in the creation of the project are no longer involved in the maintenance of the project so the project veers away from the implemented standards and becomes a smorgasbord of badly-integrated composer packages.
- programminggeek 10y agoPHP is really great. I'm not sure why so many people hate it so violently. It's useful and runs like 1/4th of the web.
- CiPHPerCoder 10y agoYou're thinking WordPress, which runs 25% of the web. PHP runs a lot more. Over 80% according to w3techs.
- programminggeek 10y agoMy bad.
- czarpino 10y agoThis is satirical right? Unless you're building something super trivial, a framework is the way to go. You end up reinventing the wheel anyway. Here's a sober reason why to use a framework http://symfony.com/why-use-a-framework http://symfony.com/why-use-a-framework.
- mediaserf 10y agoThis is awesome, thank you! PHP may have started out as a "set of tools", but it evolved into a complete language. Like any programming language, you can write sloppy code or elegant code in PHP - with or without a framework. Languages are foundations on which frameworks and design patterns can be built to solve common problems. The trap that we fall into is trying to fit all of our problems into those common ones that frameworks and design patterns solve. This leaves potential edge cases that become bigger problems. PHP can be has hacky or as elegant as you make it. The versatility of that makes it a great utility. It also makes it very approachable. This is a big contributor to why it runs a big part of the web.
- V-2 10y agoWhy learn frameworks when you can build everything from scratch and become a true carpenter ("building software using general purpose frameworks doesn’t make you a coder or a programmer any more than putting together a pre-built house makes you a carpenter"). "These people [framework creators] seems to be infatuated by the though of having other people follow their “way of doing things”, becoming some kind of PHP community leaders, and having other people use their latest “hip” Open Source tools..." How lame of these people. The problem is, if I inherit an application created with a well-known framework, I'll have a much easier time figuring out what is what, and looking for answers when something goes awry. On the other hand, if the codebase has been written from scratch by Greg, a real carpenter of a programmer, who is no longer with the company, then good luck. I'm at his mercy entirely. I'll be having his "way of doing things" for dinner whether I want it or not, the only difference is that I won't have a community of other people in the same situation. This aspect isn't addressed by the author at all, although he found just enough time to provide us with a psychological analysis of framework authors and their narcissist motivations :)
- MustardTiger 10y agoI wonder why this mentality only exists with web devs. Everywhere else, someone writing software is considered normal, not some scary problem. Nobody sees any other kind of application written by a previous programmer and cries "oh no! I am entirely at the mercy of this previous programmer! If only they had used one of the dozen competing frameworks this tragedy could have been avoided.". It is just normal. Perhaps the low barrier to entry and corresponding low average experience of web developers plays a part in this mentality.
- V-2 10y ago"I wonder why this mentality only exists with web devs [...] Nobody sees any other kind of application [...]" Your premise - on which you based a slightly convoluted ad hominem, implying lack of professional experience on my part - is false to start with. While I did have some PHP experience, I'm not really a web dev. I'm a mobile (Android) and desktop (Windows) developer. Having said that, with web applications you typically have more moving parts and layers to integrate than in case of a client app.
- siegecraft 10y agoThe entire argument could be reduced to: "be informed, and make good decisions" which is a very banal statement that could be applied to almost every endeavor in life. Because PHP makes it so easy to be productive without being informed you run the risk of unknowingly making bad decisions. There is an exhortation to use frameworks so that if you aren't informed you at least get the guide rails / hand-holding / best practices that the framework imposes on you.
- efficax 10y agoThis is why I don't use Cocoa to write iPhone apps, or Swift, but ARM assembly. True carpentry! Jesus was a carpenter too, and God spoke the machine code of the universe.
- kyberias 10y agoThe usage of that Paul Graham quote is hilarious. The author misses the point entirely! Graham uses the word pattern to describe a repeated piece of code that matches a pattern. And it's a sign of trouble: a violation of the DRY principle. Nothing to do with design patterns really. Are all the other quotes used as unsuitable, we don't know.
- TeMPOraL 10y agoNo, the author does not miss the point - though I assume he may not understand it fully. The quote is written in context of Lisp macro facilities, which let you DRY your code from a lot of things, including GoF-style design patterns. So e.g. if you see yourself using "Memento pattern" (or whatever) in many places in your code, writing the same kind of methods doing the same thing everywhere, you should consider writing a macro that'll do that for you instead. That is, if your language lets you do that. Design patterns really start where the language's ability to abstract ends.
- kyberias 10y agoNo, I don't think so. That's not a critique towards design patterns. It's critique towards ANY CODE THAT IS REPEATED. If I use a certain design pattern once in my code, I didn't repeat anything. Macros don't remove the design pattern, they just allow me not to repeat myself.
- TeMPOraL 10y agoYou rarely use design patterns only once in a project. And while this quote does not cover it, you can also use macros to better communicate that one-off design pattern instance - instead of identifying a pattern by noticing a set of familiar methods or a typical inheritance graph, the person reading your code can just see the the macro invocation and know he's dealing with a particular design pattern here. Design patterns aren't bad per se, even if they imply some problems with language's capabilities to abstract - because they shift an abstraction from code to programmers' shared knowledge. The problem is with what I would call "design-pattern-driven development" - attempting to fit your problem into the bunch of design patterns you know. It's unfortunately very common.
- choult 10y agoIt's rather a shame that the author of this site has chosen to be anonymous; I should like to understand why they choose to reject a number of points generally considered best practice in software engineering, regardless of programming language: patterns; frameworks; library reuse; standards bodies etc. This unfortunately sounds like the cry of a programmer who has worked on their own for years suddenly encountering the requirements of working with a team of coders.
- justinhj 10y agoI feel like this could have been a tweet not a website
- spdionis 10y agoBetween composer and symfony and php 7 I would say PHP is ahead of both ruby and python communities in terms of code quality, perfomance and ease of deployment. There are some minor drawbacks in the core language, nothing compared to the python 2/3 split and all the virtualenv and packaging mess, and the sub-par arhitecture of rails (as far as i heard). Mind you this is limited to web development, php does not shine in any other field. People FTPing their code to a server or writing code in pure (probably sub-optimally designed) PHP beyond trivial scripts and web pages are not representative of the PHP community at all. At least not in europe.
- joesmo 10y agoAt over a dozen PHP jobs in over ten years, I've never seen a real application without a framework be anything but fucking garbage. Garbage. You know it's going to be garbage when some idiot tells you not to use a framework but is too fucking stupid to realize that if you don't use one, you have to write one yourself. Every single time. And PHP as a framework itself? Please. PHP is a horribly shitty framework itself for any app that's going to be more than a couple hundred lines of code. It's only with a proper framework on top that it becomes a proper web development platform (some may argue otherwise but their ignorance can be safely ignored). But I assume the author has never written anything more than a demo app, so yeah, if you're writing short scripts under 500 lines, don't use a framework. If you're writing real apps, don't listen to idiots like this author. This isn't PHP specific. There's nothing that makes PHP different from Ruby or Python. Appeals to PHP having been developed for the web are idiotic because while true, it's irrelevant due to the poor quality of PHP < 5 and especially PHP < 3. Yes, it was specifically developed for the web poorly and we've been fixing that ever since. If the author wants to use PHP 2 or 3 (or whatever the fuck they were called), that's one thing, but to pretend that coding in PHP 2/3 style is what makes proper apps these days is fucking insane.
- w3clan 10y agoWe don't have to reinvent the wheel everytime we create apps or any product using framework. Like imagine , When my every product needs login / register mechanism , i would look for something that is really fast, secure and may/may not have better approach of doing that. So, framework are basically to speed up work in same elegant way the others are doing.