top | item 6392209

Abandoning PHP for Python

67 points| marklit | 12 years ago |techblog.stickyworld.com | reply

82 comments

order
[+] mgkimsal|12 years ago|reply
So... OP worked on a team of people who didn't care about good code, and were using PHP. It probably happens with PHP more than other platforms, but I've worked on teams who did crappy Java and crappy Perl and crappy ASP too.

Bigger takeaways - working in a situation where you get to choose your own tools and be self-directed is probably a better fit for this person. When he works on a team of 3-5 other people who want to do different things in his Django code, there will be tension. Probably not as much as his PHP monstrosity, but there will be some.

Working with large established frameworks, it's hard to see one file have JS, HTML, raw SQL, ORM code and core PHP app logic all in the same file. The conventions dictate where/how to separate.

The OP likes that separation, likes conventions, and wants to move to Python. Great. However, I feel the benefits he's going to get are coming more from a greenfield setup and working alone vs the language or framework itself.

Also, typo alert: the word is 'resonate', not 'resinate'. ;)

[+] adamors|12 years ago|reply
Yeah, I'm getting the feeling that the OP has no idea of PHP frameworks (or anything that has happened with PHP in the last 5+ years for that matter), and prefers to throw the baby out with the bathwater because of this.
[+] est|12 years ago|reply
Python encourages you to write clean code.
[+] kayoone|12 years ago|reply
Exactly..take Symfony2 for example, which creates clean and maintainable PHP code using very modern methodologies. You have package management, ORMs, ODMs, Template engines, coding standards and a huge community that produce high quality Bundles (like plugins) that you can integrate into your project. Id even argue its better than Django or Rails nowadays.
[+] badman_ting|12 years ago|reply
Who didn't see this response coming? I'm sure it is possible to write decent PHP code, but it's funny how that never seems to actually happen.
[+] endijs|12 years ago|reply
What I got from this was - he ditched PHP not because it's impossible to write good code with it, but because it's possible to write crappy code with it. And that messed up code is result of bad team, not bad tool. But yeah - you can feel that I'm PHP dev and if that will result in HN down-votes, so be it. But I had to express my opinion.
[+] marklit|12 years ago|reply
What I was most hoping to get from this blog post is to encourage PHPers to give Python a go. Try it out, build something in it. I think lowering the amount of bespoke PHP code in the wild would help the software industry as a whole.
[+] TylerE|12 years ago|reply
I would go farther and say PHP makes it easy to write crappy code. Much harder to screw up in Python than PHP. Can you do it? Yes, but have to actually go out of your way to it, as the "easy" way is 99/100 the correct way, or will at least will fail hard and fast. That is where PHP errs, and something Go gets right. Code should either work or error ... warnings are a code smell, and PHP is very warning happy, including things that are an error in pretty much any other language, like accessing an undefined variable.
[+] tpetry|12 years ago|reply
it's more like the abandoned PHP because they had a crappy years-old codebase. And start developing in a new language (Python) with a new codebase which is not years old and they can design correctly. And in about 4-5 years they abandon python because they've got a crappy python codebase...
[+] JonoBB|12 years ago|reply
I can't help but get the impression that the author has not kept up with recent developments in the PHP world.

Python has PEP-8. PHP has FIG. Not as ubiquitous, but its getting there.

"There is package management in PHP but I never found any code bases in the wild using it to the same extent as PIP". Wait, what? Just about everyone uses Packagist and Composer these days.

Also, isn't is pythonista, not pythonist?

By the way, no disrespect to Python, which I use as well. There are arguments for preferring python over php in some circumstances, but most of the reasons given in this article lack validity.

[+] yareally|12 years ago|reply
I never actually heard of FIG and have been using PHP for quite a few years. Are they new? I don't follow PHP news as close as I used to with having to use other languages more often so perhaps that is why. Only standards I was aware of for PHP are those that Zend[1] gives.

edit: Looking at the guidelines on FIG, they really should take some cues from PEP 8 and make the writing style look less hostile and less RFCish², if they want a majority of the community to willingly read it.

Discussing it with a fellow PHP developer looking over the FIG guides, he said it best (by quoting PEP 8):

"A Foolish Consistency is the Hobgoblin of Little Minds"

[1] http://framework.zend.com/manual/1.12/en/coding-standard.htm...

²Nothing against RFC and the format works for what they are trying to accomplish. It doesn't work so well for coding guidelines though.

[+] mynameisme|12 years ago|reply
I love picking on PHP as much as anyone else, but you can write just as terrible code in Python as any other dynamically typed language. Those Django and Rails projects can grow into monstrosities as well.
[+] Daishiman|12 years ago|reply
Perhaps, but while the PHP community will debate endlessly about standards and projects inevitably end up become a pile of inconsisten spaghetti code, the conventions in Python make uniformity the path of least resistance, at least by an order of magnitude.

Also, while Rails is in the same league as Django as far as tools and expressiveness go(expressiveness perhaps more so), Django goes to considerable lengths to enforce style and consistency; it is not taboo to politely tell people that their code is not PEP8 compliant.

