16 ms·
Ask HN: How will it impact my webapp if it is written in Python instead of PHP.
Folks, I have seen too many HN posts on the fact that PHP is not a good language to develop a robust web application, despite of the fact few of the biggest web sites are running on PHP. We(my team and me) started debating on the issue of choice of the technology for the next project. I am still in some ways not convinced that python may be a better approach.
PHP and Python
* Both have good framework web.py | codeigniter
* Both have good helpful community and support
* Both large set of plugins
How will it impact my webapp if it is written in Python and not PHP
- beza1e1 16y agoI do not know what you mean by a "robust" web application, but in my experience Python libraries (for example feedparser) are of higher all-around quality. Less pitfalls, means fewer bugs and faster development.
- Chirag 16y agoWhat I mean by 'robust' is scalable and usable.
- petervandijck 16y agoAnd what do you mean by scalable and usable? :) Scalable in what sense? Usable by who?
- Zak 16y agoPython 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 it tends to make dealing with code other people wrote easier.
- zackattack 16y agoHow do you relate "broken window theory" with the grammar of PHP?
- Zak 16y agoBroken window theory, as it applies to code essentially says that sloppy code begets sloppy code. PHP itself has sloppy design, such as inconsistent argument order and naming conventions for built-in functions. Most of the complaints I can think of about PHP that are objectively demonstrable are outdated. The language now has namespaces, closures and the like. Most of the complaints I have left have to do with the feel of the language, and some remaining cultural elements; it feels like a ghetto, even though it seems to have modern infrastructure now.
- deleted 16y ago[deleted]
- keyle 16y agoThis list might help http://wiki.python.org/moin/PythonVsPhp http://wiki.python.org/moin/PythonVsPhp
- jedsmith 16y agoPython has a strong culture of having one obvious and good way to do things. This is, I think, where people new to Python stumble up. If they were Dutch, the obvious way would be easier to spot.
- sreque 16y agoIt will probably negatively impact your project if all of your team know PHP better and are more comfortable with it. Pick whichever language works best for your team. If some of your team love Python and are able to convince the rest of you as to why its better, then go for it. However, a bunch of strangers on HN probably aren't going to offer much of value. If you are really curious, I suggest diving into Python yourself (no play on words intended!) by reading a book on it, writing some code examples, and then maybe a small project of around 500-1000 lines, trying to use the idioms of the language that you are less familiar with. And if you're not curious, more power to you! In the end, it's the product and the team developing it that are most important.
- stratospark 16y agoIf you want a more "guided" approach to Python webdev, try looking into Django. There's a large community that has built up around it contributing tons of plugins. I say this as someone who is working on a Pylons site. You can do anything with Pylons that is possible with Python, you just have to figure it out yourself or twist someone else's library to make it work. Sometimes you don't need that much freedom and the guided approach will do 90% of what you need. Do a bit of research and see which approach best suits your needs.
- newaroundhere 16y agoI'd also recommend a look at Flask: http://flask.pocoo.org/ http://flask.pocoo.org/. It's quite new but more polished and easier to learn than Pylons, and comes with excellent documentation and handy extensions. As you say, however, Django is a good place to start for a beginner - it has a larger community and ecosystem of apps for doing just about anything web-related (although the apps are of variable quality). It's also quite mature (5 years now) and has more job opportunities.
- zalew 16y agocontributing tons of plugins. applications, not plugins
- plinkplonk 16y agoThe only way to get useful answers (vs just answers) to these questions is to get a feel for web-app development with Python yourself. Work through a Python tutorial (I suggest "Dive Into Python") first and then set up Django and work through the Django tutorial. Build a small app of your own with Django. If you are a decent programmer all the above should take you a weekend at most. And then you'll have some first hand experience about difficulty of transition etc. Fwiw, I prefer Django to PHP. But then I am biased so use appropriate amounts of salt. I'd kill myself if I had to work for very long in PHP.
- crististm 16y agoMaybe debating about it is not the right approach. If you have experience in PHP and you can afford some (inherent) delays in the next project you should try Python and see for yourself. You will be hit by reality faster and better than any debating would. Then you'll have an educated opinion for the next (second) project. I'm biased towards Python.
- notphilatall 16y agoPython will allow for easier modularity, wheras PHP will make it easier to pollute the global namespace. Likewise, all standard python components are made available in namespaced modules, are consistently named and well documented. You can certainly write PHP without creating a global mess, but novice developers will be tempted to introduce globals and the standard library is in the global namespace, setting a bad example. Perhaps more importantly, many skilled developers favor Python and will avoid PHP. When you seek to grow your team, you will likely draw from a better talent pool if your application is written in Python.
- bkrausz 16y agoFrom 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 obviously scale well, and both have the same set of capabilities barring some specific edge cases. [1] - http://www.quora.com/What-are-PHP-s-main-flaws-(and-good-parts)?__snids__=1360846#answer_55743 http://www.quora.com/What-are-PHP-s-main-flaws-(and-good-par...
- moe 16y agoReally, the language doesn't matter. I disagree. Python, by design, makes it hard to write bad code. PHP, by design, encourages bad code.
- bandushrew 16y agobut 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.
- bkrausz 16y agoThank you! For some reason I always take flak for this position, great to know I'm not the only one who feels this way.
- moe 16y agoa 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? That's an esoteric question. A good coder wouldn't choose PHP in first place, unless there are pressing reasons (i.e. a legacy code-base). Consequently you can speed up your hiring process simply by weeding out candidates who propose to use PHP.
- jessor 16y agoA friend of mine always says "it just doesn't matter" in his startup, meaning just chose a language instead of constantly debating over which is better, which will scale better, which sounds more awesome... It's probably more important to just getting something done in the first place. You can probably rewrite when you get some revenue.
- BerislavLopac 16y agoHow 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.
- justin_vanw 16y agoYea, 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?
- BerislavLopac 16y agoNo, they tried to build the app with a technology they wanted to learn {Reddit : Lisp, Twitter: Rails} and then had to rewrite it (mostly) from scratch when that didn't work out {Reddit: Python, Twitter: Scala}. Neither failed, because they were smart enough to know when to ditch. God knows how many startups failed because they didn't know that.
- bolden 16y agoFor Twitter, Rails was the technology they knew. They decided it wasn't the right tool for their needs. Scala is the tech they learned (and continue to learn) on the job. They even have a group blog detailing this process (http://gracelessfailures.com http://gracelessfailures.com).
- ANINDIAN 16y agoUse Python + Django hosted on Google App engine It will remove all your worries of paying any thing unless you get million hits per month!
- adrianscott 16y agoI concur. Also you will be disciplined into writing scalable code and will not have to deal with operating system issues, setting up servers, configuring db's etc., so you can focus on programming. (If you want an invite to Fosdev for trying out GAE quickly, let me know.)
- jeb 16y agoWith PHP it will be much much easier to outsource parts of your project compared to python. There are more PHP developers and they are much cheaper.
- anthonyb 16y agoThe downside of that is that it's much harder to find good PHP developers. There are an awful lot of awful developers who use PHP; less so with Python and other 'niche' languages.
- justin_vanw 16y agoI 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.
- JustAGeek 16y agoIt 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. :)
- kashif 16y agoPython for more modular code. Python for maintainable code. Python for better libraries. Python for Google App Engine and .NET Python because of a cleaner grammar and better syntax. Python for you.
- benno 16y agoIf 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.
- bandushrew 16y ago"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.
- superdavid 16y agoUse what you're good at. If you're good at neither, it's time to find another day job.
- TheSmoke 16y agoI'm happy that I'm developing my web apps with Python. I have used almost all Python web frameworks out there. So let me explain my experience. Django - Until 1.2 Django was a total headache but with 1.2 it really is a great tool to develop web applications. No reason not to use it unless you feel something's missing. Django has an amazing community with very helpful people. web2py - web2py lets you create apps very fast, it doesn't push you hard and you can build something in a very short time. However when things get complicated, you will want to quit web2py. I don't like its form helpers, I don't like its validation as the validation is unfortunately not per object but the input data and url routing is headache with web2py. Web2py also has a great community. All your questions will be answered in a short time. turbogears - turbogears is a subset of pylons with sqlalchemy as orm and genshi as templating system. i don't like the @expose decorator. it's just not for me. provides many other tools by the way. TurboGears has a small but helpful community. SourceForge is using TurboGears. werkzeug - now this is the framework of my choice. the endless freedom. it is only a skeleton which lets you dress your application onto it very easily. you can choose anything as your orm and templating system. provides a strong url routing mechanism. supports sessions, secure cookies and any other thing you may need. however i am not using werkzeug anymore as i don't like the way people act in #pocoo on freenode. this is the only reason i am not using werkzeug. they are ignorant and i don't like it. Pylons - My favourite Python framework of all times. Flexible as much as it can be. Provides you the freedom you need for anything. I strongly recommend using Pylons. I am currently using Pylons and I'm very happy with it. Pylons is also used at some very popular web sites such as bittorrent.com, reddit.com, etc. It has a helpful community whenever you need. Frameworks aside, how will using Python will help you? * Very clean and beautiful code. * Easy updating and maintaining the code. * Easiness and laziness. * Great set of libraries. * Python for your mental health. And I'd like to thank justin_vanw for the great sum. :)
- mdg 16y ago>however i am not using werkzeug anymore as i don't like the way people act in #pocoo on freenode. this is the only reason i am not using werkzeug. they are ignorant and i don't like it. Care to explain? I dont lurk in #pocoo but I am confused as to why you are putting an entire room on blast.
- 16y ago
- randallsquared 16y agoThe two framework examples you give are not at all on the same level. CodeIgniter has a lot of stuff to structure your application, but many experienced PHP developers wouldn't bother with it (and I, personally, don't think it's worth all the extra code you're importing); web.py, on the other hand, merely gets you partway to where PHP starts, with regard to writing your application. If those were your only alternatives, then I'd say you probably want to use web.py, but if using web.py is one of the choices, then you might just as well use PHP without a framework at all, which is one less piece of third-party software to go wrong. One thing I've really liked about PHP is that (using Apache) if the webserver is up, PHP is up. When I developed most of the applications in Python, it seemed as though I was constantly worrying about the application process failing, even though this happened very rarely. PHP really is an ugly language, but you eventually get used to it. :(
- petervandijck 16y agoRepeat after me: it does NOT matter. It does NOT matter. It does NOT matter. Choose the one you are most comfortable with.
- mdg 16y agoit does NOT matter. It does NOT matter. It does NOT matter.
- karanbhangui 16y agoJust use what your team knows better. Period. There are enough implementations of both languages in the real world (YouTube - Python, Yahoo/Facebook - PHP)
- jrussbowman 16y agoIf you know PHP and CodeIgniter well, and don't know Python very well, then it will take it longer to write in Python. If you move to something like Tornado (python), Twisted (python) or node.js (javascript) then you might be able to get more performance out of your app, but really only if think moving to that level of complexity is necessary for you app. In general, it's best to go with what you know. Yahoo! uses a lot of PHP as does Facebook. Since you mentioned CodeIgniter specifically, you're already well down the path of using a framework that allows you to write modular and reusable code with PHP.
- f1gm3nt 16y agoI've been creating sites for a number of years now and have used php since the days of putting perl scripts in your cgi-bin. I'm just now starting to learn python. Here's mho. If you use php, check out symfony. Codeignighter is crap once you get to know you way around symfony. Php is something I feel comfortable using and know my way around. I use it for all my web sites. The reason I am learning python is to use the app engine. It looks like a cleaner language then php and seems to be slightly more powerful. I think it would come down to 1) does your developer know php, python, or both? Let him develop in whatever language they choose. 2) where are you gonna do with it? I think there's a time and place to use php and to use python.
- GeneralMaximus 16y agoSome perspective if you're using Python: I've mostly done desktop apps (ObjC + Cocoa and C++ + Qt). Some time ago I decided to learn web programming. I'd been programming Python for quite some time so, unsurprisingly, I started learning Django. I never felt at home with the framework. This might just be me, but Django has too much magic -- which can be disconcerting if you like to know exactly what your framework is doing behind the scenes. A month ago I started dabbling in Pylons. It's the best framework I've ever used. The Pylons Book is great, if a bit outdated. The official docs are nice (they seem nice to me; I've been burned by Apple's shitty documentation). The entire framework basically consists of glue code to tie together best-of-breed Python libraries: Mako, SQLAlchemy, Beaker, WebOb, PythonPaste, FormEncode, HTMLFill, Routes. Oh, and it's all WSGI. WSGI is the best thing to ever happen to Python web development. You should at least skim the WSGI PEP (PEP 333) if you're serious about Python web development. Next, I'm planning to check out Werkzeug. It's an even tinier set of libraries that allow you to, in effect, build your own framework. If you're building a simple REST-based service, Werkzeug is what you need. I also know some people who swear by Web2Py. I haven't tried it myself, but I hear it's great for quick and dirty webapps.
- gte910h 16y agoIt entirely comes down to who knows it (so when you hire, what type of people you get). PHP has a lower skilled mean programmer who does it. This is not necessarily a bad thing if cheaper programmer is better than better programmer for your company. PHP is easier to get going, python has more compelling libraries once you do. Python libraries are often better maintained than their PHP brethren, and the debugging stack for python is much more compelling.