Live data from Hacker News

PHP: A fractal of bad design

me.veekun.com

261–270 of 514 posts

Re: PHP: A fractal of bad design

#261

Earlier quoted context omitted.

Until people stop using PHP I welcome detailed critiques of the language. There are still enough PHP apologists out there that we can use all the ammunition we can get.

Why do you care so much about what other people use to get a job done? Care about what you use.

1. It reflects poorly on my profession as a whole if practitioners are too lazy to fix or abandon obviously broken methodologies.

2. It's symptomatic of a general "good enough" mentality that makes software development much more difficult than it needs to be.

3. It breeds bad habits in novice developers that are likely to be my colleagues one day.

4. It steals mindshare and time that might much better be spent improving better alternatives.

5. It provides LAMP detractors with ammunition to shoot at the entire open source web stack.

6. I may one day have a half-assed PHP mess dumped in my lap to clean up.

Re: PHP: A fractal of bad design

#262
post #96

Earlier quoted context omitted.

Does warts-and-all PHP include that eval wart, or is it more like most-warts-and-a-subset-of-all PHP ? Not snarky, just curious if there was something I missed.

What is the problem with eval? Even Python lets you do that. There are legitimate uses for it.

For some reason, I can't reply to colanderman's comment above/below, but Python's namedtuple is implemented using eval (technically it uses exec, but it's the same idea in Python).

Re: PHP: A fractal of bad design

#263

All those words, and yet the word template only appears once. And that's to assert that PHP has: …no template system. There’s PHP itself, but nothing that acts as a big interpolator rather than a program. As if that was a bug and not a feature. PHP succeeds because there is one PHP templating syntax and it is called "PHP" . PHP started life as a templating language, and that's where its soul lies. Which is important,…

It is so easy to write a fully functional php templating engine too. Here is a quik and dirty example (without error checking etc/ the php way i kid :)

http://pastie.org/3761953

Re: PHP: A fractal of bad design

#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 just means it is request-scoped (ignoring $_SESSION, which is explicit anyway).

Do people complain about request-scoped data in any other language? No. The PHP haters just decide to hate this largely due to the (somewhat incorrect) label of "global".

> There is no threading support whatsoever.

That's a good thing. It forces you to use async HTTP programming or something like beanstalk, both of which are better than the complexity of threading.

> array_search, strpos, and similar functions return 0 if they find the needle at position zero, but false if they don’t find it at all.

So, it's a problem that array_search returns 0 when something is at... position 0? And returning false is just a sentinel value, much like functions in other languages might return -1. So what?

> In, say, Python, the equivalent .index methods will raise an exception if the item isn’t found.

I, for one, hate throwing an exception when an item isn't found. This sucks:

    try:
      index = a_list.index(a_value)
    except ValueError:
      # do something
- If you use FALSE as an index, or do much of anything with it except compare with ===, PHP will silently convert it to 0 for you

Yes, you have to use --- and basically understand that otherwise 0 == false. So what? In C/C++ you also have to remember to use == not -.

> [] cannot slice; it only retrieves individual elements.

Much like Java/C/C++. PHP has array_slice() if you want it.

It's since been redacted but the OP originally claimed that Facebook doesn't really use PHP (because, hey, that fits his world view).

Look, I could go on but really what's the point? Haters gonna hate.

Sure it would've been nice if PHP had been consistent with, say, parameter ordering (needle, haystack vs haystack, needle) and function naming (sometimes using underscore, sometimes not) but really none of that matters. If you use it, you soon remember. Humans are built to understand inconsistent languages. If we weren't, we wouldn't be able to speak to each other.

Some like to argue that PHP is a beginner's language. I disagree. I think PHP is a fine language for just throwing something together... if you know what you're doing. Otherwise it's just a recipe for SQL injection and XSS vulnerabilities.

A common mistake with PHP is people try and turn it into Java with complicated object frameworks. There is typically lots of hand-wringing about OO'ness.

