Live data from Hacker News

PHP: A fractal of bad design

me.veekun.com

381–390 of 514 posts

Re: PHP: A fractal of bad design

#381
post #264

If this one thing that annoys me on HN it's the pervasive anti-PHP snobbery. A selection from the OP: > Because of the @, the warning about the non-existent file won’t be printed. So your complaint is that when you use @ to suppress an error it... suppresses the error? > The language is full of global and implicit state. "Global" is one of those dogmatic points. Nothing is truly "global" in PHP. The "global" in PHP j…

It isn't just snobbery (though I'm not denying that there's going to be an element of that in the comments, languages make people get religious and weird). Being called in to do maintenance on a php project sends a stab of dread through the heart of an experienced programmer and it's worth understanding why. This article goes a long way towards doing so.

It's important to re-iterate what the article is NOT saying. It's not saying that you can't do awesome work in php, there's tons of great counterexamples. It's not saying that you can't change the world with php. It's not even saying that you can't write a maintainable, legible, beautiful app with php.

The problem with php is that the core language ignores a ton of what we as a community have learned about language design: Be consistent. Make it easy to do the right thing. Make unwise code look awkward. Pick a type system and embrace it. Don't try to magically do the right thing. Be predictable. Avoid action at a distance.

It's not that PHP makes for a great beginner language. So does Python. It's not that PHP has flaws, so does every language. Many darlings of the Hacker News crowd even have some of the flaws from this list. But I'd challenge you to make a list a quarter of the size of this one with Python, or Haskell, or frankly even Javascript.

Re: PHP: A fractal of bad design

#382

Earlier quoted context omitted.

I've done quite a bit of PHP development, a lot of more advanced stuff (Earlier in this topic I linked to a PHP Daemon library of mine on Github). But PHP has either missing or NOTORIOUSLY inferior Memcached/Redis/Mongo/Cassandra/HBase/Riak/etc clients. They get the job done, but they underperform, say, Python or Java versions in benchmarks and introduce far more bugs and quirks than I've experienced in other languag…

I haven't used a PHP nosql client library at serious scale so I will bow to your better experience (although in the case of Redis clients, some links would be nice as I wasn't aware that the two major PHP clients had any performance/reliability problems - I'm very surprised that https://github.com/nicolasff/phpredis under performs given it's a C extension). Having said all of that, if you are building a site that use…

I may have been making that up re: redis, honestly. It's guilty by association in my mind, but I've used redis in PHP a lot without any first hand problems.

But Memcached, certainly (and even doubly so for the `Memcache` extension that ill-informed developers install instead of the better `Memcached`), and the others listed, either are slower/etc or just don't exist.

Re: PHP: A fractal of bad design

#383

Earlier quoted context omitted.

I haven't used a PHP nosql client library at serious scale so I will bow to your better experience (although in the case of Redis clients, some links would be nice as I wasn't aware that the two major PHP clients had any performance/reliability problems - I'm very surprised that https://github.com/nicolasff/phpredis under performs given it's a C extension). Having said all of that, if you are building a site that use…

I may have been making that up re: redis, honestly. It's guilty by association in my mind, but I've used redis in PHP a lot without any first hand problems. But Memcached, certainly (and even doubly so for the `Memcache` extension that ill-informed developers install instead of the better `Memcached`), and the others listed, either are slower/etc or just don't exist.

Fair enough, I'm sure you're right with some of the other lesser used libraries e.g. Riak. It's probably fair to say it takes PHP longer in general to get a good client library than say Python. Not sure about Ruby.

Re: PHP: A fractal of bad design

#384
post #346

Earlier quoted context omitted.

Oh, you mean as opposed to the usefulness of calling people snobs because they understand that PHP is terribly designed? Fuck outta here.

You don't like it? Don't use it. You're the kind of asshole that'll walk up to somebody in McDonalds and tell them that the food they're eating isn't healthy. You know what? Mind your own business.

No, this is more like writing a long, well reasoned, extensively researched article with the thesis "McDonalds food is unhealthy". It is a public good.

No one in this comment section is saying to you "stop using php on this project you're doing because it's badly designed". No one is in your business.

Re: PHP: A fractal of bad design

#385

I regularly, (all over this thread), see people swear that PHP is great for beginners. Everything in this article seems to indicate the opposite. You have to trip over PHP's poor design while trying to learn to program. Outside of the wide availability of PHP servers for cheap, what makes PHP so great for beginners? With Ruby, Python, Go, hell, even JSP for the "instant", in-HTML effect, I just don't see PHP as some…

