News for hackers. Stuff that matters.
Re:PHP: A fractal of bad design by mechanical_fish on Tuesday April 10, 2012 @03:10AM (#3821125)
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, because if a non-programmer wants to start editing dynamic HTML pages, most likely the first thing they open in their text editor will be a template. And if a customer wants to change the website, but doesn't want to pay a highly-trained programmer (we're very expensive, especially because none of us really wants to be paid to edit templates all day), they'll hire someone who knows how to edit the theme. For every seasoned programmer in the world, there are half a dozen themers who know how to edit HTML and CSS, and maybe how to embed a "foreach" loop that calls a stock WordPress function, or edit an argument list, or swap one Drupal function name for another. And for every themer there's a dozen non-programmers who dream of knowing enough to be themers.

This class of user is what every other platform tends to neglect. Ruby and Python programmers tend to design tools that are intuitive to other programmers. We build "frameworks", where one must tinker and monkey-patch and fork to such a degree that only another programmer can download and assemble a working system, let alone customize it. (One word: Gemfiles.) We write programmer-centric documentation filled with jargon terms from Javaschool, like "object". (PHP themers often do not understand OO, and often don't need to. This, all by itself, could be why PHP is so popular.) But one leaves a lot of money on the table when one designs software systems exclusively for users whose programming education entitles them to six-figure salaries. There aren't enough such people on earth; that's why they earn six-figure salaries.

Designing the minimum viable product for borderline-non-programmers who want to tinker with dynamic web pages is hard work, though. PHP evolved into that niche, but if you don't start there it's hard to steer there deliberately. For me, trying to remember when object inheritance and version control and function definitions were mysterious is like trying to remember when I didn't understand algebra. (And, believe me, I really didn't understand, once. But I'll be damned if I can remember why not.) It's so hard to keep one's eye on that ball that even the PHP developers lost the plot long ago: PHP has long since bulked up with features borrowed from other languages. But if you ignore its newer features the soul of PHP is still a little templating language that you can edit into the HTML on your server; change a filename extension and reload and you're good to go. And, the thing is: You can write a crazy-complicated core system in PHP, but then expose it as an API at the template layer, and those tinkerers hacking at the HTML on their servers will be able to use it.

Re:PHP: A fractal of bad design by mquander on Tuesday April 10, 2012 @03:37AM (#3821199)
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 form of templated HTML? Of course not. That's what irritates people, the endless parade of bad design decisions that appear totally bad, with no upside, where they could have just as easily made a good decision and didn't.

Re:PHP: A fractal of bad design by mechanical_fish on Tuesday April 10, 2012 @09:45AM (#3822121)
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 by icc97 on Friday April 13, 2012 @04:57AM (#3835942)
I’ll never understand why people feel the need to criticise another language. Certainly between PHP, Ruby and Python all the languages are great and have their own pros and cons. Its not like any of them are evil corporations trying to do the world a dis-service. They’re all open source and there’s enough room on the internet for all of them. Heck there’s even enough space to get a bit of C programming in.
Re:PHP: A fractal of bad design by joelangeway on Tuesday April 10, 2012 @09:14AM (#3821982)
I don't think that those problems are really independent, but rather, share a common cause with some of the things that made PHP a success. PHP evolved as it did in large part because its benevolent dictator refused to think about more than one problem at a time. I don't argue that that's the optimal way to do things, but it did provide a unique experiment for us all to learn from.
Re:PHP: A fractal of bad design by KaeseEs on Tuesday April 10, 2012 @05:07AM (#3821389)
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 computing technology for a business are in Anno 2012, there are many better systems available which do not expose the novice or intermediate programmer to nearly so many pitfalls.
Re:PHP: A fractal of bad design by mechanical_fish on Tuesday April 10, 2012 @10:13AM (#3822226)
An important thing to remember about PHP is that it really isn't stuck in 1996: When we say PHP you need to think WordPress, or Drupal, or CakePHP or Symfony, since that's what one actually uses nowadays. Novices are steered away from code that pipes SQL injections directly to the database, and toward one of these frameworks, which does the heavy lifting for you so that you don't need to reinvent the wheel.

For years I consoled myself by calling myself a "Drupal developer". I'm not a PHP developer; if I weren't using Drupal I wouldn't touch the language with a ten-foot pole.

But I agree that basic PHP is optimized for the style of web development that dates back to 1996: Server-side rendering of HTML templates. (More powerful PHP - the underpinnings of the PHP frameworks, the stuff one gets in the latest versions like objects and namespaces and closures - basically turns the language into the equivalent of every other scripting language, though obviously much more inconsistent; there's no great reason to choose any of that over Python or Ruby except that it degrades gracefully to PHP, which may actually be very important, but only so long as what you're building looks superficially like a server-side-rendered HTML template from 1996.)

One reason why I'm spilling 10,000 words on PHP is that I've been working with it for five years now, but I'm having trouble getting excited by its future. It has a long future, because 1996-style web sites are not going anywhere: WordPress.com has a zillion users and Drupal is taking over the enterprise and, well, Facebook. But one eventually gets tired of living in 1996. And PHP is useless for client-side-rendered "HTML 5" views, or mobile app client development, and its advantages as a templating language become moot if your server-side code is just an API coughing out JSON objects RESTfully. No newb can figure out that stuff today - even wizards can't agree on the proper semantics of REST, for example - and if ever we do develop a framework for designing RESTful APIs that's as easy for novice programmers to pick up as PHP is for 1996-style templating, I'm betting that framework won't be built in PHP.

But maybe I'm wrong. Hence, deep thought.

Re:PHP: A fractal of bad design by Joeri on Tuesday April 10, 2012 @12:29PM (#3822981)
I actually find php well suited to client-side rendering. Implementing a web service in php is pretty easy. The only thing i use php for is building json-rpc and soap services using zend framework's service classes, wrapping around zend framework's database classes. The app itself is all javascript.
Re:PHP: A fractal of bad design by mechanical_fish on Tuesday April 10, 2012 @01:06PM (#3823209)
True, and if this is all your server-side needs to be, while there's not much reason to prefer PHP for this above anything else, there's also no reason not to just keep on cruising with PHP.

My experience running PHP cloud services suggests that, operationally, PHP is a dream. It's the least problematic layer of the LAMP stack, at least once you've learned what the words "APC cache" mean.

Re:PHP: A fractal of bad design by molsongolden on Tuesday April 10, 2012 @09:48AM (#3822129)
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 by onli on Tuesday April 10, 2012 @11:53AM (#3822748)
I'd say that using Ruby with Sinatra is really easy to pick up - the documentation of Ruby itself is great and Sinatra is also documented really well, not that i think it's particularly complicated. Use an easy template-engine or stick with the default (erb) and (at least for the beginning) the sqlite-gem.

Of course, that was my impression given my prior knowledge, which of course influenced my start with that environment. But i found it to be great almost instantly.

Re:PHP: A fractal of bad design by corford on Tuesday April 10, 2012 @01:09PM (#3823226)
Or you could stay with PHP and use Silex and Twig.
Re:PHP: A fractal of bad design by pbhjpbhj on Tuesday April 10, 2012 @11:00AM (#3822440)
This, please.
Re:PHP: A fractal of bad design by gaius on Tuesday April 10, 2012 @07:48AM (#3821729)
Let us not forget that PHP was once PHP/FI which meant "personal home page form interpreter". And in the 90s, it did exactly what it said on the tin.
Re:PHP: A fractal of bad design by polyfractal on Tuesday April 10, 2012 @10:08AM (#3822216)
What? I find working with databases in PHP (using PDO) far more enjoyable and fast than, say, working in Python.
Re:PHP: A fractal of bad design by mechanical_fish on Tuesday April 10, 2012 @10:29AM (#3822295)
I'm not surprised. A big advantage of PHP's database layer is that it doesn't reinvent the SQL wheel.

[set Greenspun Cynicism Level to MEDIUM HOT]

Other platforms wrap up SQL to the extent that you are encouraged to pretend it does not exist. This is an irreplaceable killer feature if you are trying to encourage new programmers to design things that will eventually prove difficult for them to optimize, or are trying to drum up membership in the NoSQL-silver-bullet-of-the-month club, but in the end what was good for 1996 is still pretty good for 2012: Pull the data from the database using classic SQL from the 1970s, loop through the result set, paste each row into the template, and ship it out to Apache.

PHP does this transparently, which makes it relatively easy to figure out what is going on. Of course, what is going on may be "the novice PHP programmer is staring directly at the SQL but still cannot optimize it", but hey, at least now you can see the problem.

[set Greenspun Cynicism Level to LOW]

Re:PHP: A fractal of bad design by corford on Tuesday April 10, 2012 @01:20PM (#3823295)
Sorry but that is quite hard to swallow.

How are any of these not fit for building an MVP in 2012?

http://silex.sensiolabs.org/ http://twig.sensiolabs.org https://github.com/nrk/predis

There are also modern libraries for a plethora of other RDBMS and NoSQL systems (I think PHP is even going to support mongodb natively soon i.e. no third party client library required).

Re:PHP: A fractal of bad design by encoderer on Tuesday April 10, 2012 @02:19PM (#3823591)
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 languages.

This has actually been a positive thing, because when you're using these data stores/queues/etc at scale and you need bulletproof client libraries, you naturally are led to a SOA. You end up with Python/Erlang/Clojure/Java services that interact with the datastore, that you consume from PHP using Thrift et al.

But being so bad that it pushes you into building a better architecture is kinda a preverse benefit

Re:PHP: A fractal of bad design by corford on Tuesday April 10, 2012 @02:22PM (#3823609)
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 uses NoSQL and needs to scale to millions of simultaneous hits you'd be insane not to develop it with SOA in mind. Using just PHP (or any other single language) wouldn't make sense.

Re:PHP: A fractal of bad design by encoderer on Tuesday April 10, 2012 @02:25PM (#3823627)
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 by corford on Tuesday April 10, 2012 @02:32PM (#3823659)
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 by WHENCE234 on Wednesday April 11, 2012 @03:48AM (#3826428)
Please, the PHP industry is stuck on Wordpress and CodeIgniter which are amateur software.

Yes, you can enjoy these wonderful modern tools for PHP at home meanwhile you suffer with old-tier libraries at work because everyone refuses to move forward.

Re:PHP: A fractal of bad design by corford on Wednesday April 11, 2012 @01:35PM (#3828635)
Change where you work...
Re:PHP: A fractal of bad design by infocaptor on Tuesday April 10, 2012 @09:27AM (#3822036)
i got my mockuptiger entirely done in php and quite happy with my choice.
Re:PHP: A fractal of bad design by tangue on Tuesday April 10, 2012 @04:34AM (#3821320)
You're right. This is a supply-and-demand problem : which choices does non-programmers or casual programmers have when they want to create an app ? How can someone who's working or studying 40+ hours a week find the time to learn the basics of MVC, inheritance etc ... There is a demand for easy to create template-based websites and PHP is the only kid in town for this kind of things.
Re:PHP: A fractal of bad design by Sapient on Tuesday April 10, 2012 @05:12AM (#3821397)
This is no excuse. If you want to learn how to do something, effort is required. How much time will that person waste in the long run battling all of the problems and traps PHP brings with it?

I contend that learning a proper language will be of greater benefit to a person just starting web-development, and putting in just a few extra hours at the beginning to get a solid foundation will in fact save them time in the long-run.

Also, giving complete amateurs this loaded, rusty .44 magnum and pointing them at the battlefield is bad for web security and the web in general, they will inevitably lose all the plaintext usernames and passwords they have in their database.

PHP is a blight on the web.

Re:PHP: A fractal of bad design by kamaal on Tuesday April 10, 2012 @07:11AM (#3821635)
I agree, but lets say your car breaks down somewhere in the middle of the road.

Now you have two options. One is to learn the entirety of automobile engineering before touching your car, second is to learn enough fix the problem for the moment. Needless to say any normal person will prefer the second approach.

Now some mechanical engineer may make an argument that this small quick fixes are harmful for long term mechanical engineering practices. But for the guy who does this quick fixes, none of this matters or is even relevant.

Re:PHP: A fractal of bad design by Sapient on Tuesday April 10, 2012 @08:32AM (#3821840)
The effort required to learn something better than PHP is not equivalent to learning everything about automobile engineering, its more like reading a maintenance manual. Sooner or later, the guy who fixes his car in the middle of the road without knowing anything is going to replace his brake-pads with bits of wood he found on the sidewalk (Not really his fault, someone on a PHP forum has already labeled all the bits of wood as "brake pads")...
Re:PHP: A fractal of bad design by joelangeway on Tuesday April 10, 2012 @09:27AM (#3822039)
A better analog than fixing a literal car might be changing the tire of a car which doesn't have any tires when it is parked but which instantiates some with the help of an instance of ITireFactory. Obviously it makes no sense for a car to use a tire factory instead of just having tires. That is exactly how everyone who prefers PHP feels about everything.
Re:PHP: A fractal of bad design by Sapient on Tuesday April 10, 2012 @11:43AM (#3822689)
There are far better solutions to this ITireFactory problem than PHP, which puts the tires directly onto the car, but forces you to buy a new car as soon every time you get a flat.

Also, the tires are likely to explode every 16 left turns unless you know about the secret tire fixing button under the dash.

It is true that PHP may save people a few hours in the beginning, but at what expense? How longer does it really take to get a noob running a Sinatra, web.py, dancer or something similar?

Re:PHP: A fractal of bad design by entropy_ on Tuesday April 10, 2012 @11:53AM (#3822747)
"Everything else" does not resolve to "Java" or "C++"
Re:PHP: A fractal of bad design by OzzyB on Tuesday April 10, 2012 @12:23PM (#3822935)
While I'm sitting on the side of the road waiting for the PHP maintence truck to come and tow my car away -- I'll read a book...

http://djangobook.com/

Re:PHP: A fractal of bad design by toenail on Tuesday April 10, 2012 @05:14PM (#3824467)
Don't, it's outdated and the official docs are just fine.
Re:PHP: A fractal of bad design by tangue on Tuesday April 10, 2012 @07:44AM (#3821716)
>This is no excuse. If you want to learn how to do something, effort is required.

Some people doesn't want to learn web programming. They want to get things done. Think of PHP as an equivalent of Bootstrap on the server side. People don't use Bootstrap because it's beautiful but because they can't design and in fact don't need anything fancier.

Re:PHP: A fractal of bad design by Sapient on Tuesday April 10, 2012 @08:46AM (#3821881)
The difference between getting it done NOW and getting it done properly is very small in terms of time and huge in terms of safety.

There really needs to be a "good" version of PHP.

Re:PHP: A fractal of bad design by antihero on Tuesday April 10, 2012 @05:33AM (#3821440)
Thing is, if we were to consider PHP a templating language in comparison with a DSL like Jinja2 or Twig, we would reject PHP because it is overly verbose, does not have inheritance, is inconsistent, and has no caching by default.
Re:PHP: A fractal of bad design by emehrkay on Tuesday April 10, 2012 @09:43AM (#3822114)
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