Live data from Hacker News

Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

news.ycombinator.com

21–30 of 89 posts

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#22
post #3

Python will probably be easier to write and almost certainly be easier to maintain. It's possible to write good code with PHP, but a great deal of the example code you'll find online is not good. On top of that, the language itself tends to encourage bad design (see "broken window theory"). Python has a strong culture of having one obvious and good way to do things. In some situations, that can feel restrictive, but…

This list might help http://wiki.python.org/moin/PythonVsPhp

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#23
I have been writing serious, database backed, large dataset, etc etc web applications using Python for about 4 years. Although it may seem like bragging, I probably know the ins and outs and what-have-yous of the python web programming landscape as well as anyone.

State of web programming in python:

The frameworks:

Django: More powerful? No. Faster, more seductive. In the long run you'll outgrow it, if you are any good. It gets you from zero to twenty five percent almost instantly, then gets in your way. The ORM is a terrible mess. The template language is easily the worst (slowest by 10x, slow enough that common templates take 300ms to render, insanely unusable 500 line tracebacks), of any of the common python templating languages. Once you swap out the ORM and the templates, you suddenly realize what is left is also a piece of crap. Django middleware are horrid. I remember trying to write a database session middleware and an error-reporting middleware in django, only to determine it is literally impossible (there are edge cases where any middleware can be skipped and never see the request). When having to deal with it, I use it's oddball WSGI adapter and park WSGI middleware in front if it. I can not say enough bad things about django, it is rotten through and through compared to the alternatives. The admin interface is neat, but is basically a toy once you run into real complexity or data volume. I might use django if I were making a content based application on contract, since the admin interface would be a huge piece of free functionality, or a very simple web app, like a hotel website or something.

Pylons: WSGI based, thank the lord. This means you can write real, flexible, efficient, predictable middleware. I was a huge Pylons fan from around the beginning of 07 until I discovered Werkzeug near the end of 08. I still lurk in #pylons quite a bit, and it was at my urging that the Banquet library (a common interface to all template systems) was discarded (although it may have been on it's way out anyway). Pylons uses great libraries under the hood (webob, beaker, etc), and I would recommend it without hesitation. The __call__ method of the BaseController class used to be a complete mess, I would guess that it still is. Luckily you only run afoul of it very occasionally. the __before__ and __after__ methods are handy. When I stopped using it they were still recommending AuthKit officially, but the mood of #pylons seemed to be (and I agree) that AuthKit is a horrifying abortion that should never be used. The canonical stack with Pylons is Pylons-SQLAlchemy-Mako. I would swap Mako with Jinja2, although who use Mako tend to be loyal to it, and there aren't too many huge warts (the way it does template inheritance makes my head hurt though). TLDR-Pylons good.

Werkzeug/Flask: My personal favorite. You are building a web application, you should have all the moving parts where you can adjust them as necessary without bolting on bizarre hacks, and Werkzeug lets you do that. It may be a bit of a jump for a beginner. Flask is an attempt to make a 'framework' out of Werkzeug, and it seems to be getting some momentum. If you know what you are doing, I believe Werkzeug is the best thing out there for Python web programming.

Tornado/Twisted: Either is great. Due to the pain of dealing with them (you need special event driven db adapters, etc) I would only use them for long-polling applications or the long polling portions of a general application.

Also rans: Turbogears: crap, web.py: crap. Also also rans: Zope (if you don't know what it is already, you probably don't want it).

How to deploy:

mod_wsgi for Apache is the one true way to deploy python web applications. Anything else (fastcgi, reverse proxy, etc etc) is a hard to maintain, unreliable, mess. I would put mod_wsgi on each webserver, and have a machine running nginx or varnish or pound as a load balancer. Varnish is the best if you want to do sophisticated caching or edge side includes, nginx is easy and fine also. Everybody seems to want to argue for something besides mod_wsgi, since Apache is so unfashionable. Part of me wants to encourage everyone to do so, because it makes it drop dead easy for me to walk in and 'fix' your apps reliability problems in about a half a day, and look like a genius in the process. You can deploy python applications to run multiple threads per instance, but realistically due to technical limitations of the interpreter you don't want to run many threads. I suspect less than 10 is the optimal amount. Luckily you can have mod_wsgi spin up multiple processes as well. I would have it recycle the processes after around every 25000 requests, even if you don't have any memory leaks in your app.

Database: I recommend SQLAlchemy. There isn't really anything else worth mentioning. Even if you hate ORMs (there is a strong argument for and against), the sql expression language SQLAlchemy gives you is basically the most amazing thing there is. It takes quite a bit of time to master. If you use SQLAlchemy, use the defaults for the Session until you understand it, or you will end up spending a lot of time and trouble mucking with it.

Nosql: I don't trust it. I suppose I might be becoming a dinosaur, but I also haven't had a major use case where I really needed it.

