News for hackers. Stuff that matters.
Re:PHP: the quiet powerhouse by drostie on Wednesday June 13, 2012 @06:39PM (#4108846)
"It’s been very interesting beginning my trajectory in web development in 2012... [PHP] might be the best language to use in gaining an understanding of the fundamentals of web development... No web development language outside of PHP grants you the kind of flexibility to both (a) produce genuine functionality from scratch, outside of an MVC framework, and also to (b) work within the bounds of MVC in deeply sophisticated ways if you wish."

I believe you have overstated your case, perhaps due to inexperience with other languages. In particular, claiming that any modern scripting language is inflexible sounds a bit crazy.

I have attempted explaining how to get a WAMP stack running, with EasyPHP, to an absolutely new-to-web-dev indiviual who was curious about creating a chat room. Let me just say that the situation is ten times better now than when I was the same age and was poring, lost, over Bruce Eckel's Thinking In Java trying to do the same thing, which must have been sometime around 1999/2000.

These efforts to teach a newcomer reminded me that there's a lot I take for granted. There is a step where you are saying "okay, we've got to see where Apache is; what port is it listening on, how can we get you to phpMyAdmin; here's how you set up rows and columns in your tables and think about a database; no the reason it's not working is because you saved as '.html' and not '.php'; I know you've seen URLs that don't end in '.php' but that requires invoking the Rewrite Engine and teaching you about .htaccess files; oh the header modifications can't be the first thing you emit; here's the docs, you basically have to search them because there is no organizing principle and no way to find out what you can do..."

I agree, Python+Django will make you learn a bunch of weird "modeling" stuff first. To me, setting up the data model at the beginning of an app is like inputting a character name at the beginning of an RPG: as some sources testify [1], you can easily waste several hours on purely aesthetic concerns before you even really start to play.

Nonetheless, Python+Django comes with a lightweight dev server and an interactive console and a routing table, as well as a template language. The knowledge of the database is internalized to the language, so that I don't have to teach someone how to use phpMyAdmin but rather when to use a ForeignKey. If we talk purely about learning to develop on the Web then PHP has much, much more useless overhead.

Sure, eventually we will have to get a production-ready web server communicating with the application, but that can be abstracted until later with Django: it occurs as an up-front teaching cost with PHP.

I say this not even as a Python aficionado per se. If anything I like Node, and Node is nowhere near either of them in offering pleasant functionality.

[1] http://www.cad-comic.com/cad/20030630

Re:PHP: the quiet powerhouse by lucperkins on Wednesday June 13, 2012 @06:49PM (#4108879)
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.

Re:PHP: the quiet powerhouse by spahl on Wednesday June 13, 2012 @06:55PM (#4108911)
What 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.

Re:PHP: the quiet powerhouse by lucperkins on Wednesday June 13, 2012 @07:20PM (#4109003)
1. 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.

Re:PHP: the quiet powerhouse by spahl on Wednesday June 13, 2012 @07:36PM (#4109053)
1. 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/ 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.

Re:PHP: the quiet powerhouse by cloverich on Wednesday June 13, 2012 @10:01PM (#4109435)
@1. When the project is only a couple of pages.
Re:PHP: the quiet powerhouse by drostie on Thursday June 14, 2012 @03:47AM (#4110284)
Look, 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.)