[+] eugenesia|12 years ago|reply
Instead of choosing one over the other, why not choose both? I specialise in both PHP and Python. For web projects on commodity hardware, nothing beats PHP, especially when used with powerful frameworks such as Zend, Yii or Drupal. For installable programs or scripting, Python works well with wxPython.

>> Quoted from article: "It was around this point that I decided I'd rather be an unemployed Pythonist than an employed LAMP developer."

Sorry man, I'd rather be an employed LAMP developer, but with a few side projects in Python. It's just a programming language, not a religion. :D

[+] dtoma|12 years ago|reply
Of course you can, but I think choosing between various languages mostly ends up being a matter of taste. I tried PHP, built a rather large website using it and found out I didn't like reading my own code after a while - a problem I have not encountered yet using python. I don't think this kind of article should be taken as a list of reasons that make python better than PHP, just as a reminder that maybe you could have a look at python if you do not enjoy writing your code in PHP.
[+] tariqr|12 years ago|reply
"Abandoning KungFu for Taekwondo". Both are means to an end (or survival).

I agree that there is a large number of bad php code/coders out there, but you can write and build beautiful, fast and well designed codebases with PHP just as well.

Like the martial arts, the barrier of entry is very low. The black belt, however, takes perseverance and years to earn.

[+] irahul|12 years ago|reply
I am not very familiar with PHP dependency management. If you are using Python, you should use virtualenv. Apart from providing you a repeatable development environment, it also enables you to use 2 versions of the same library in 2 different projects.

I deploy within virtualenv mainly because I use the same machine to host multiple services. I sometimes use requirements.txt.freeze(pip freeze -l requirements.txt > requirements.txt.freeze) for production deployments, but in the end, I find specifying versions in requirements.txt itself more convenient.

