I'd say the necessity of this post is <i>why</i> PHP is as popular as it is. With PHP, there are no package managers I have to install; there is no template language to learn; there is often no version control; there is no "framework"; etc. You just drop in a .php file and, most likely, it will just run. If I need a quick dynamic page on my server, it's much easier to do this in PHP than in Python or Ruby.<p>Until Python or Ruby have that kind of simplicity, they can't overtake PHP. While it might not be the kind of design that leads to well-designed web apps or even good code, it is the kind of design that leads to more — especially less technical, or, like me, lazy — users. It's up to the developers of those languages if this is even a market they want. There may need to be something new to do the same job as PHP, but better, without the innumerable warts.
Nice littel overview, but...<p>"Unicode sucks. This is a universal truth."<p>And here I stopped reading. Unicode is the best thing around, what sucks it that Py2 does not implement it very well. Py3 does, and that is the main reason I really would like to use it and hope Django will soon fully support it. (Because: there are other languages beside the European ones)
I would love to switch to Python from PHP but I can't. The reason is I keep getting told to learn Python 2. Python 3 has been out for ages!<p>Basically I am concerned that I will learn something and create app's which within a year will be out of date. I am confused why Python developers are advocating that newbies learn an old and presumably soon to be legacy version of the language.<p>I remember when this kinda happened with PHP and versions 4 and 5. I still run across hosts who default to PHP4!? WTF? Its 2012!<p>Is PYthon3 really that new that you shouldn't pick it up or is this developers still refusing to update?
<p><pre><code> The idea is that a transaction starts when a request starts, and it’s automatically rolled back if there’s an exception. This is behavior you want from the start! It’s half (err, ¼) the point of using a database.
</code></pre>
I mostly agreed with the rest of the article but this strikes me as massive blooper. I can see no reason this would be considered good advise.<p>It's the database equivalent of the GIL, can't figure out what you actually need to lock? Just lock everything!<p>An example of this going wrong in production, I work in the online gaming (gambling) industry. One of our users won a large jackpot, our code started a transaction, contacted the 3rd party to have them release the funds, recorded the win in the transaction journal, updated the customers balance etc. Then the stored procedure which inserted a row into the outgoing email queue had a small error. This caused all of the database work on our end to rollback.<p>For what its worth, this was discovered during a reconciliation with the 3rd party and the customer received his winnings.<p>My point being, this is a horrible way of dealing with database transactions. Only things which are transactional by nature should be carried out within the same transaction. Obviously your code needs to deal with any errors and carry on or report an error as is appropriate.
"MySQL is the PHP of databases". Strange, I just had this sentence popping in my head yesterday. I'm seriously considering writing a list of its wrong doings.<p>Great article overall.
Is there any cheap & easy webhosting available for Python?<p>Occasionally I get commisioned to build small websites ( < 50 visitors per day) and for that I want to be able to build the site in a day or two.<p>I don't want the hassle/expense of having to setup and run VPS/AWS infastructure. I just want to give someone a bunch of files and say "sign up for some cheap webhosting, ask them to give you a DB called X and upload these".<p>I usually end up just doing it in PHP, but it has always felt like a poor reason to choose a language with so many warts.
I have no idea why web2py gotten such a bad rep. I am a beginning webdeveloper and seriously: web2py is a pleasure to work with. Simple to start, deploy, port and hack. It's backwards compatible and has a template language that really is non existant as so far as its pure python.<p>Compare that to Rails - which is (comparable) hell to set-up and breaks with upgrades etc.<p>If you want python web development to be simple, web2py is the way to go. Since I don't have a CS degree and I have often been wrong before - there might be a real problem somewhere. But I don't think so. One of the reasons for this is that Jakob Moss removed his web2py bashing from this thread. Didn't edit - removed it: <a href="https://www.quora.com/Is-web2py-a-good-Python-web-framework/answer/Anthony-Bastardi" rel="nofollow">https://www.quora.com/Is-web2py-a-good-Python-web-framework/...</a>
Personally, I _like_ PHP because, at the core, it is a collection of utility functions to write webapps quickly. Here's a small set of those function that I would like to see somewhere else (like in Python for example):<p>Save a file: file_put_contents()<p>Load a file: file_get_contents()<p>Trim whitespace: trim()<p>Print a string (even numbers!): print $str<p>Dump an array: print_r()<p>Print the stack trace: print $e->getTraceAsString()<p>Want to embed HTML? Go ahead, _without_ any of this nonsense: print "<table><tbody><tr><td>"+str(val)+"</td></tr></tbody></table>"<p>Want to check for errors and improve the quality of the code? Go ahead! Use lower level functions like fwrite, fread, etc; most functions return FALSE on error, use try/catch, throw Exceptions, create custom Exception classes, go nuts with over-architecting if that's your thing.<p>Also, as someone who knows C and C++ rather well, I find PHP completely intuitive, very easy and flexible, as opposed to:<p><pre><code> if __main__=="__main__":
main()
</code></pre>
and passing self around is just plain redundant.<p>The icing on the cake is that a huge part of the built-in functions wrap and extend existing C functions: strpos, strlen, so the language rarely gets in your way. The docs are pretty good (there's room for improvement).<p>So you can be a zealot all you want, but the truth is: the language doesn't make your code reliable - YOU make the code reliable and, from my experience, people who bash a language rarely know what they're talking about and it usually just boils down to personal preferences like braces vs no-braces.<p>Lastly, I wish you all the best in your fanatic bashing of a good tool that has proven itself appropriate for web applications. Everyone's tired of the following example, but I'm going to say it anyway: Facebook (and thousands of other large websites). Feel free to be in denial about that.
This guy failed to cover web.py which is one of the fastest ways to start prototyping a web app in python. =/<p><a href="http://webpy.org/" rel="nofollow">http://webpy.org/</a><p>I personally use it for a small app which returns (and stores) search suggestions from redis.
I was thinking this could redeem the author's credibility a little after the PHP rant, but the irrational hatred for Cheetah sounded very familiar.<p>I only used it in one project, a few years ago, but there's really no bad thing about it I couldn't say about any other templating system in any language I ever tried.<p>I wouldn't really take offense with that, but while the XSS chapter still has some points, the Sanitizing chapter goes on to bash PHP for a subjective trend of sanitizing (examples?) just to go on and present an example of sanitizing.<p>In general, it was a decent article, but sadly again much more opinionated than needed. It's one thing to suggest one technology over the other but it doesn't help to make people who actually agree with your point have their eyes rolling every second paragraph. (That the author doesn't like MySQL was to be expected after the PHP rant as it usually goes hand in hand, but showing some real reasons for Postgres over MySQL would have been nice.)<p>Still the same criticisms apply, I'd wager most people use PHP (or MySQL for the matter) because it's MINDBLOWINGLY AMAZING, but because
a) the infrastructure is set up (especially DBAs hate to mix and match in my experience)
b) the people at hand can use the language and use it well
c) it gets the job done. quickly. sometimes "good enough".
I like java for web app development, simply because it has a well-structured api and a massive community of developers who have run in to the majority of the road blocks you will most likely encounter on the way to launching your app.
I really don't think it's worth taking this guy seriously. First he writes a worthless and inaccurate lambast of PHP, and now he's trying to "convert" people to Python by telling us Unicode sucks. Get a life.
Good article apart from one thing - avoid the hell out of session state. This becomes the dumping ground for all sorts of crap and will slowly knacker your app. You should only persist enough information to identify the user between requests and keep the rest stateless. We do that using encrypted cookies containing the user id, display name and correlation id.<p>I've just spent 6 months entirely removing session state from an asp.net app and the performance gain is amazing.
Great article! For those of you who say how easy PHP is, it's because you don't remember the early days when you had to compile php to run on your box, only to watch it fail after an hour of compilation :) history aside, these are just tools. For many site, perhaps for majority of tasks, PHP might be the best tool for the job. Once you start doing more complex stuff that will require additional libraries and modules then you need to look into other languages.<p>I used servlets from very early days, just because I could never understand another man's perl code and I thought the architecture was better. However J2EE got so big and academic that took all the fun out of coding. I've recently started to do some stuff in python and the fun is back again. I love all the NLP libs that are available for python in addition to vast support and ease of coding. Not to mention, I like the python community more than ruby (rails really). It just seems like python guys come from a stronger CS background and are not some over-night rail guys who want to push their faith down your throat.
By far the easiest way to get started with Python web development is Web2py which comes as a self-contained install where you can get started in 5 minutes. So you automatically get "request" information, big deal.
In python, stay away from default arguments for methods/functions.<p>EDIT: yes, mutable default values:<p><a href="http://effbot.org/zone/default-values.htm" rel="nofollow">http://effbot.org/zone/default-values.htm</a>
Say wat you want of php. But it's (insert personal pejorative option) made for it.<p>Sure Its a_little_inconsistent AndSomewhatChaotic<p>But all the basics for the web are incredible accessible right away.<p>With every other language you have to start with a framework.<p>I find php easier than rails to prototype applications and do fast hacks that need a web face.<p>It's simply the right tool for the job on those occasions. Of course, later they become huge systems...
"I only know PHP"<p>"I just trashed PHP rather harshly"<p>"I want to learn python"<p>Well, you're doing it wrong. How can you trash PHP if you know <i>no</i> <i>other</i> <i>languages</i> ?!<p>You're following articles, posts saying PHP is bad and.. you decide then that's right it's bad!<p>Ever though about <i>thinking</i> on your own first? Like, actually trying a language (python, why not) <i>then</i> deciding if it's better?<p>This kind of stuff always amaze me. You know, sheepish.