

Abandoning PHP for Python - marklit
http://techblog.stickyworld.com/abandoning-php-for-python.html

======
mgkimsal
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
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.

~~~
mgkimsal
To be fair, it's pretty hard to refactor existing spaghetti PHP in to any
comprehensive framework, at least production systems within a company with
deadlines and customers.

~~~
debacle
Is that something intrinsic to PHP? It's hard to refactor any code when you
have no time allocated to maintenance.

~~~
mgkimsal
I do think it's a bit harder in PHP, given the nature to which it allows for
spaghetti code to happen in the first place. Certainly it's never easy in any
platform, of course; I do think "bad" PHP is harder to refactor than "bad"
other code. Just an opinion, of course.

~~~
debacle
Any particular reason? You can do fewer terrible things than you can do in
Perl, C, C++, etc.

------
endijs
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
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.

~~~
johnpowell
That or the referral codes on your links to Linode and Digital Ocean.

~~~
cujo
Yeah, god forbid he have links that generate revenue for him. For shame!

------
JonoBB
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
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...](http://framework.zend.com/manual/1.12/en/coding-
standard.html)

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

~~~
jtreminio
The majority of the community[0] _are_ following the FIG standards.

3rd party PHP libraries have become _so_ much easier to read in recent years
thanks in large part to the work of the FIG.

[0] - Majority of community being major players like most frameworks and
almost all of the most popular libraries.

~~~
yareally
Good to know they're finally going for uniformity. I was mostly referring to
the average developer whose code you might read at work or from some code one
might find on Github.

Major frameworks and libraries going in that directly though is still a very
good thing.

------
mynameisme
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.

~~~
eugenesia
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

~~~
marklit
I'm the author of the blog post. If the question is related to why I dropped
PHP it's because I was getting a lot more done in Django and Tornado so I
could finish projects quicker and take on more work.

There were so many clients in need of Pythonists in London in 2011-2013 when I
was working there that I didn't have the time of day to take care of PHP ones.
Also, PHP rates were dying and there weren't a lot of people competing for the
Python work so I could keep my day rates nice and juicy.

I can think of a lot of things that beat Zend, Yii and Drupal in terms of code
management, security, DRYness of code that's implemented, flexibility, the
list goes on.

------
tariqr
"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
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 ...

~~~
marklit
I came across this gem for listing and installing packages in Ubuntu yesterday
in a way similar to pip:
[https://github.com/progrium/buildstep/blob/master/stack/prep...](https://github.com/progrium/buildstep/blob/master/stack/prepare#L9-L11)

~~~
pekk
You can use pip for system packages. But either way, this means you don't get
any of the advantages of virtualenv which were just described.

------
morkbot
"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/](http://getcomposer.org/)).

~~~
mgkimsal
given that it's < 2 years old and _still_ labels itself an 'alpha', many (
_most_?) projects might not be using it yet.

~~~
jtreminio
Incorrect.

Have a look at [http://packagist.org](http://packagist.org)

~~~
mgkimsal
What's incorrect?

That it's labelled alpha by the developers?

[https://github.com/composer/composer/releases](https://github.com/composer/composer/releases)

That it's barely 2 years old?

I'm not sure what pointing at packagist proves. There's a lot of packages
published for it. Great. _THE_ most popular package installed via packagist's
counters is Doctrine, at 1.4 million installs. It's a lot, but compared to all
the PHP installs out there, and all the PHP _apps_ out there that _aren 't_
using composer (because it's alpha and not very old yet, my conjecture) dwarf
the 1.4 million installs of a program via packagist. I'm probably 20 of those
Doctrine installs myself.

I was referring to the statement "Any serious, modern PHP project uses
Composer". There are loads of 'serious' PHP apps that don't use it, or may
only be adopting it now. If the definition of 'modern' means "has to use
composer", then, of course, "serious modern PHP projects" use composer.

I personally know people who aren't allowed to rely on it yet in their
companies because it's still labelled 'alpha'.

------
aviraldg
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](http://www.paulgraham.com/avg.html)

~~~
adamors
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.

------
ing33k
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](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](https://packagist.org/search/?q=REST)

Evented Codebases : PHP does have some tools to do the achieve the same result
[http://reactphp.org/](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
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
"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
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.

~~~
marklit
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.

~~~
deckiedan
Yeah. Pretty much all new projects I do are python (flask, actually), but I
still can see a place for very simple PHP scripts - which I think was it's
initial intention, and which it can still do.

The same for sh/bash. It's great for very simple automation/scripts, but after
certain level, it's much much easier to use a language which helps you write
maintainable code and doesn't actively try to stop you.

------
gremlinsinc
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
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
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.

~~~
aidos
Cool - which course is she taking? This is the Computational Investing course.
Buried very deep in a forum is a post by the tutor saying that you should know
programming and how to use the command line - unfortunately it's too well
hidden.

The main struggle has actually been with people on OSX Lion getting the
libraries installed.

[https://www.coursera.org/course/compinvesting1](https://www.coursera.org/course/compinvesting1)

~~~
Rossimac
On the introduction page of this course it states, "This course is intended
for folks who have a strong programming background, but who are new to finance
and investing."

Hardly well-hidden.

~~~
aidos
I stand corrected. Maybe there should be a test to weed people out early then.
Dunno - there are a few too many people on the forums who don't know the 'cd'
command.

I was referring to this little quiz [1] which I thought should be posted
directly in the description to scare people off.

[1] [http://wiki.quantsoftware.org/index.php?title=Compinvesti-
pr...](http://wiki.quantsoftware.org/index.php?title=Compinvesti-prog-quiz)

~~~
Rossimac
Definitely a bit more computationally intensive than I would have imagined it
to be. That's a bit of a challenge even for some with a CS degree!

Cheers for pointing this course out, though. It's right up my street.

~~~
aidos
Great! Very interesting stuff (as it's all new to me).

------
kayoone
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
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.

------
spellboots
Obligatory link to [http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-
de...](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/)

------
virtualwhys
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
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
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.

------
methodin
I dare say, it doesn't appear as if this person has been keeping abreast of
the latest PHP trends. FIG standards go a long way and Composer is a godsend
(prior to that I wanted to tear my hair out all the time).

------
crackedscreen
I abandoned Java, C#, PHP, Python, and Ruby for F#, Lisp, Scala, & Haskell.

------
PaulHoule
Hey, did you switch to "Python 3" or "Python 2"?

~~~
marklit
2.7 originally. Django became a big focus of my early contracting days and
support for 3 wasn't in yet.

