5 ms·
> PHP has no shortage of weirdnesses and warts, but it occurred to me recently that no other major language was created expressly for the purpose of rendering w
by Legion 14y ago
> PHP has no shortage of weirdnesses and warts, but it occurred to me recently that no other major language was created expressly for the purpose of rendering web pages. All the other major contenders (Python, Ruby, Java, etc) are, for better or worse, general-purpose programming languages, which are pressed into service for rendering HTML strings using various libraries and frameworks.
For non-trivial web applications, the "rendering HTML strings" is one of the smallest parts of the job.
The lack of separation between application and HTML output in PHP may be an asset when starting out or when making lightly scripted web pages, but when creating an application that just happens to be served up over the Web (and possibly served up other ways too), those general-purpose languages are much more natural fits for the job.
- thangalin 14y agoI use the following architecture: Browser -> POST -> Database -> XML -> PHP + XSLT => HTML Prevents HTML from being mixed with PHP. PHP becomes the "controller" in the MVC world. This makes the application easy to migrate to another language.
- astrodust 14y agoXSLT plus PHP? Are you a masochist?
- klibertp 14y agoWhy do you think so? This makes perfect sense to me - imperative language wraps purely functional one, and sits on top of declarative, relational language(s)[1] for data storage and manipulation. The GP is using a very well thought out configuration; this is using the right tool for the job incarnate. If I wasn't lacking in SQL department I would probably do exactly the same (probably replacing PHP with something strongly and maybe statically typed). [1] SQL and XML seems a bit redundant, but I don't know what they are used for exactly. Also I lumped both SQL and XML together as "relational" because of XQuery, but I admit that I don't know much about the latter and this may be not accurate.
- thangalin 14y agoLong ago I learned that system source code is not as important as data. You can always hire hot-shot software developers to (partially machine-)translate the system into the langue du jour. Using XML allows means the data associated with every "page" in the system automatically doubles as a service (SaaS). XSLT allows those those services to be translated into JSON, ASCII, PDF (via LaTeX), XML, or the format du jour. With this architecture, the amount of time to publish a new export format for every "page" in the system is reduced to the time it takes to write a new XSL template: hours to a few days. All pages can reuse the same code to render themselves: $data = get_xml( $id ); $xml = get_xml_dom( $data ); $xsl = get_xsl_dom( $stylesheet ); $proc = get_xslt_processor( $id, xsl ); echo $proc->transformToXML( $xml ); This cleanly separates business logic and the data model from presentation, plus much more. Perhaps it is masochism, though. ;-)
- astrodust 14y agoI'd prefer to pick a language for the job that can handle manipulating the data as well as emitting it in the correct format. Having to duct-tape XSLT on top of PHP just because PHP can't cut it is rather perverse. The only thing I can think of that's worse than "programming" in XSLT is ColdFusion.
- thangalin 14y agoWhat language can make every page output XML, PDF, JSON, or ASCII, without changing the business logic, data model, or spending more than a few hours developing each new format?
- Firehed 14y agoWhat lack of separation? Don't take this the wrong way, but have you ever actually tried to use PHP in a non-web context? Running "./foo.php" is just as easy as "./foo.py", "./foo.rb", etc. All of these complains seem to come from people that have never even tried to do this kind of stuff. It's damn easy. If you echo HTML, you get HTML. If you echo binary data, you get binary data. JSON, XML (including SOAP bodies), text, nothing at all, file i/o, direct socket connections, exit codes - all are supported equally well. The only thing vaguely related is the HTTP headers that you get for free if you're running it behind a fastcgi module (apache's mod_php, nginx/php-fpm, etc).
- jtreminio 14y agoHey, it sounds as if you don't know what you're talking about - at all. You can write a single PHP file that includes HTML, Javascript, MySQL, CSS and PHP, but that would make you a bad developer, or it's such a simple one-off thing that you don't worry about it. Or, you can develop with maintainability in mind and separate those 5 concerns out.
- Legion 14y ago> You can write a single PHP file that includes HTML, Javascript, MySQL, CSS and PHP, but that would make you a bad developer, or it's such a simple one-off thing that you don't worry about it. Tools facilitate workflows. The fact is, PHP very strongly facilitates your "bad developer" path. That's why there is so much PHP code that goes down that path, compared to other languages. Yes, you can go off on a better path. But better designed tools make it much more easy and natural to do things the "right" way. PHP makes your "bad developer" path the path of least resistance. That's bad.
- BlackAura 14y agoThis isn't unique to PHP, by any means. Visual Basic was much the same, even in later versions where you actually could write well designed code if you knew what you were doing. The IDE, documentation and design of the language encouraged you to make bad design decisions, much like PHP. .Net languages aren't immune to this either, particularly Windows.Forms and ASP.net. To write decent code in those, you basically have to fight the IDE and the framework every step of the way. ASP.net MVC makes it much easier to write good code, at the cost of being harder to user if you don't already know what to do. Your average newbie can't just point and click until he's half way there. PHP has decent frameworks, like Symfony. They make it much easier to do the right thing, and harder to do the wrong thing, at the cost of being more difficult to learn. Props to the Symfony team though. They're still trying to make something good out of PHP long after most other decent developers abandoned the platform on favour of something less newbie-driven. It helps a lot to have that kind of framework available, just in case I have to use PHP for something. Edit: Accidentally said that ASP.Net MVC encouraged bad code, but meant it encouraged good code.
- deleted 14y ago[deleted]