I've been coding PHP for years and am just starting to learn Ruby on Rails. I'm not a programming expert at all, and so most of the objections mentioned would take me a while to parse. From my perspective, Ruby on Rails is really, really difficult so far. You have to learn to use the terminal (which I've seen other people in my position use to totally mess up their computers); to make a simple application you're alre…

Agreed, rails is hard. Personally I prefer Sinatra and Ramaze since they are much simpler to understand.

Re: PHP: A fractal of bad design

#386
post #293

Earlier quoted context omitted.

> So your complaint is that when you use @ to suppress an error it... suppresses the error? From your edit, you've only been working with PHP for about 6 months, so you may not have seen some of the code most others have. Can you imagine, then, diving into a website's back-end to see @ all over? It turns out, the previous developer realized all those nasty notices and errors stopped happening if he slapped a @ on eve…

> Can you imagine, then, diving into a website's back-end to see @ all over? It turns out, the previous developer realized all those nasty notices and errors stopped happening if he slapped a @ on everything. You've turned something that's a person's fault into something that's the language's fault. Other languages have some sort of warning suppression as well, like Java's @SuppressWarnings or C#'s #pragma warning di…

> Other languages have some sort of warning suppression as well

But there is a huge difference here. PHP directly encourages it, making it so easy to do "just prefix it with @" and dedicating a part of the core language syntax to it (thus spending such a nice character for such a triviality). I believe (correct me if I'm wrong) that in Java, it is just another annotation, and in C# just another preprocessor directive.

And I think that's what the article is about - so many things are wrong in the very foundation of the language.

Re: PHP: A fractal of bad design

#387
post #298

Earlier quoted context omitted.

I agree with the general point but this seems more of an indictment of other languages than a plus for PHP: with PHP, it's easy to get started with the most simple features - and then it takes years to learn how to cope with the language quirks and inconsistencies, deal with outright bugs, and learn a number of non-obvious ways in which your “working” site might be hacked due to a hidden language feature. There are t…

Yes, that would be great. An alternative intro would be most welcome. It should, though: - Be able to start and serve in minutes, across most platforms - Allow for portable code e.g. the code you create locally should be able to be ported over to an actual webhost with only [S]FTP. - Not require the command line to "work". At all. I tried to learn django ~a year ago, and it was an experience wrought with frustration…

I would add low cost to that list.

HN's fascination with cloud computing and massive scalability is not representative of web dev in the rest of the boring world. The vast majority of web sites out there are powered by shared hosting, where the norm is to cram 1,000 sites on a cPanel server. Apache+PHP makes economic sense in this environment because when your site isn't getting any requests, it uses no resources. But if everybody started running a persistent Django or Rails process in the background, or if every customer had to be given a VPS, hardware and maintenance requirements would quickly exceed what the provider can profitably offer.

I can host a small website on NearlyFreeSpeech for $0.30 per month plus bandwidth, even less before they introduced a surcharge for dynamic websites. One of my old clients is hosted on another pay-as-you-go shared host, where she incurs all-inclusive charges of $0.07 per month on average. (The site is mostly static, with a PHP guestbook.) Like it or not, PHP makes this possible by folding the app server into the web server, and a lot of effort has gone into making such an environment reasonably secure without blowing up resource requirements. Even if you use a regular shared host that charges $8.95 per month, that's still cheaper than a medium-quality managed VPS.

The current state of shared hosting might not be anything to write home about, but the low cost (compared to a VPS) allows anybody, including dirt poor students, to run a web site without being held hostage to a less customizable service that might or might not exist tomorrow, e.g. Posterous. I think this contributes to technical literacy and independence in a small but unique way. Any realistic alternative to PHP had better meet the same requirements.

Re: PHP: A fractal of bad design

#388
post #362

Earlier quoted context omitted.

> Can you imagine, then, diving into a website's back-end to see @ all over? It turns out, the previous developer realized all those nasty notices and errors stopped happening if he slapped a @ on everything. You've turned something that's a person's fault into something that's the language's fault. Other languages have some sort of warning suppression as well, like Java's @SuppressWarnings or C#'s #pragma warning di…

> You've turned something that's a person's fault into something that's the language's fault. > You're taking a look at other people's code, and judging the language from it. At some point, you have to start blaming the language for fostering an environment where that code is acceptable.

You can write bad code in any language. It's the programmers responsibility to make sure the stuff they are writing is good and that only comes from experience with the language.

Re: PHP: A fractal of bad design

#389
post #361
post #344

Earlier quoted context omitted.

> have error reporting turned off (which you should) No, you should not. You should never have error reporting turned off. You should certainly have it set to not display errors to the client, but all errors should be sent to a log, preferably syslog, and they should be reviewed. Your code shouldn't generate any errors.

"You should never have error reporting turned of" Sorry bro, if you have ever put code on production with error reporting on...you are doing it wrong.

He specifically mentioned you should have errors logged instead, not displayed to the client. You're quoting only the part that leads to your insult.

Re: PHP: A fractal of bad design

#390
post #354

Earlier quoted context omitted.

Convincing people to stop using such a flawed language when there are so many viable (and in nearly all ways preferable) alternatives.

Obviously, since millions of people are using it it is preferable for them. Of course, this is only because they are too stupid to agree with you and have the exactly the same criteria and preferences that you have. It can't be that intelligent people can disagree with you on what is important and what is not in a language. It's clearly either you didn't explain it to them or they're too stupid to understand. Let's w…

> It can't be that intelligent people can disagree with you on what is important and what is not in a language.

This is quite harsh sarcasm, but if it isn't true for the GP, it's true for so many people. Well said.

Post reply on HN