TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Stack Overflow: Defend PHP - convince me it isn't horrible

40 pointsby Chiragalmost 15 years ago

21 comments

weegoalmost 15 years ago
These topics always just smell of "Now I'm a grown up programmer I'm going to tell the world how much I understand by slamming an easy target language".<p>I love PHP and have used it for years since moving away from asp.net and agree with some of the posters arguments as a theoretical principle, but as day-to-day PHP developer I also say so what. Naming and parameter inconsistencies? Yes, my libraries have that too and I can at least learn the PHP ones with some experiernce. I don't know any asp.net developer that doesn't have to use some kind of tool to help them find where System.Obscure.FoundItOnline.Function exists in the monster .net namespace system. It allows me to be productive and allows me to be the gatekeeper of how well or poorly I implement things. This is a crucial point of the constant argument about poor PHP logic/presentation support for me, I can happily write mixed and messy code for a £500 job or I can write some clever system that implements caching and output buffer manipulation and have a great template system.<p>There are far too many people spending far too much time thinking that academic level programming considerations are applicable in every detail to every day programming practices of web developers.
评论 #1514612 未加载
pilifalmost 15 years ago
I'm spending most of my time maintaining a web application consisting of around 150k lines of PHP code. We (well - initially, it was just me) began development back in 2004 but since then the application has grown constantly.<p>Back in 04, I already felt some reservations against PHP, but that's what I knew best and that's what was most used for the web (Rails might have been around, but not really known - other ruby options were not quite there yet. Python I disliked and Java I. don't. touch.).<p>The application was written in PHP5, initially developed on some RC of 5.0.0 and I was careful to keep a clean style and not using deprecated code.<p>This lead to a quite clean application that I could really be proud of. And still: While it has suffered from sometimes not quite reasonable customer demands, it's still very good at what it's doing and while there might be some dead bodies rotting in the code, it's nowhere near daily WTF material (aside of some bugs we have a good laugh at and fix shamefully).<p>Still. I have some bad gripes with PHP that made me stop doing anything new in that language.<p>I can easily live with the usually quoted problems though:<p>- parameter order in library function? I don't care - my IDE lists them.<p>- Huge base library? I don't care as the stuff I don't need doesn't cost me anything but disk space and the stuff I do need, I'm glad is there.<p>- No namespaces? Yeah. Bit me a couple of times, but I can work around that - besides, with 5.3 we got namespaces, so this doesn't count any more<p>- Performance issues? It's fast enough for said application.<p>- Security? It's just as secure as any other language you can write insecure code in (i.e. all of them).<p>- Allows intermixing of layout and code? Sure, but you don't have to. If you have <i>any</i> sense what so ever, all requests go through a central /index.php and all other code is in some not-publicly accessible location and emits no html what so ever. All output is generated using any of the thousands of templating libraries.<p>What really disturbs me about PHP is its type conversion rules. 1 == '1' or even worse 'foobar' == 0, or '123n' == 123. This is cause for so many subtle bugs.<p>Just use === you tell me? Sure, but then you clutter your code with an insane amount of isset()'s and isint()'s and whatnot - the fact that the database library I'm using (pgsql) returns everything as strings doesn't help that cause either.<p>The other thing is the really clumsy syntax. Array literals, anonymous functions, closures (with explicit declaration of all variables of the outer scope you want access to), operators, even just the lack of named function parameters. The syntax is clumsy and all the elegant code you see even from JavaScript just gets bloated and unreadable once you port it to PHP.<p>These two issues made me do stuff in Ruby, Python(3) and lately a lot of Node.js, but the maintenance of that huge application remains to be the main part of my day-job and even though the two issues really bug me, it's still not painful enough to really be complaining (or, heaven forbid, port the thing to whatever-other-language-thats-currently-hip).<p>So in retrospect, while I'm as die-hard a PHP user as you can get with many, many lines of PHP under my belt and while I do find some of the stuff highly enjoyable (php's arrays that are also ordered hashes for example. Or the really easy and accessible web-server/HTTP integration), I also dislike it quite a bit to the point of being unwilling to start something new in PHP.
评论 #1514538 未加载
评论 #1515046 未加载
terra_talmost 15 years ago
The real advantage of PHP is deploy-ability.<p>If you choose mod_perl, mod_python, JSP, or most of the classic environments you need a sysadmin to take care of the web server... It's going to crash from time to time, run out of memory, and otherwise make trouble for you.<p>PHP's mode of integration with the prefork Apache web server is almost trouble-free... It's such a big difference that there could be a "blub" factor here... People who program in other environments often have a really hard time believing that a large fraction of the sysadmin activities that they are doing just don't need to be done if you're running PHP. (You can go five years and never "kick Tomcat", something that some shops have to do every 5 hours).<p>That said, scaling comes to play here. For a small company or for a company that's doing a number of small projects, the cost of system administration that comes with other programming environment matters a lot more than it does for a big company. It's not such a big factor for a company like Facebook.<p>On the other hand, PHP forces people into a "shared nothing" model that scales well and ~eliminates~ a wide range of concurrency-related problems that are endemic to thread-based backend apps. For instance, quite often I've seen a race condition in an ASP.NET app and had everybody on the team swear up and down that there's no shared state, then I spend a few hours looking at the app and there's a static variable that nobody knew was there.<p>Another strength of PHP is that it has a very complete library that's largely correct. The PHP team is much more honest about what works and what doesn't work than a lot of others (PHP and Python have the same problem with threads, for the same reason -- PHP says "don't use them", Python says "jump in the water is fine".) If you program in some weird-o language like Haskell you'll probably have to write your own urldecode function and you'll probably be so busy thinking about higher-order functions you won't pay attention to details... Like making it work right. (Perl has a broken urldecode function in CPAN FOREVER)<p>Don't get me wrong, there's plenty to hate about PHP; but try to get some real work done in environment X and you'll find plenty to hate too.
brlewisalmost 15 years ago
I'm not a PHP advocate, but I'll take this one:<p><i>PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.</i><p>The ideal web application is the one that best fits the unique characteristics of the data being manipulated. When exploring how a web app should work, you <i>should</i> be thinking at all levels: view, controller, model. A framework that forces you to separate all three from the start is a bad framework. It pushes you toward generic data manipulation forms and reports. If those generic tools are the best ones for the data model being manipulated, why involve a programmer at all?<p>We would have much more interesting and varied web applications out there if the prevailing "wisdom" of MVC would die.
评论 #1514328 未加载
评论 #1514502 未加载
pierrefaralmost 15 years ago
I think this is the wrong approach. The guy should try to convince me that PHP is bad. That PHP has never not did what I wanted it to do. That I need to invest time and switch to some other language because it's better for my needs and purposes, and the switch will quickly get me to a level of expertise that I have with PHP now.<p>The fact of the matter is PHP is ugly and that's really it. I can live with ugly because I know it and it does everything I've ever asked it to.<p>Frankly, it's no different than me switching from English because it has quirks.
评论 #1514521 未加载
byoung2almost 15 years ago
This debate reminds me a lot about another debate about language. When I studied English in college, I occasionally came across papers enumerating the weaknesses of the English language. It's terrible for writing poetry, because you can't rhyme like you can with Italian or seduce like you can with French. It's difficult to learn, because of irregularities in spelling and pronunciation.<p>Now that I'm a PHP developer, the response I give when people ask me why I use PHP and not a "real language" is the same one I would give if someone asked me why I speak English. There are more people who speak my language. If I travel to a remote fishing village in China, chances are I can find one person who speaks English. Try to find someone who speaks Italian. When I'm working on a web project, I know that if I write it in PHP I can find hundreds of developers to hire at a reasonable price versus hunting around for Ruby developers (who cost double).<p>At my day job, we run 200 websites, and 194 of them are written in PHP (1 is Java, 2 are .NET, 1 Ruby, 2 Coldfusion). When the company buys sites, the first step is converting them to PHP (if they aren't already), just so future maintenance is easy and cheap.
DrJokepualmost 15 years ago
To be honest I don't think case insensitivity is really that much of an issue. Common Lisp is case insensitive as well and I have never had any problems with that.
评论 #1514393 未加载
Goladusalmost 15 years ago
Actually, I think the depreciation point is one of the better points. Yeah, sometimes clean up is necessary, but when a language is a moving target like that, it raises serious concerns about portability and long term maintenance.
评论 #1514322 未加载
delanoalmost 15 years ago
No one ought to convince anyone of anything.<p>Use it yourself and keep using it for as long as you like it. When you stop liking it, stop using it.<p>That doubles as a recipe for learning any new thing.
billpgalmost 15 years ago
I wish I could ignore PHP, but it's just so darn ubiquitous. Most webhosts priced within the means of "normal" people have PHP, while far superior (IMO) platforms like ASP.NET are the exception. Until webhosts can be convinced to support a wider range of platforms, I fear humanity will never be freed of the bonds of PHP.<p>Bill, hates PHP with the heat of a thousand suns.
steverbalmost 15 years ago
Personally, my distaste for PHP centers around the fact that there are so many developers pumping out crappy PHP code for $20 / hr.<p>I don't need to compete in a race to the bottom.
Yaggoalmost 15 years ago
From a programming language perspective, PHP is somewhat horrible (PHP 5.3 less so, but still). I guess nobody will deny that. But from practical perspective, PHP is very suitable tool for many tasks and has huge ecosystem behind it. Complex real-world websites and applications have been successfully built with PHP. Isn't that proof enough?<p>Do you consider yourself a purist or pragmatic? In the latter case, PHP may be worth dating for a while.
评论 #1514429 未加载
slantyyzalmost 15 years ago
It's a little pointless to defend PHP to someone who thinks it's horrible.<p>That's like asking someone to defend a religion. A waste of time and energy.<p>In a good programmer's hands, the results will be good, regardless of language or platform choice.<p>Sure, you can argue the finer points until you're blue in the face, but in the end, the only thing that should matter to your "customer" is that the solution satisfies his/her needs.
jamesmontalvo3almost 15 years ago
I'm wondering, as a fairly inexperience programmer with most of my time in PHP: is there any good reference for "How to start web development in ___ with previous experience only in PHP". I would love a tutorial that explained how to accomplish in another language all the things that PHP makes simple for newbies. I'd also be totally willing to help an experience person develop such a tutorial.
bufordtwainalmost 15 years ago
"There are more useful systems developed in languages deemed awful than in languages praised for being beautiful--many more." -Bjarne Stroustrup
hsarvellalmost 15 years ago
PHP is great if you need to get some small thing up and running yesterday. PHP is also great if an out of the box solution will almost fit the bill due to the fact that there are so many. Just take a box and do some small modifications, voila, done!
评论 #1514333 未加载
评论 #1514349 未加载
noodlealmost 15 years ago
php is a tool. it has its benefits and its drawbacks. you shouldn't have to "defend" the language itself, but you should be able to defend your choice of language. if you don't like a language, go use another one.
snorkelalmost 15 years ago
Facebook and Wikipedia.
hackermomalmost 15 years ago
PHP may be one weird concoction, that's for sure, but all of the arguments brought up by this guy - and this is the exact same boring song belched out whenever there's an argument of "PHP is a terrible language" - fall into the category of vanity, because no matter how one twists and turns these points they still really don't make the language itself terrible, and they don't make PHP one bit less capable, nor one bit less adequate for the supposed job.
评论 #1514825 未加载
ndimopoulosalmost 15 years ago
To answer to the topic of the post - why should I (or anyone else for that matter) bother trying to convince the author that PHP isn't horrible.<p>If the author does not think that PHP is suited for his/her needs then he/she should not use it. There is a plethora of programming languages out there - pick and choose.<p>The post has a disconnect between the title and the content. The author does not want to use PHP and tries to outline the flaws in the language from his/her own view. Sorry to disappoint, but I disagree with those points. I use PHP amongst other programming languages and I use it only when it suits my needs and the needs of my project. It is not perfect but then again nothing is.<p>Final thought for the article would be a paraphrase of its title as a reply:<p>Defend 'behaviour'. Convince me it isn't spelled horribly - correct spelling 'behavior'.<p>I think you get the point :)
评论 #1514460 未加载
sandGorgonalmost 15 years ago
Drupal, Joomla, Wordpress, phpbb, vbulletin, invision power board:: Together they are 99% of online communities + personal websites. If you want to use any of them. Then it is php.<p>I may not particularly like PHP, but to deliver projects in reasonable time, you may have to leverage PHP