3 ms·
People who argue for PHP as a language always brings up this one argument: "PHP gets things done". Great. It get things done. Quick and dirty, but it gets thing
by josteink 14y ago
People who argue for PHP as a language always brings up this one argument: "PHP gets things done". Great. It get things done. Quick and dirty, but it gets things done.
That is all fine and dandy, but what when you need things done proper? How does it stack up then?
Oh. You mean you have to consider input-data as actual text, not as some byte-streams which incidentally maps to the same character-set you used to write your code with?
Oh. You mean I need to have locale-ware date, time and number-format handling?
Oh. You mean I need to actually validate these input-data and sanitize them for SQL injections and all that before sending off to the database?
Etc etc.
When you need things not just "done", but done proper, how well does PHP stack up then?
It is my opinion (as in opposed to fact) that when you add that one tiny, but oh so important clause, all arguments for PHP being the one language which gets things done falls apart.
Or am I being too simplistic?
- InclinedPlane 14y agoI'll play devil's advocate here. Define "proper"? Does meeting a business need, bringing in money, putting food on the table, and paying the rent mean "proper"? If not, why not? PHP has a plethora of flaws, but it's still a serious tool and used to build creations of significant value, that can't be ignored. As far as quality, what platform do you use to guarantee quality? I've heard many stories about terribly broken code bases in every language that's out there, from C to Ruby and Python to Java.
- josteink 14y agoBy "proper" I mean building a piece of software which has a clean and maintainable implementation, logical semantics, proper encapsulation, and last but not least, which is solid. That is, should be able to withstand real world challenges and input-data without crashing, failing, silently failing, creating corrupted data or any combination of those things. Granted, it's been quite a while since I've done PHP, and it that sense the initial point of the article stand true, but when I need something done in PHP, I always find myself spending more time ensuring basic truths which a proper language should guarantee for me are actually true, than I spend writing code doing something. I find PHP silently failing all the time making debugging code hard. And it makes it hard to do things proper, because you may have failure-modes which you should have been able to catch, but which PHP "kindly" shields you from. Hope that clears things up.
- InclinedPlane 14y agoRight. So by your definition there are no good platforms to write "proper" web applications in, since it takes a lot of special effort to avoid all of those problems in any language (ruby, python, c, c#, java, node.js).
- josteink 14y agoSome languages makes it easier, some make it hard. I would argue that PHP falls into the "hard" camp. And C would definitely be in the "very, very hard" camp. And then you have stricter languages like C# which makes doing things proper the default, although often at the expense of making other things harder. That said: This is definitely crossing the line between factual and subjective right now. And I can see how this is a subject open to discussion.
- dangrossman 14y agoHave you written a production app for PHP in the last 5 years? It handles (out of the box) multibyte encodings, locale-aware number and date formatting, parameterized prepared statements for your SQL, etc as well as most any language.
- josteink 14y agoI'll be intellectually honest and admit that, no, I haven't really touched PHP for anything near a production app in the last 5 years. But to be absolutely clear: before PHP used to be the only language I wielded for money. I have enough lines of PHP on my back to claim the right to an opinion. That said, last time I looked into PHP, modus operandi seemed to being focusing on making things easy, not making it easy to do things right. AFAIK this one quote from "PHP is a fractal of bad design" still holds true and that if you ignore all the other obvious things (wildly inconsistent BCL, etc), it is probably the core reason why I can never bring myself to like anything PHP: PHP is built to keep chugging along at all costs. When faced with either doing something nonsensical or aborting with an error, it will do something nonsensical. Anything is better than nothing. AFAIK that's still true, and I find it hard to have confidence in any code written on top of something based on that core tenet. Edit: Experience clarification
- xd 14y agoSo why did you comment in the first place, in what world do you find it expectable to berate something with no working knowledge? Also I have no trouble developing PHP code that halts on the first sniff of an error. But yes, with no experience of the language it will happily chug along.
- Seldaek 14y agoI think with the proper tools (and I don't mean using the bare language, but enough libraries that give you nicer abstractions), it can be used for doing things properly just fine. Heck we do a living out of building custom apps for customers that range from financial world to data-oriented startups. You just have to know what you are doing, like with any language really. - The mbstring ext gives you more or less decent transcoding support. I never had huge issues since it's generally ISO-8859-15 or UTF-8 I'm dealing with, but you may have a point. I can't answer conclusively. - date handling overall is really great in PHP, I don't know about it in details in every language, but I know in some it's a massive pain. See http://php.net/DateTime http://php.net/DateTime and http://php.net/manual/en/intldateformatter.format.php http://php.net/manual/en/intldateformatter.format.php for locale aware formatting. - SQL injection is handled by the PDO db connectors just fine, and all libraries abstracting this basically take care of it. Unless you follow 10 years old tutorials it's pretty hard to have SQL injection leaks. Etc etc. The key is just this: know your tools.
- debacle 14y agoYou're being some what ignorant. Modern PHP platforms support locales, utf8, and SQL injection prevention out of the box, and the libraries to do so are vast, varied, and decoupled.