4 ms·
I certainly didn't mean to say that languages like Python and Ruby are inflexible! What I meant to say is that you can't use either of them in direct conjuncti
by lucperkins 14y ago
I certainly didn't mean to say that languages like Python and Ruby are inflexible!
What I meant to say is that you can't use either of them in direct conjunction with HTML the way that you can use PHP. This was what I meant when I said "genuine functionality from scratch." Would I prefer Python+Django/Flask for lots of use cases. Absolutely.
As for the "useless overhead," there are things like the command line (which Python and Ruby web dev absolutely demand) standing in the way of some of the other languages. Personally, I strongly prefer the command line for almost everything, but for beginners this is another barrier.
My argument was not for the superiority of PHP over other languages, but rather against its casual dismissal from consideration.
- spahl 14y agoWhat advantages does this "direct conjunction with HTML" have over templating solutions? Why do most PHP frameworks implement templates then? Also, if command line is a barrier for an aspiring (web) programmer, he/she should start looking for a new career path.
- lucperkins 14y ago1. I wouldn't want to do anything at a meaningful level of complexity without templates. No question about it. And I think that having so many templating frameworks is wonderful (ERB, Jade, haml, etc.). I was only arguing that PHP lets you dive in without NECESSARILY needing to jump through a templating hoop. 2. Is it unthinkable that a person could start learning web dev and pick up the command line along the way? I started out learning PHP/MySQL on my old Windows machine, terrified of the CLI, and now I do almost everything on it (and have converted my old PC to Linux). If the command line were a barrier at all points in the learning trajectory, then you might have a point. But I also don't think that command line mastery should be held up as a sine qua non of learning web dev.
- spahl 14y ago1. Ok so when is it appropriate/useful to use the power of embedded php (in html) instead of templates? Just for learning the first couple of hello worlds? In my experience it becomes a mess to manage when you start having more than one commiter and more than a couple of lines of code. 2. You don't have to be a command line expert to start using it. All the books at http://learncodethehardway.org/ http://learncodethehardway.org/ show that command line can be integrated in the language learning process seamlessly. No reason to be terrified of it, on the contrary, new coders should embrace it as soon as possible.
- cloverich 14y ago@1. When the project is only a couple of pages.
- drostie 14y agoLook, there are two things you are saying. One is "you can't do this with Ruby/Python" -- which is a superiority-of-PHP argument -- and the other is a plea of "PHP has done a lot, so let's not be too hasty dismissing it." You made both of these arguments. In fact, you made the first one in this very comment where you say you're not arguing for PHP's superiority over other languages. In some ways this is true but I would be hesitant. What you're really advertising is that PHP has an implicit `echo("` statement which looks like `?>` and also implicitly occurs at the beginning of the file. A lot of new folks write really hard-to-follow code. Here is the seed of badness from which such code eventually germinates and blossoms: <ul><?php foreach ($users as $user) { ?><li class="user"><a href="/users/<?php echo $user['id'] . '">' . $user['name']. '</a></li>'; ?><?php } echo '</ul>'; If you do not see why this is bad, imagine that you have a loop within a loop and they get separated by more than 20-30 lines of PHP. Notice how some of the HTML occurs within the PHP statement but pairs with tags outside of the PHP statement, and imagine functions which are producing such code. Et cetera. Python+Flask will force you to either do it in a Jinja template, which avoids the problem because you cannot 'return back to Python' midway through: <ul>{% for user in users %} <li><a href="/users/{{ user.id }}">{{ user.name }}</a></li> {% endfor %}</ul> Or else you could define the file within Python using strings, in which case your syntax highlighter will be able to tell you exactly where these strings begin and end: output += """ <!-- ... more code ... --> <ul>""" + "".join([""" <li><a href="/users/%i">%s</a></li>""" % (u['id'], u['name']) for u in users]) + """ </ul> '<li><a href="/users/%i">%s</a></li> % (u['id'], u['name']) for u in users]) + """ Of course, Jinja is more readable in this case, and that's kind of the point. For most web apps, you want a sort of preamble which calculates and formats a bunch of information, selects a template, and renders the template to the user. For PHP, this preamble is Apache, and if you want more, you probably need to generate an include() file to force yourself to stay sane. (PHP doesn't force this however, and many people write bad code which simply does the calculations in the HTML wherever they are needed -- and then you get massive code duplication and the joys of trying to match curly braces through large blocks of HTML.)