If you are building async services in python, have a look at gevent and learn the basics of event loops. gevent abstracts the event loops(there isn't an explicit loop) but there are cases where you are better off rolling your own select/epoll loop. Also, the article paints too rosy a picture - "I've built backends that do authentication, query a few million rows in Solr and return JSON in a couple of milliseconds thanks to Python" If you structure your applications properly, and your application is IO bound, you can get good performance out of Python. But it goes without saying that Python isn't a performance powerhorse. You might need to replace CPU intensive services with some other language or write a c extension or write cython ...

[+] ihsw|12 years ago|reply
Dependency management in PHP is generally done through Composer.

http://getcomposer.org/

There is no analogue to virtualenv, and dependencies are loaded into a directory rather than somewhere in the operating system.

[+] morkbot|12 years ago|reply
"When was the last time you looked at a PHP project and saw a list of all the third-party libraries and respective version numbers being used written in a single file?"

Huh? Any serious, modern PHP project uses Composer (http://getcomposer.org/).

[+] mgkimsal|12 years ago|reply
given that it's < 2 years old and still labels itself an 'alpha', many (most?) projects might not be using it yet.
[+] aviraldg|12 years ago|reply
I think everyone defending PHP, saying that it's as easy to develop well in it as in Python, is missing a valuable point: that owing to PHP's reputation as a "web dev intro language", there are far more inexperienced and incompetent PHP developers than Python developers.

See also: http://www.paulgraham.com/avg.html

[+] adamors|12 years ago|reply
I think that people defending PHP are getting a point you (and OP) are missing: both PHP (the language) and its ecosystem matured a great deal in the last 2-3 years.

A lot of good ideas were either implemented into the language or ported over from other languages/frameworks. There are tools/frameworks that rival those in Python/Ruby land.

[+] kayoone|12 years ago|reply
So ? Bad/mediocre people shouldnt be hired then, no matter what language.
[+] debacle|12 years ago|reply
It's likely that there are also far more experienced and competent PHP developers than Python developers.

The PHP ecosystem is just vastly larger.

[+] ing33k|12 years ago|reply
I am glad that OP has found the ideal language for him, but not knowing what PHP is well suited for after working on 12 years sounds absurd.

Every PHP dev after working on it for few years will know that its not the best language out there, but they will also realize that using it they can get stuff done.

Regarding books : I have to agree on the fact that there are many crappy books out there related to PHP, and I have still not found the ideal reference book for my needs .

Package Management : while its true that there was no standard package management tool for php few years ago ( except PECL ), the situation is different now, composer has evolved now and has become very common these days. composer does have the system where one can put all the dependencies in a single json file to manage all the dependencies .

Django's first tutorial : just go through Symfon2's first tutorial and in my honest opinion it can give serious competition to that of Django's http://symfony.com/doc/current/book/http_fundamentals.html

RESTful and DRY : OP mentiones some libraries which are good for creating RESTful API's in Python, and Of course PHP has some high quality libraries to create RESTful API's.

https://packagist.org/search/?q=REST

Evented Codebases : PHP does have some tools to do the achieve the same result http://reactphp.org/

Deployments : no one can deny the fact that PHP is knows for its ease of deployment ( shared hosting ) , but any ony one serious about their app cannot go with shared hosting , but deploying PHP on a VPS/dedi is actually easier then deploying a Django App . and even modern deployment tools can Chef, Puppet, Ansible have wide support for PHP and its frameworks.

I am wondering that how just by switching to a language will make my code RESTful, DRY and more maintainable. In the end even Python/Django can be used to write crappy code.

Actually I was expecting more solid reasons to switch from PHP to Python ( There might be some too ) .

[+] anupkhandelwal|12 years ago|reply
Personally, I think language wars are silly. Languages are tools. Learning different languages only makes you better prepared for the market and give you greater freedom to choose from a wider range of the available jobs.
[+] jtreminio|12 years ago|reply
"When was the last time you looked at a PHP project and saw a list of all the third-party libraries and respective version numbers being used written in a single file..."

Are you serious? This is what your hate boils down to: you don't know the PHP ecosystem well, at all. It seems like you've been living under a rock.

Going to your 8-4 every day and hacking away at your company's codebase and not bothering to read up on the goings-on about your language will result in bad times.

[+] deckiedan|12 years ago|reply
Things I like PHP for would be single file simple scripts which are part of otherwise essentially static sites. For instance, a static blog (with Jekyll/Pelican/whatever) but a single .php file which is for searches (in a sqlite FTS cache of the blog, say) or 'related posts' or whatever. Then you can upload it into an apache "standard" web host, and add that tiny bit of server-side stuff that otherwise would be a pain.
[+] Supermighty|12 years ago|reply
For a lot of developers that single file explodes into a large multi-file monstrosity as features are added and deadlines are put ahead of refactoring.
[+] marklit|12 years ago|reply
Have a look at Sinatra and Tornado. Single-file projects are possible as well and it'll lead you down a road to quick deliveries and better tooling.
[+] gremlinsinc|12 years ago|reply
I was for the longest time enamored with rails and the income potential of becoming a rails Dev...until I had finished a small ecommence app that I wanted to deploy on a cheap Linux host like hostgator or site5...both of which do support rails but only specific versions and getting everything to work was going to be a nightmare.

that's when I decided I needed to find a globally method to deploy which brought me back to php. Which initially pissed me off cause I was Loving Ruby's syntax.

then I discovered laravel..and holy shit I finally learned how to be a good php developer and use namespaces and really build some awesome stuff. It is rails on php and a hundred times easier to deploy on just about any lamp stack.

[+] aidos|12 years ago|reply
I'm taking a Coursera course at the moment where a lot of people on the forums are new to Python. I've been trying to guide them in the right direction in terms of the Pythonic way of doing things which has been a very interesting experience. Lots of people turning to for loops 5 levels deep (or even worse - wrapping 5 for loops in a list comprehension).

This is a typical quote:

"I'm still a little bummed that python doesn't have the for(;;) C syntax"

I'm pleased to report that quite a few people have been impressed with how clean and simple the code is once they see the Python way.

[+] marklit|12 years ago|reply
My girlfriend is taking the python course with them as well. She said there were 60,000 in total taking it (sounds like there will be a lot of new Pythonists in 2013).

She and another friend of hers was having some troubles understanding when and when not to use parentheses and I did a quick clinic with them to walk through it.

It might be a good idea if volunteers from the Python community could be found to offer extra lessons, perhaps some sort of live video cast mixed with a live chat. It could help out a lot of people who otherwise don't have many people to call on around them.

[+] kayoone|12 years ago|reply
And again... That article has nothing todo with PHP vs Python, its just about choosing the right framework and methodologies. All of the pro python arguments can be had for PHP as well if you dont work in a spaghetti codebase.
[+] prostoalex|12 years ago|reply
Solution seems to be mostly about covering symptoms than addressing underlying issues.

"technical architecture of the code could change with a developer simply deciding to do things in a different way from the rest of the team" tells me there's no strong code review culture, or code discoverability, and you've simply moved the problem from a lower level to a higher one. While people might be adhering to Python idioms, they're probably not going to write the code that's idiomatic to the organization or make the best use of internal libraries.

[+] virtualwhys|12 years ago|reply
Didn't even bother with another dynamic language * , went straight to the JVM and discovered Scala (framework-wise, enjoying Play)

* not totally true, 6 months on Groovy, followed by 6 months of hell (AKA pre-2.0 Grails)

Can't speak for Python other than a couple of months of Django (out of the box CRUD functionality is indeed nice).

After a couple of years of Scala can't imagine going back to a runtime only language (other than Coffeescript/LESS via GruntJS for the front end)

[+] shire|12 years ago|reply
I'm currently learning Python from a PHP standpoint which is kinda exciting because Python is beautiful language and joy to work it. Do you know of any good Python books that cover 2.7? I know you mentioned Python Essential Reference I'll check that out as well most Python tutorials are outdated it seems.
[+] xr09|12 years ago|reply
I know there is Symfony, Laravel, Slim and the rest but what bothers me about PHP is the language itself. It feels clumsy, full of monkeypatches all over it, as the result of many different shools of thought.

On the other side Python feels like one mind's labour, it just fits togheter.