Other: These don't really have to do with python specifically, but I'll throw them in at the end here: I recommend Redis over Memcached. I strongly recommend Postgresql over Mysql (unless you don't understand what a join is). If you have lots of images (say over 2000), put them in S3 from day one. Some stopgap solution is more painful to fix later than earlier.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#24

How about choosing one that your team knows better? Your startup's app is not a good place to learn new technology, as proven by Reddit and Twitter, among others.

Yea, Reddit and Twitter are great examples of places that failed because they were afraid to learn new technology? Wait. That failed because they tried to learn and implement things in unfamiliar technologies? Oh, wait, what?

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#25
It really doesn't matter.

What matters is having great coders, great ideas for your app and executing them effectively and efficiently which is possible with both PHP and Python.

You can write horrible code with both languages, it might be horrible in a different way but it'd still be horrible. :D

That said, if you're the only one having doubts about Python but the rest of your team wants to write the app in Python and they do have experience working in Python - why don't you trust your team's judgement?

As it doesn't matter, it would be the sensible decision to pick the language your team would like to code in, imho. :)

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#26

I have been writing serious, database backed, large dataset, etc etc web applications using Python for about 4 years. Although it may seem like bragging, I probably know the ins and outs and what-have-yous of the python web programming landscape as well as anyone. State of web programming in python: The frameworks: Django: More powerful? No. Faster, more seductive. In the long run you'll outgrow it, if you are any go…

Could not agree more.

My default stack is Werkzeug+SQLAlchemy+Jinja2. Deployed on Apache/mod_wsgi. If a customer wants Windows/IIS, I deploy using isapi-wsgi.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#28
If you have to ask this question, you're out of your technical depth.

The best thing you can do is promote the guy who's clamoring the loudest to steer clear of PHP to technical lead, and defer all future technical decisions to him.

The language is just a tool. Consider car racing. If you have a poor driver in the fastest car, it won't make a difference. No matter how fast the car is that he's driving, he's going to lose. And if you have a great driver in a slow car, no matter how good he is, he's going to be limited by the speed of his car.

If you have a poor technical lead, it won't matter what language you choose. You can give him a great language, but he will not understand and take advantage of its best features. If you have a good technical lead, but you choose a bad language, the quality and pace of his development will be forever limited by the language.

(And in the context of a team, the abilities of the team to make good technical decisions are limited by the technical direction your technical lead sets -- which is why you need the most talented guy in the position of technical lead.)

The guy on your team who is the most against using PHP is likely the one who best understands the ways in which PHP will limit your team. You do not have the deep technical understanding to make these judgments, and for that reason (without taking months of hard work to gain such understanding) you should defer to him.

Yes, some of the largest websites are written in PHP. But you do not have the same level of resources to throw at the problem that they have.

You're also starting your development at least 5 years later than any of the largest websites that you refer too. Frameworks/plugins/communities evolve quickly. There were more reasons 5-10 years ago to choose PHP then there are today. Companies that have already written millions of lines of code in PHP will find it very hard to switch to another language -- but you do not have to deal with the weight of such legacy issues.

As a small team, you need to look for every advantage you can get. Choosing a programming language that makes your developers more productive is an important part of that.

If you care about framework, community and plugins, Ruby is also a better language than PHP, and Rails provides these three things in spades. Assuming you don't have a good system administrator on your team, companies like Engine Yard and Heroku provide scalable managed Ruby on Rails hosting -- so you can outsource combating issues like down-time and data loss.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#29
post #28

If you have to ask this question, you're out of your technical depth. The best thing you can do is promote the guy who's clamoring the loudest to steer clear of PHP to technical lead, and defer all future technical decisions to him. The language is just a tool. Consider car racing. If you have a poor driver in the fastest car, it won't make a difference. No matter how fast the car is that he's driving, he's going to…

"The guy on your team who is the most against using PHP is likely the one who best understands the ways in which PHP will limit your team. You do not have the deep technical understanding to make these judgments, and for that reason (without taking months of hard work to gain such understanding) you should defer to him."

sorry, what? the guy on his team who is most against using PHP could equally well be an idiot who is simply repeating stuff he has heard on the web by rote, using regurgitated puff to hide his complete lack of understanding of both the issues and the languages themselves.

Your willingness to entirely overlook that possibility and to make the kind of sweeping statements you have made in your post in the absence of any data causes me to doubt that you have the kind of experience and technical expertise that is required to make that kind of statement.

Re: Ask HN: How will it impact my webapp if it is written in Python instead of PHP.

#30
post #14
post #12

From my Quora post on PHP[1]: "PHP is just like every other language: it allows you to write horrible, insecure, stupid code. It also allows you to write clean code." Really, the language doesn't matter. Find people who write good code and give them the tools and atmosphere to do so, and your code will be good. Both are mature languages with plenty of time put into plugins, security, and documentation. Both can obvio…

Really, the language doesn't matter. I disagree. Python, by design, makes it hard to write bad code. PHP, by design, encourages bad code.

but a good developer can write good, clean code in either one.

Every language/IDE combination encourages a 'default' coding approach, I agree that the PHP 'default' coding approach tends to be to create a hopeless muddle of assorted, random crap. OTOH, which would you rather have...a coder who is currently being 'forced' to write marginally better code in Python than he would in PHP because of the language constructs, or a coder who understands good code design and knows how to apply it?

A good coder will be a good coder in any language, the fact that a crappy coder can be made to look marginally better if they are forced to use Python just doesn't feel like much of a win to me.

Post reply on HN