Citizen
Citizen

Reputation: 12927

From a coder's perspective, what kind of project should I choose python over php for where both could do the job?

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.

Upvotes: 3

Views: 685

Answers (8)

Nate C-K
Nate C-K

Reputation: 5932

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: https://stackoverflow.com/questions/1022738/i-need-a-good-programming-project

Upvotes: 16

sjobe
sjobe

Reputation: 2837

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

Upvotes: 1

Kevin
Kevin

Reputation: 13087

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.

Upvotes: 1

GmonC
GmonC

Reputation: 10970

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.

Upvotes: 2

Sander Marechal
Sander Marechal

Reputation: 23216

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.

Upvotes: 5

jathanism
jathanism

Reputation: 33716

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!

Upvotes: 4

Dean J
Dean J

Reputation: 40298

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.

Upvotes: 1

Nick Craig-Wood
Nick Craig-Wood

Reputation: 54079

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.

Upvotes: 3

Related Questions