6 ms·
PHP has a reputation as a language that makes dead easy to write very ugly sphagetti code. As far as I learned a lot has chaned since last time I was using PHP
by piokoch 13y ago
PHP has a reputation as a language that makes dead easy to write very ugly sphagetti code. As far as I learned a lot has chaned since last time I was using PHP - something like 5 years ago.
Is there any good book or other resource which describes modern PHP with best practices, parts to avoid, etc?
- fleitz 13y agoI'd recommend this for modern PHP: http://www.nodebeginner.org/ http://www.nodebeginner.org/ It's a great intro on how to write sphagetti code with out losing face.
- paraxisi 13y agoI've seen this around a few times, seems to be what you're looking for http://www.phptherightway.com http://www.phptherightway.com
- jbeja 13y agoI am reading "Apress Expert PHP and MySQL", the code is very releasable, it teach good practices about security and sql management, is more target to beginners and intermediate level programmers, but i really like how the author view and teaching skills.
- gedrap 13y ago>> PHP has a reputation as a language that makes dead easy to write very ugly sphagetti code. I believe that programmers ability to write poor code is quite language agnostic.
- gizmogwai 13y agoFrom my personal experience, I disagree. I have seen a greater percentage of poor codes in languages that a lower entry barrier than those that require more initial investment. Most poor coders I've met are lazy coders (in the wrong side of it).
- gedrap 13y agoYes, there are plenty of crap coders and agree with your argument but, again, it's not really the language's problem. Actually, I believe it's quite opposite. It's a side effect of success. PHP was suitable for new programmers because of how easy it is to deploy, learn. PHP3, the first version of PHP which was widespread, was released during the dot com bubble. When everyone and their mums was into Web. Everyone started writing tutorials, passing their shitty skill set. to new developers. Which produced more crap developers.
- wwweston 13y agoI'd agree that PHP really isn't that bad (at least, from the perspective of someone who started writing web apps using C, Perl, and Java). Some missing or clunky meta/higher level features feel limiting to me, but more or less it seems to be as successful as its other dynamic scripting siblings when it comes to tools devs have used to ship. The big problem with PHP is that it grew to popularity as it grew into a turing-complete templating language, and the major paradigm for it was more or less the idea that documents are programs. That actually encouraged mixture of logic and presentation concerns. There are some other warts possibly worth railing at, but that's really the main place it gets its probably deserved reputation for having more spaghetti code, even though pros working in have long since moved on from that paradigm. FWIW, this is also its strength: it's a very short distance with a gentle curve from authoring documents to authoring dynamic documents. I don't think anything else matches it. Of course, the curve from there to a larger application, that can be a different story, depending on what kind of guidance one has (and most likely, without guidance, ontology will recapitulate philology, as they say).
- mkramlich 13y agoIn my judgement, PHP best practice is #1 to never write anything new in it. And where it does already exist, #2 is to ideally write replacements (or do an incremental migration) in something else with a better overall balance of positive to negatives, that fits best, typically Python, Java, C or a sh.
- jtreminio 13y agoYour judgement kind of sucks.
- janson0 13y agoIf I were you, and I wanted to see how elegant and great PHP can be, I would just go check out and learn Laravel 4. I recently moved from CodeIgniter 2.x over to Laravel, and it was like breathing fresh new air at the top of a mountain. Everything is cutting edge, organized, and fun to code again. Sounds like hyperbole, but for real it reinvigorated my programming efforts. Check it out here: http://laravel.com/ http://laravel.com/
- xemoka 13y agoAnd if you're going the Laravel route (which I certainly recommend, I've used it a couple times here and there when PHP has been required), check out CodeBright by Dayle Rees (a Laravel core team member) on Leanpub (https://leanpub.com/codebright https://leanpub.com/codebright). It was the manual I needed to get going.
- sigzero 13y agoMy\Full\Classname Namespace convention sucks. That is all.
- umsm 13y agoLearn how to use the Symfony Framework: http://symfony.com/ http://symfony.com/ That is modern PHP done right.
- asciimo 13y agoI'm not sure that PHP done like Java is "right."
- krapp 13y agoI think the best answer, probably, is that modern PHP done right uses some kind of framework, or at least a PSR-0 autoloader, url routing, proper data security and some kind of templating to separate the logic from the view. It can (and has been) argued that PHP is itself a templating language and that the added abstraction of something like Twig is unnecessary... while that's technically true, scaling that gets you trainwrecks like Wordpress' API, where it's all but impossible to write plugins without mixing html in with the code. You also get nice things like macros, auto-escaping, and caching with a template engine, and you would probably end up having to reimplement a lot of that at some point anyway. Although what Laravel uses (blade) for templating looks pretty close to bare PHP, so there's plenty of room for minimal abstraction. But all of it is light-years ahead of the nightmare that is typical legacy PHP.
- dscrd 13y agoActually, Symfony seems like some kids went to basic OO design courses and took everything there seriously. It also causes the end product to be measurably the slowest in the world. http://www.techempower.com/benchmarks/ http://www.techempower.com/benchmarks/ I think this is the worst symptom: Sure, you can write snappy code that performs fast but when you try to reach a higher abstraction level, all those fundamental design failures catch up and make everything awkward and just bad.
- mikelbring 13y agoThe Laravel book by Taylor (creator of Laravel) is great for even non-Laravel users. https://leanpub.com/laravel https://leanpub.com/laravel