views:

353

answers:

8

Hi! I'm planning on moving to Python and I have a couple of additional questions along with the title:

  1. did you have more fun with python?
  2. are you as productive as when you're using PHP?
  3. what made you change to python?
  4. Would you do a project again in PHP? If so, why?

Your answers would really be useful for us PHP devs wanting something more I guess :)

Thanks in advance!

+2  A: 
  1. yes
  2. yes
  3. curiosity, search for better languages, etc. (actually, I learned them somewhat in parallel many years ago)
  4. yes, if a project requires it explicitly

disclaimer: I never really moved from php.

The MYYN
+2  A: 

Well, I started with PHP, and have delved into Python recently. I wouldn't say that I've "moved to", but I do use both (still PHP more, but a fair bit of Python as well).

I wouldn't say that I have more "fun" with Python. There are a lot of really cool and easy things that I really wish I could take to PHP. So I guess it could be considered "fun". But I still enjoy PHP, so...

I'm more productive with PHP. I know PHP inside and out. I know most of the little nuances involved in writing effective PHP code. I don't know Python that well (I've maybe written 5k lines of Python)... I know enough to do what I need to, but not nearly as in-depth as PHP.

I wanted to try something new. I never liked Python, but then one day I decided to learn the basics, and that changed my views on it. Now I really like some parts (and can see how it influences what PHP I write)...

I am still doing PHP projects. It's my best language. And IMHO it's better than Python at some web tasks (like high traffic sites). PHP has a built in multi-threaded FastCGI listener. Python you need to find one (there are a bunch out there). But in my benchmarks, Python was never able to get anywhere near as as fast as PHP with FastCGI (The best Py performed it was 25% slower than PHP. The worst was several hundered times, depending on the FCGI library). But that's based on my experience (which admittedly isn't much). I know PHP, so I feel more comfortable committing a large site to it than I would PY...

ircmaxell
Why aren't you using `mod_wsgi`?
S.Lott
Quite simple, I don't use Apache. I use either Lighttpd or Nginx with a load balanced FastCGI setup (where there are multiple FastCGI Application Servers. And I think it would defeat the purpose to proxy from the frontend to Apache on the backend just to workaround Apache's bloat and the lack of a decent FCGI dispatcher in PY (not that I could write anything better)...
ircmaxell
+10  A: 

I was a PHP dev for about 5 years before switching to Python almost exclusively a year ago. The experience has been a mostly positive one; I'll answer your questions but also list a few gotchas I ran into.

  1. Definitely. I continually find surprisingly powerful features/expressions in Python that do a great deal in a small amount of code (yet still being more readable than Perl).
  2. Far more productive. It might just be my style, but Python's functional programming tools, generator expressions, list comprehensions, etc. allow me to accomplish tasks correctly with less code and less time invested than PHP.
  3. I had an analytics project that needed a powerful stats package, so I went with Python+numpy. Then I found Turbogears and loved the syntax. Eventually I discovered coroutines and cooperative multitasking, and there's no going back. I use bottle, gevent, and gunicorn to crank out lean, fast, scalable web apps in record time.
  4. Not if I could help it. PHP's verbose "everything is a long-named function call" syntax is just hard on my eyes at this point. I find it tedious to optimize as well (every page load reinterprets the source code in a default configuration).

Here are a few of the gotchas to be aware of:

  1. For cheap, low-traffic sites, it's much harder to find a web host with a good python environment.
  2. Apache isn't really a typical setup for Python in my experience. Python webapps are usually daemons that are exposed to the public with a reverse proxy webserver in front (nginx is very common). A number of corporate environments balk at new-fangled technology like nginx. It also takes some adjustment to think about your webapps as daemons, and it can take some effort at first to get your daemonizing correct and consistent.
  3. If you use mysql, you will have some pain switching for a while. There just isn't a Python mysql library that is highly compatible with PHP-style mysql queries. For example, most of them don't use the simple "?" syntax for parameterized queries, so you can't just paste your queries over (you have to use printf-style "%s", etc.). Also, just the fact that you actually have to choose and install a mysql library is an extra step over PHP. This no longer bothers me, since I don't use mysql anymore anyway.