The procedural style is actually very natural for serving HTTP requests. The core of PHP is a stateless core of API functions. This is incredibly useful for keeping resource usage down. Much like the old CGI model, the entire environment is created, used and destroyed on each request.

This is a feature not a problem. Anyone who has done Java Web development (with stateful servlets or any derivative) should know this as it is virtually impossible not to have come across resource leakage and concurrency issues at some point. The stateful model, while useful, has a significant cost.

I really don't understand this need to complain so vocally about something like this. Possible reasons:

- It affirms the OP's sense of superiority somehow;

- It's about "street cred" with [Python, Ruby, Node.js, insert other language here]; or

- One is so obsessed with "purity" that one spends all one's time complaining about how everything isn't Lisp.

Use it or not. I don't care. If you're not going to use it, why complain about it? If you are using it, what does the public snobbery (which is really adding nothing new to all the other PHP rants) really add?

I'm a big fan of pragmatism and the fact is that 4/20 of the most visited sites on the Internet are written in PHP.

EDIT: /sigh/ I get the inevitable "you must be a PHP programmer" retort (like that's actually a retort and not just more snobbery). For the record, I've only used PHP for ~6 months. My main experience is Java (~14 years), Python (~2 years), C (~5 years) and C++ (~4 years).

Re: PHP: A fractal of bad design

#265

All those words, and yet the word template only appears once. And that's to assert that PHP has: …no template system. There’s PHP itself, but nothing that acts as a big interpolator rather than a program. As if that was a bug and not a feature. PHP succeeds because there is one PHP templating syntax and it is called "PHP" . PHP started life as a templating language, and that's where its soul lies. Which is important,…

Yeah, but what drives programmers nuts is that most of the problems in the language are totally independent of that ease of accessibility. Is there something about consistent naming, or consistent behavior of different library functions, or consistent syntax and operators -- they can be lenient and type-coercing, but consistent, like Javascript's -- that would make it a worse language for people to wade into in the f…

How could I disagree? PHP is crazy.

But these irritations are only apparent once you're inside the PHP conversion funnel. And, as I have observed time and again as a pro PHP developer, once a PHP programmer knows ten lines worth of PHP it is easier for them to struggle through the eleventh line than to start over with another system.

The entrance to the funnel matters, a lot! Everyone passes through it, and the bulk of your user base will never even leave it. That's my theory of PHP's apparently inexplicable success. (It also explains a lot about every other platform's userbase, by the way.)

And it's not as if one can't master PHP to the point that one could build, say, Facebook: It's empirically evident that one can build Facebook, WordPress, and Drupal in PHP. And, though PHP eventually turns into one gotcha after another - almost immediately, actually; the array() semantics are an absolute horror show - at every single step of the PHP experience there are ten people stuck on that step along with you, and you're all being coaxed ahead live, on the internet by the ten people who are stuck one step above you. So it eventually works out, at least as well as any good hack does, and trying to pretend otherwise doesn't fool anyone. You can try to tell people that PHP can't possibly fly, like the scientists in the urban legend who allegedly tried to claim that the bumblebee can't fly, and they'll smile at you and go back to struggling with PHP.

The question implicit in your comment is: Could we design a system that offers the ease of accessibility of the first few steps of a PHP programmer's career but, as one climbs the learning curve, eventually blossoms into Python or Ruby or even Lisp? I wish I knew. My best guess as of this morning is that a demigod could design such a system, but it's very difficult for mortal humans to do so, because once you know how to program it's hard to avoid overdesigning, putting in things that will eventually be useful in year two but are discouraging in year zero. We make terrible pedagogical mistakes, like turning everything into an object. (Does your ORM seem intuitive to you? That is why PHP is beating your system in the marketplace.)

Re: PHP: A fractal of bad design

#266
post #246

Earlier quoted context omitted.

> Where's the Ruby version of this? The Python version? The JavaScript version? heroku ? you don't even have to upload anything manually, a single command deploys your app.

That's not the same level of beginner friendly. With PHP, you have a file with a .php file suffix on your server. That file has code in it. Navigate to that file on your browser. You have a dynamic website. No installation of external programs is necessary. No terminal. Often, you don't even need an FTP client, since you can use your hosting provider's GUI. That blinding level of simplicity gets the non-programmer st…

Sadly you are right. Ruby has no equivalent and Rails especially is not for beginners.

Re: PHP: A fractal of bad design

#267

All those words, and yet the word template only appears once. And that's to assert that PHP has: …no template system. There’s PHP itself, but nothing that acts as a big interpolator rather than a program. As if that was a bug and not a feature. PHP succeeds because there is one PHP templating syntax and it is called "PHP" . PHP started life as a templating language, and that's where its soul lies. Which is important,…

PHP is not a good tool for quickly getting a minimum viable product. Despite its flaws it is a good weapon for fighting 'the last war' - that is to say, it makes it quick and easy to make what are essentially the CGI pages of 1996 - but if you're doing anything more complex than that (for instance interacting in any way with a database), and I would suggest that even relatively non-technical people looking to use com…

What would you recommend as a starting language to build a MVP? The extent of my experience is html/css, manipulating wordpress php files, and a weekend hacking together a couple of learning projects (a PHP blogging platform and a "rank this list of items by number of upvotes/this number" website).

Given my past experience I was planning to use PHP as it is the only language I have any experience with and while the functionality I'm shooting for is totally different, I don't envision it being any more difficult to code than the blogging platform. I will be interacting with a database.

Are the other options as easy to pick up as PHP? Is it as easy to google for help?

Re: PHP: A fractal of bad design

#268
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…

> There is no threading support whatsoever. >> That's a good thing. It forces you to use async HTTP programming or something like beanstalk, both of which are better than the complexity of threading.

While there isn't multi-threading in PHP, you can in fact multi-process which provides similar functionality.

http://php.net/manual/en/function.pcntl-fork.php

Re: PHP: A fractal of bad design

#269
post #137

Earlier quoted context omitted.

Agreed. While PHP apps are definitely more likely than others to be vulnerable to systemic SQL injection, XSS, and other vuln classes of that sort, all applications are equally vulnerable to things like command injection, authorization bugs, etc. No one gets that stuff right, and if you can execute code on the system, well, it doesn't really matter if you can't find SQLi.

Why is PHP more likely than others to be vulnerable to SQL injection attacks? Most people (and likely All newbies) will be using PDO which automatically protects them.

This is why:

http://www.google.com/search?q=php+mysql

Searching for PHP and MySQL yields tons of tutorials, code examples, and documentation related to the now-deprecated mysql interface. When I wrote my first comprehensive PHP application last year I spent half a day trying to determine best practices before finally settling on PDO. Newbies won't go through that effort, and will naively land on mysql rather than PDO or mysqli as likely as not.

Re: PHP: A fractal of bad design

#270
post #19

"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)" I'm a Facebook engineer who works on the HipHop compiler and HipHop virtual machine. It's in PHP, absolutely full stop. It's amazing how much the fact that g++ is involved somewhere in the toolchain confuses people in this matter. C++ is just an intermediate representation; the source language r…

I find it to be an interesting philosophical question about what defines a language. If you write code in Java, but compile it to native format (using gcj, for instance) instead of using the JVM, is it still Java? In doing so, you lose what is probably the language's biggest selling feature. Or, perhaps less relevant now, but I remember the days where people would go on about how Ruby didn't support native threads. E…

The problem is that most people lack the proper compiler development background when discussing languages.

Most people without a proper CS background mix the language with the implementation.

A language is defined by:

- syntax

- semantics

- libraries

Everything above can be made available as:

- bytecode interpreter

- text parser based interpreter (like the earlier BASICs)

- compiler

- JIT

That is why it is absurd to discuss language A vs language B in regard to implementations, because any language can have all types of implementations.

It is always a matter of cost/benefit which type of implementation is used as default for a given language.

Post reply on HN