TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask YC: Python vs. PHP

35 pointsby symbioticabout 17 years ago
So far I have done all of my web programming in PHP. I've also recently learned Python and so far I find the syntax to be annoying (that might be because I'm just used to PHP). But I've heard a lot of buzz on these boards about using Python. Can anyone give me the quick laundry list of advantages/disadvantages for each?

19 comments

dmpaytonabout 17 years ago
As someone whos only significant experience is in PHP and Python, I hope I can be of some help. I started with PHP when was 13 or so. When I was about 18, I discovered Python, and haven't looked back since.<p>PHP is designed primarily as a web language. As such, it's pretty simple to get it up and running which is great for new web developers. The language itself, however, is pretty bad and programming concepts beyond syntax are better left to other languages. That said, I learned a lot with PHP and I think that dealing with it's idiosyncrasies and pitfalls has made me a better programmer overall.<p>Python, OTOH, is a general-purpose language that has recently gained popularity as a web language. It has greater applicability, but it's a little more difficult to get up and running on a web server. It's great for a new programmer, but not necessarily a new web developer. Since you already have a bunch of experience developing web apps, this is probably a non-issue.<p>We can debate advantages and disadvantages of the two languages all day. In the end, everyone is different and everyone has their own preferred language. Obviously, my language of choice is Python, Paul Graham is a LISPer, and I know someone who swears by PHP, even though he's used Python and Ruby/Rails. It doesn't matter. I say go ahead and give Python a shot. The worst that will happen is that you've added another tool to your toolbox.
rguzmanabout 17 years ago
<a href="http://xkcd.com/353/" rel="nofollow">http://xkcd.com/353/</a><p>Now more intelligently. It is very expressive (little code says a lot) and the code is really easy to read. If you already know how to program it takes a few hours to get your feet wet and from there the "batteries included" philosophy makes it easy to start writing real python.<p>More technically, my favorite features in no particular order:<p>- list comprehensions<p>- functions as first are first class objects (you can pass functions around just like any other piece of data)<p>- functional programming tools<p>- indentation determines scope (some dislike this, I don't like curly braces), and this makes the code look nice<p>- slice notation<p>- powerful native data structures (lists, dictionaries, sets)<p>- <i>args and </i>*kwargs<p>- awesome standard library<p>I could probably keep going...
评论 #157732 未加载
jamongkadabout 17 years ago
Oh this seems interesting and I hope that unlike Reddit posts about PHP this will not degenerate into another flame post. So first off I would initially recommend using PHP as it is something you already know. Learning Python is cool(although I must confess I'm more of a Ruby user) but in the interest of getting something up and running quickly. And factor in that you already know PHP.<p>It would do you some good to learn a good PHP framework to rapidly build your app and get something out there immediately. A framework not only makes you look smart but it requires you to write code that does not merit you getting stabbed in your sleep. Ergo good PHP code.<p>Now we can all wax rhetoric that PHP does not support Functional idioms, brain dead functions, and name spaces. But in the interest of rapid prototyping and ease of deployment PHP comes first in mind. PHP frameworks now most notably Symfony(used by Yahoo to rewrite Delicious), CakePHP, Akelos, Kohana and my personal favorite CodeIgniter changed my opinion of PHP. You can easily abstract away logic using these frameworks. And they picked out some functions out of PHP's bewildering list of functions so that you have a solid base to work with.<p>So in a nut shell it's possible to write good PHP code but you have to exercise some discipline for it not to turn into spaghetti code.<p>Another reason you might want to carefully choose a language is the type of application you want for it. Let me explain, my company makes web based applications that customers can host within their corporate server. Now I don't want to waste much time trying to configure the server to run a specialize application. In fact I need something that can be installed and used right away in the shortest amount of time. So my choice of using PHP is more of a business decision as well.<p>So just weigh things out and ask yourself what do you wish to accomplish. Right tool for the right job.<p>edit: oh please consider reading this book <a href="http://www.manning.com/reiersol/" rel="nofollow">http://www.manning.com/reiersol/</a> makes a good study on how to write good PHP code.
luxabout 17 years ago
Python is certainly the more flexible of the two languages, but if you're really familiar with PHP you may be able to write your app faster in it and get it out there faster. But there's also long-term time savings to consider as well...<p>I haven't really done much in Python yet unfortunately, but I've worked quite a bit in Perl, PHP and Ruby, and personally I don't find any of them mind-blowingly different from one another, syntax aside. Some have more succinct syntax for looping and other things, but no major paradigm-shift IMO (like the one from imperative to functional).<p>Most of the complaints against PHP (just like MySQL) are about things that were solved years ago, but continue to linger on anyway. I like to think of PHP not so much as a language though, but more as a wrapper around C with memory management and a more flexible type system. Looking at PHP that way shows why many of its inconsistencies exist (e.g., in function names). It's also of the "structure is optional" philosophy, which requires more discipline to code well in.<p>Anyway, I think it comes down to figuring out whether it would save time now and later to use PHP or Python.
评论 #157681 未加载
评论 #157655 未加载
评论 #157643 未加载
jmtullossabout 17 years ago
PHP:<p><pre><code> - Easy to deploy on a webserver - Easy to integrate with HTML (good for small sites) </code></pre> Python:<p><pre><code> - Not ugly - Real and consistent object system - Better documentation than PHP (even though PHP's is good) - More consistent libraries - BDFL (PHP is an unregulated mess) - Good C API - Excellent web frameworks - Excellent desktop app support - Very cross platform compatible - http://www.python.org/dev/peps/pep-0020/ - It makes me smile</code></pre>
评论 #157942 未加载
doubleplusabout 17 years ago
<a href="http://wiki.w4py.org/python-vs-php.html" rel="nofollow">http://wiki.w4py.org/python-vs-php.html</a>
评论 #157742 未加载
paulgbabout 17 years ago
I know Python's indentation is a big turn off to most people coming from another language; it seems almost invasive of the interpreter to pay attention to whitespace. But you get used to it, and it becomes quite nice.
评论 #158075 未加载
dazzawazzaabout 17 years ago
I developed my first web app last year. I decided to use python as I already knew it. I didn't find python got in the way at all. In fact MOST of the code for the site is in preprocessing data and python worked equally well for that as it did serving content. PHP developers I've spoken to say that while PHP could have done the processing, python was a better choice.<p>Just thought I'd mention that.<p>good luck.
brentabout 17 years ago
The syntax that you hate will grow on you. If you're like me, at some point you'll wonder why other languages do not use whitespace effectively. It may be annoying at first, but when you revisit code later it makes it much more readable imho. If you're referring to other syntactic details, many grow on you, but luckily there is a fair amount of flexibility in coding style.
tptacekabout 17 years ago
I find this to be a useful assessment of PHP:<p><a href="http://www.tnx.nl/php" rel="nofollow">http://www.tnx.nl/php</a>
robabout 17 years ago
I found PHP to be easier to deploy. It might (because I'm not sure how much memory Python apps with mod_python or mod_wsgi really take) also be a better choice if you're making multiple sites and don't have a lot of memory on your server (e.g., 256MB VPS) since it doesn't take up too much memory.
chaostheoryabout 17 years ago
for me (compared to php) python is easier to debug and it's easier to organize and abstract your logic.<p>not to mention I think there are cooler libraries out for python than for php, and it's more versatile (desktop apps, utility scripts) instead of just being web-centric
symbioticabout 17 years ago
Thanks for all of the comments. doubleplus' link was particularly helpful. I should clarify that I already have a prototype in PHP and was thinking about switching to Python for the beta/release version if it seems worth it.
inovicaabout 17 years ago
It depends what you want to do with it ultimately. I use both - generally PHP for web-based front-ends and Python for heavy lifting (crawlers, text processing etc)
jskinnerabout 17 years ago
Also, consider that Python has a lot more non-web uses that PHP does. You'll derive more benefit from Python proficiency than PHP.
wallflowerabout 17 years ago
Google App Engine<p>Python: +2
评论 #157822 未加载
andreyfabout 17 years ago
Learn it and find out ;)<p><a href="http://docs.python.org/tut/" rel="nofollow">http://docs.python.org/tut/</a>
sabatabout 17 years ago
Sigh. I cannot in good conscience support a language in which an indent has semantic value. It's just not right.<p>:-)
theoutlanderabout 17 years ago
What about Ruby?