This is a broad topic with much, much more to say, but I hope this was helpful.

sunetos
At least within the Django community, Apache and mod_wsgi is arguably the deployment approach of choice. If the framework you're using is WSGI compatible, I'd really recommend trying it out instead of messing around with managing daemons.
thraxil
It's better to use an ORM library in Python anyway, except for performance critical parts.
Imran
@Imran, that is a good point. I thought about going into the complications I had ramping up with SQLAlchemy, but my post was so long already.
sunetos
A: 

I've never really worked with PHP (nothing major) and come from the .NET world. The project I am currently on requires a lot of Python work and I must say I love it. Very easy and "cool" language, ie. FUN!

.NET will always be my wife but Python is my mistress ;)

Andre
my wife's your mistress?? - sorry, bad joke ..
The MYYN
Sh#t happens... soz, horrible joke ;)
Andre
+2  A: 

I'll try my best to answer your questions as best I can:

  1. Did you have more fun with python?

I really enjoy how minimalist python is, having modules with non-redundant naming conventions is really nice. I found this to be especially convenient when reading/debugging other peoples code.

I also love all of the python tricks to do some very elegant things in a single line of code such as list comprehensions and the itertools library.

I tend to develop my applications using mod_wsgi and it took some time to wrap my head around writing thread-safe web applications, but it was really worth it.

I also find unicode to be much less frustrating with python especially with python 3k.

  1. are you as productive as when you're using PHP?

For simple websites python can be less fun to setup and use. One nice feature of PHP that I miss with python is mixing PHP and HTML in the same file. Python has a lot of nice template languages that make this easy as well, but they have to be installed.

  1. what made you change to python?

I became frustrated with a lot of the little nuances of PHP such as strange integer and string conversions and so forth. I also started to feel that PHP was getting very bloated with a lot of methods with inconsistent naming schemes. I was referring to the PHP documentation quite frequently despite having a large portion of the php library memorized.

  1. Would you do a project again in PHP? If so, why?

I would develop a PHP project again, it has a lot of nice features and a great community. Plus I have a lot of experience with PHP. I'd prefer to use python, but if the client wants PHP I'm not going to force something they don't want.

GWW
+1  A: 

Last year I switched job to get away from PHP and work in Python. I'm very much satisfied with the decision I made :)

To answer the individual questions:

  1. did you have more fun with python?

Yes!

  1. are you as productive as when you're using PHP?

More productive I'd say. But the overall increased experience in programming also had something to with that.

  1. what made you change to python?

You are not expected to be a jack of all trades in non-PHP jobs. (Photoshop/Web Design/Flash is required for many PHP jobs, and I hate Flash). And I liked Python/Django a lot.

4. Would you do a project again in PHP? If so, why?

If it's small stuff that's better done without any framework, then yes.

Imran
+1  A: 

I run a self-developed private social site for 100+ users. Python was absolutely fantastic for making and running this.

  1. did you have more fun with python?

Most definitely.

  1. are you as productive as when you're using PHP?

Mostly yes. Python coding style, at least for me is so much quicker and easier. But python does sometimes lack in included libraries and documentation over PHP. (But PHP seems second to none in that reguard). Also requires a tad more to get running under apache.

  1. what made you change to python?

Easier to manage code, and quicker development (A good IDE helps there, I use WingIDE for python), as well as improving my python skills for when I switch to non-web based projects.

  1. Would you do a project again in PHP? If so, why?

Perhaps if I were working on a large scale professional project. PHP is so ubiquitous on the web A company would have a much easier time finding a replacement PHP programmer.

Zarneth
A: 
  1. did you have more fun with python?

Yes. Lot more.

  1. are you as productive as when you're using PHP?

No. I think more.

  1. what made you change to python?

Django.

  1. Would you do a project again in PHP? If so, why?

Only if it is required.