3 ms·
Personally I think there are better languages for beginners than PHP. I think Javascript, Perl, Python, and more are fundamentally better in this regard. Ther
by einhverfr 15y ago
Personally I think there are better languages for beginners than PHP. I think Javascript, Perl, Python, and more are fundamentally better in this regard. There are some fundamental, lexical problems with PHP in this regard. I think by a "language intended for beginners" I think it is meant as "a language intended to allow HTML/SGML authors to cross over into programming."
PHP is in essence a fairly narrow tool, much like a chasing hammer (which really isn't that good for driving nails but is extremely important in some kinds of metal work). It is a preprocessor for SGML files (and this is why all programming logic is typically put in SGML PI tags). I call it a "templating system turned on its head" because whatever you do with PHP, every file is lexically part of the template even those which have no other SGML tags other than the PI tag which is indicating programming logic.
But what this means is it works very well in its own specific domain (namely preprocessing HTML, XML, and other SGML files), but degrades quite a bit as one gets out of this area. This limits code reuse basically to web apps (yes, I know you can write GTK apps in PHP, but really? why on earth would you want to?) and thus locks one into essentially one set of technologies. So there are drawbacks as well as advantages.
- blindhippo 15y agoTotally agree. In addition, PHP is a freely available, incredibly pervasive language that can be installed and run on even the most inexpensive web hosts. There is almost no messy configuration or server setup to be done. So for a beginner web developer, all they need is a GoDaddy account and a couple tutorial guides. The sad thing is that many developers stop here. They don't go on to figure out how PHP and Apache work together, how memory gets used and how to manage it effectively. They don't get exposure to proper coding standards (PHP's common standards are horrible IMO). And more often then not, a PHP developer learns how to code in isolation. Coding should be developed as a mentored skill.
- mechanical_fish 15y agoPHP is indeed a "templating system turned on its head" (according to second-hand reports from a talk by Rasmus Lerdorf, PHP was originally designed as a bare-bones templating system for C programmers, but then more and more stuff migrated into the templating system...). And it is, indeed (or was, anyway) tied strongly to a single domain, and a limited set of architectural patterns. But every design choice cuts both ways. These features are not merely drawbacks. These are PHP's strengths, the things that make it so delicious for "HTML authors who need to cross over into programming". You can learn PHP with Google. My understanding is that most people do. [1] Just Google all your problems and up will pop some code that you can mimic. This works because, to first order, all PHP code is solving the same problem in the same way. You will probably not accidentally Google up some PHP-based physics simulation. You will probably not Google up some PHP code used by sysadmins to parse the output of pipes on the command line. You will certainly not Google up any PHP-based graphics algorithms or device drivers or client-side DOM manipulations or Android system functions. No, when you Google "how to do X in PHP" you'll get some code that you can paste into a template with a .php extension and then execute on your cheap shared host. Until fairly recently there wasn't even any danger of encountering object-oriented PHP. You can argue that programmers trained in this way are useless for anything but cobbling together Web pages, and you're right, but 90% of them don't care. Web pages are a killer app. People build whole businesses out of cheesy web pages. My suspicion is that many PHP tinkerers don't want more "architectural flexibility"; that translates into "decisions that we have to make but don't know how to make", "knobs that we have to set carefully but which we don't even know how to turn", and "oodles of online documentation for use cases that we don't have, which chaffs up the search results for the use cases that we do have." The irony, of course, is that PHP's maintainers have been hard at work bolting features from other languages onto PHP, which as a side effect threatens to destroy the narrow domain-specificity that was its most unique feature. [2] Objects, namespaces, closures have all been welded onto the superstructure. One wonders what happens next. Maybe the folks who embrace all these things will drag the entire PHP community closer to Java, Python, Ruby, or some oddball superposition of these things. But I think it more likely that the community will continue to balkanize, with the bulk of users rejecting all these transplants but certain segments embracing one or another of them. --- [1] I learned PHP via reading and hacking on Drupal modules, which is a much better plan, but also definitely not the beginner-friendly choice. Drupal has a steep learning curve. [2] Though don't blame the maintainers too much: These features are in fact in demand, from the people who took up PHP without realizing that it was a narrow domain-specific language and pushed it right up to the limits of the available hacks.
- einhverfr 15y agoCompletely agreed. Hence the chasing hammer metaphor. You wouldn't use a chasing hammer to drive nails, but you wouldn't use a carpenter's hammer for chasing either. These are strengths, but they ensure that PHP is a relatively specialized tool.