views:

307

answers:

8

I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.

Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform. Edit 2: I'm hoping for objective answers, like a specific project, not a general field of projects, etc.

+14  A: 

Python is better suited for practically anything that doesn't fall within PHP's specialty domain, which is building websites.

If you want a list of programming projects that you could work on, see this thread: http://stackoverflow.com/questions/1022738/i-need-a-good-programming-project

Nate C-K
I'm a PHP programmer by profession, and could only +1 this. Python is a better language.
just somebody
I've also done both (as well as .Net, java, actionscript, etc, etc...).I'd pick Python for just about anything, just about any time, if given the choice and it's a green field project (i.e. there aren't already mountains of PHP code to work with)
Paul
An example project where both could be done but you'd choose python?
Citizen
@Citizen: It sounds like "anything" provide a nearly infinite domain of examples. Since we don't know what you actually might do that's not website development, it's really hard to pick something from that nearly infinite set that would resonate with you. How about you update your question with specific examples from your worklife so we can comment on them rather than guessing.
S.Lott
@Citizen, ok, examples:Any project that is already started and/or needs to use an existing PHP framework/library/app due to Non-Functional Requirements (e.g. customer is used to WordPress already), that would be a project I'd pick PHP.Any project that does not require PHP due to the above reasons, I'd use Python for.
Paul
+3  A: 

A project you want to maintain over any length of time.

I've had to maintain PHP code and there is something about the fact that you can mix HTML and code that makes PHP stuff a nightmare.

Python has a much higher level of abstraction and makes more maintainable code much easier to write and much more importantly for maintenance - read.

All IMHO of course as this is a rather subjective question.

Nick Craig-Wood
Sounds like you're comparing bad PHP code to good Python code. If a mix of code and HTML results in a nightmare (which is very true) don't do it.
kemp
These aren't inherent properties of the language. It's up to the developers.
Jordan Ryan Moore
[on HTML/PHP mix] Oh G-D yes. @Jordan is right, it's up to the developers, but I'm working with code that randomly intersperses HTML, PHP and Javascript in the same file. If I didn't shave my head, I'd be tearing my hair out!
Brian Postow
@Kemp that's probably true. But I've never seen bad Python code to the badness of the bad PHP I've seen. Then again, I've never seen bad PHP to the level of bad Perl so it's all relative...
Brian Postow
This further highlights that PHP makes it too easy to do things the wrong way. If it is pretty much widely considered that intermingling HTML and PHP code is "bad" (which it is), then it shouldn't be possible to do it. And that is where Python shines: separation of duties.
jathanism
Properly speaking, this clean separation of code and markup is a property of web frameworks built in Python, not the language itself. It is certainly very possible to mix HTML with code in Python; I could write a CGI script that does it in about 2 minutes. The thing about PHP is that it has a single web framework that is its the web framework is its raison-d'être -- as evidenced by the fact that practically nobody uses it in any other context -- whereas a Python framework is just another member of a wide variety of Python applications.
Nate C-K
@synack: well it **has** to be possible since PHP is basically a template engine so it must work together with HTML.Also, forcing things does not necessarily solve problems: a bad programmer *forced* to separate code from markup will surely fuck up somewhere else.
kemp
+1  A: 

Anything that requires background processing or any significant amount of code that doesn't just show a user a page. Python is really good as a scripting language, and writing a command line Python script is commonplace; writing a PHP script to do command line work is rare.

Dean J
Actually, I do it all the time. But I guess I should probably be using Perl for those things...
Brian Postow
Honestly, use whatever works. :-) I write most of my scripts in Java, which certainly isn't the "best" way to do it, but is by far the fastest for me.
Dean J
+3  A: 

I am going to answer based purely on ease of programming and encouragement of good design practices.

I learned to program using Perl and for many years wrote web applications using CGI, which was never pleasant in the first place. I always found that Perl was tedious to get right and way too easy to get wrong.

When I started developing web applications more seriously, I discovered PHP. Going from Perl to PHP was a natural progression because they share many of the same methodologies and syntax. I loved that PHP was so heavily installed and widely used and was much easier to code in than Perl. Except, like Perl, PHP makes it way too easy to do things the wrong way, and ushered in a new era of poorly-written and insecure web applications.

Now... Four years ago I discovered Django, which was in its infancy at the time, and it changed my life. I used this as the motivation to learn Python and have not looked back, not once. I use Python for everything now:

  • System programming (server configurations, monitoring, alerting)
  • Network programming (router/switch configuration automation, auditing, syntax checking)
  • Web applications (self-explanatory)

Python's ease of use, elegant syntax, and the fact that it encourages best practices by default is what turned me on and kept me interested. Give Python a shot, you won't regret it!

jathanism
+4  A: 

PHP for websites. Python for pretty much anything else, such as commandline tools, long-running scripts, daemons, etcetera. If you're writing a PHP script and you're reaching for functions in the posix extenstion, shared memory or other low-level stuff then that's generally a sign that Python would be better suited. It's not that PHP can't do it, but Python just does it better and less buggy.

Especially when you're venturing into background daemons for your website you'll want to look at Python. PHP has some garbage collection problems in long running processes such as daemons. Also, some functionality is much easier and clearer in Python (e.g. redirecting STDIN, STDOUT and STDERR. PHP misses posix_dup2()). Also, Python has threads :-)

The only time when I now use PHP background daemons for my websites is when they can re-use significant amounts of code (such as with MVC frameworks like CakePHP).

One more advantage of Python is that there are many, many libraries for it, because it's rather easy to create a Python wrapper for a C library. So, Python has libraries that PHP doesn't have (OpenGL, multimedia, etcetera). So if you're into those areas Python becomes the obvious choice.

Sander Marechal
Thumbs up for your real world answer free of fluffy, squishy emotions. ;)
jathanism
+2  A: 

I only use php for the following reasons:

  1. The software I'm using that solves my problems is written in it (like Wordpress. Don't try to program everything, sometimes you have a lot of good stuff in php);
  2. I need/want to run in a lot of different server configurations (a lot of people use shared hosting, and can't install/don't have support to python, but php is a default in any web hosting company);

When I can choose (I have server environment control and I don't mind factor 2) , I choose Python. Just because you can write good code in php doesn't mean you should. I miss a robust language, with good Exception handling and a lot of other advantages. The language is clean and you can even use Google App Engine for free if you want to learn Python.

You can write almost everything you write in Python with PHP. But I dislike PHP because a lot of times you use a feature, and you know that you have to configurate your php.ini, or use an obscure function just after having a lot of headaches with the feature.

IMHO, at least in my experience, PHP is something you get used it. And Python is something you just fall in love: because it just works.

I know these last paragraphs may be a personal opinion, but the first two factors aren't. Just choose the language what you think it's worth in that case.

GmonC
+1  A: 

My company was contracted to build a web application last year, and the client specified that it should be done in Flex. Now, this application should have been a web application, but we had a unique opportunity to try something new.

We had absolutely no idea what we were doing at the time, but it was a great learning experience. My advice would be to try something new when you get the chance, make mistakes, and continue to learn.

Might be harder if you want to learn Python casually... Try getting someone to pay you for using it.

Kevin
+1  A: 

If you're doing any multi threading development, pick Python over PHP.

sjobe