
Ask HN: Why Would I Write Web Apps In Anything Besides PHP? - citizenkeys
I recently considered moving all my web apps from PHP to something else, mainly because I was bored and it was an excuse to get proficient with another language.  However, the alternatives were not written with web scripting in mind.  Python and Ruby were both designed as stand-alone programming languages with web wrappers added later.  Beyond those two, I couldn't even think of a third language that was even worth considering.  So I stayed with PHP because PHP was designed specifically for web scripting.<p>My question is: What benefits are there to writing web apps in any of those other languages that weren't designed specifically for web apps?
======
thenduks
Eh, I don't really get your question here.

Why would you _rewrite_ all your apps with something other than PHP? You
wouldn't, of course.

Why would you consider a language that wasn't "designed specifically for web
scripting"? Because that's an irrelevant criteria for choosing a platform. It
makes no difference if something was(n't) designed for a single purpose, only
that it is effective for the purpose you require.

A third language worth considering -- how about JavaScript w/ Node.JS?

Benefits to writing web apps in a language other than PHP? Well, you get the
benefits of that language - whatever those might be. Benefits might include
anything from technical superiority (and what 'technical superiority' means is
based a lot more on the application than the fact it's web-based) to it being
easy to find developers who know a platform in your city when you need to
hire, availability of documentation, or even the general progressiveness of
the whole ecosystem (is new stuff happening? is there community interest?).

I think that discounting everything but PHP just because they aren't
pigeonholed into web apps (of course, PHP can be used for more than just the
web, but let's gloss over this fact) is pretty... close minded.

A counter question: if you like PHP and are productive/happy/etc using it, why
would you go out looking for new languages to replace it? You will only
discover that _they aren't PHP_.

~~~
PaulHoule
"designed specifically for web scripting" is worth a lot.

PHP's standard library has a function called htmlspecialchars() which escapes
special characters in HTML. If you don't use a function like this, your HTML
forms can be destroyed by ' and " characters and crackers can f- up your web
site by putting <script> elements on your pages.

There is no function like this in the Java standard libraries. Nothing like
this comes with JSP or JAX-RS. You can get one in the Apache commons lang
project, but a Java web developer who doesn't know this (or write his own) is
in deep trouble.

PHP is a great tool; it's creators have gotten many details right, and it
offers developers the chance to get started without running into gotchas. On
the other hand, other languages have things going for them too.

Ruby gems and Java's maven are incredible package managers that put PEAR to
shame. There's a lot of junk software written in Java, but some of the best
open source projects are there too. People are doing interesting stuff in web
frameworks in Python, Ruby, Java, C# and many other languages, even PHP.

~~~
ablerman
Who cares if it's in a "standard library", as long as it's available in a
library?

~~~
PaulHoule
but you have know about it, and Java programmers have a lot of things
clamoring for their attention. Programmers in all languages, including PHP,
fail to escape characters correctly. But PHP programmers have no excuse: you
can tell them what to do and they don't have to mess with the build system,
think about licenses, all that.

In a large Java system, you might find you're using 4 different JSON
libraries... because 2 of them are used by other Open Source projects your
project uses and 5 of your subteams picked 2 different JSON libraries.. Now
you've got to deal with bugs in 4 different libraries and if you're doing
cross-functional coding you've got to know the idiosyncratic APIs and you can
always get your panties in a knot about which library you should use in who's
turf.

PHP programmers use json_encode() and json_decode() and avoid bugs and wasted
time.

~~~
jshen
rails 3 makes strings safe by default. PHP doesn't.

~~~
SaltwaterC
Rails 3 is a web _framework_. PHP _isn't_. I am always puzzled by the apple to
oranges comparison: Rails vs PHP.

~~~
thenduks
I normally would agree. But I think this is a unique discussion because the OP
is asking why he should use something other than PHP. One might use Ruby
_because_ of Rails. So it's not a comparison of PHP and Rails directly, just
reinforcing the point that languages/platforms other than PHP (and it's
frameworks) are just as useful for web work as PHP is.

------
porter
Cleaner code, powerful libraries, frameworks with vibrant communities
(django/rails), and so you have friends to sit with at lunch. Really, it's a
personal preference. If you have existing sites in PHP and you're really
comfortable with it, why waste time porting things over? Go create something
new in the most efficient way you can!

~~~
riledhel
cleaner code is just a matter of coding standars, not a language feature.

~~~
ionrock
I agree that for the most part this is correct. But, I also would argue that
some aspects of a language can lend itself to more organized code. The include
statement is one example where I think PHP doesn't help keep code organized.
An actual module system with packages helps a good deal here.

------
akshaykarthik
One major advantage to using Python especially is the availability of many
libraries and apis. I think that the main reason for the growth of PHP (at
least in the beginning) was the good interface with SQL (LAMP). Now that there
are good alternatives (MongoDB, Riak, Redis, etc.), PHP's SQL support isn't a
must. I think that the simple nature of the ruby language is a good thing. The
code is easy to understand and the libraries aren't a mess _cough cough_.

All in all, it comes down to personal preference.

Personal Plug for Python: I have used python for some major statistical
analysis (over the web) and Django interfaces well with sciPy and numPy.
Python also has much better native access so R works well with it.

AFAIK: Node.js was written for webapps. Also javascript is interoperable in
most major browsers so you use the same language on client and server side.

Personal Plug for Node.js: I love node. It is really simple to use especially
with coffeescript and express. The tools available are constantly growing and
there are so many modules available. Also, node.js moves a lot faster with
major releases and updates as well as the availability of any existing
javascript library available.

~~~
ddagradi
This is the same advantage as Ruby - the community for both languages has been
more vibrant and interesting than PHP for years.

~~~
OstiaAntica
Hardly. The PHP Drupal community alone is bigger than Ruby and Python
COMBINED. Ruby is in decline and neither community has the innovation coming
out of projects like HipHop, Wordpress, etc etc.

PHP is a mature language and isn't trendy, but it is far more vibrant, broad,
and interesting than Ruby or Python.

~~~
sigzero
Where can I get some of that kool-aid?

~~~
PandaMilk
Get me some as well, installed ubuntu server today...

apt-cache depends a* | grep -c python: 18711

apt-cache depends a* | grep -c php: 1596

apt-cache depends a* | grep -c ruby: 2839

Not that it proves anything but it might be an indicator.

------
tshtf
There is no benefit.

PHP is great for doing rapid prototyping for web applications, and will
suffice even for the final version in most cases.

Most here are concerned with producing something of value, so if it's easier
to do in PHP, then do it! Your final product on the web will speak for itself,
no matter what framework it was written in.

------
gfodor
Good luck applying your PHP knowledge outside of the tiny sliver of software
engineering domain that is web apps. Learning Python and arguably Ruby (now
with JRuby out there) is a wiser long-term investment if you want to be able
to use your skills towards solving other types of problems.

~~~
ceejayoz
That's like telling a brain surgeon their skills are useless elsewhere in
medicine. True, perhaps, but still a pretty stupid argument. You can make a
pretty good living (and be perfectly happy and fulfilled) as a brain surgeon
even if your skills won't let you become a radiologist.

I'd love to hear why Python and Ruby are going to prepare you to solve all
sorts of problems but PHP isn't. The particular syntax isn't the important bit
of coding - the problem solving mentality is.

~~~
gfodor
It's a cultural thing and a library thing. I'm not well tapped into the Python
community (which seems to have a healthy breadth of work going on), but with
JRuby you have full access to the Java ecosystem which (needless to say) puts
you in the position to solve all kinds of problems beyond web applications.

Your analogy is flawed since people go to school to become brain surgeons with
the expectation of a life-long specialized career. This isn't the case with
most web application engineers, who usually have a more general computer
science background. You'd be hard pressed to find a PhD, our version of
specialization, whose dissertation focused on the types of problems PHP is
generally used to solve.

~~~
ceejayoz
> with JRuby you have full access to the Java ecosystem which (needless to
> say) puts you in the position to solve all kinds of problems beyond web
> applications.

Putting aside for a moment the fact that PHP is Turing-complete, are there any
examples of these amazing things you can do in JRuby that you can't do in PHP?
Even the JRuby wiki talks mainly about how awesome it is to be able to run
Ruby on Rails via a Java interpreter.

To extend the medicine analogy, being a surgeon isn't about how awesome the
particular scalpel you're using is. It's about knowing where and how to cut.
The same is true with code. Someone who's a really good coder in PHP likely
isn't going to have much trouble learning other languages if they so desire.

~~~
gfodor
Like I said, it's a cultural and a library thing.

First, the cultural.

PHP's community is largely focused on web applications, and has lots of folks
that do not have a background outside of PHP or web applications. The PHP
culture is generally one of "I'm not interested in understanding why its
broken, just give me the code to fix it." If you browse the PHP documentation,
you'll notice the comments are riddled with errors, bad advice, hacks, and so
on. It even bleeds into print, I'd argue "PHP: The Good Parts" is the worst
software engineering book I've ever read.

The Python and Ruby communities have their problems, for sure, but you're more
likely to find good advice and altogether more competent people when asking
for help there. There is a focus on constant improvement, elegance, and
craftmanship while maintaining pragmatism in the Ruby community that fosters
more of a joy for learning and building things than I think you'll find in
PHP.

On the library side, I can't speak for Python, but my point with JRuby is that
you have access to not only the Ruby ecosystem but the Java ecosystem. For the
purposes of arguing the breadth of applications I can simply stop at the Java
ecosystem, full stop, since it's arguably the largest set of libraries
available on a single platform ever built. To start, just look at the Apache
projects, Hadoop, Lucene, Solr, Mahout, and more give you access to state of
the art machine learning, IR, and data analysis algorithms that are beyond
your wildest dreams in PHP. And this, of course, is just the surface of what
is available to you.

~~~
SaltwaterC
Putting aside Quercus, a PHP implementation on top on JVM, Zend at least
provides a proper Java bridge into their Zend Server line of products,
including the Community version:
[http://www.zend.com/en/products/platform/product-
comparison/...](http://www.zend.com/en/products/platform/product-
comparison/java-bridge)

I tried to use Quercus, but besides templating, it pretty much blows at
everything else PHP related. <http://www.caucho.com/resin-3.0/quercus/>

Therefore this isn't a sole feature of the J-something language implementation
on top of JVM.

------
freshfunk
IMO, a language derives the most of its real-world utility from (good,
updated, relevant) supporting libraries. This is a great reason to learn
python AND ruby.

(Personally, I have a project where I'm debating the two. I've decided Ruby
for now but may move to Python. I hope I never do PHP again.)

~~~
Spyro7
I realize that this does not have much to do with the topic of this thread,
but I wanted to share a quick tip with you from the perspective of someone who
spent a fair amount of time debating Python vs Ruby.

I love Ruby because it is really an amazing language (and I knew about and
loved Ruby before Rails ever came into the picture). I also love Python - it
was the first language that I ever finished a major project in, and it is an
equally amazing language.

They are both similar enough to make favoring one over the other an extremely
difficult decision. At the same time, the differences between the two
languages are strong enough to make it so that you will miss the features of
one language when you choose the other.

I literally spent weeks agonizing over which one to choose for a major project
that I was about to begin. Finally, I realized that I would have to make a
decision if I ever hoped to get anything done.

In order to make my decision, I simply made a list of the libraries/modules
that would be helpful to me in completing my project. Then, for each item on
this list, I looked at the status of the pre-made solutions that were
available in each language. Where there was no library available in either
language I just crossed it off (I'll write it myself).

When I was done, I looked at the list and choose the language that satisfied
the most of my 3rd party library needs. For that project it was Python. When I
repeated the process for a different project, then it was Ruby.

The important thing was that I was able to overcome paralysis by analysis and
finally get some coding done. I don't know the size, scope, or nature of the
project that you are working on, but I hope that my experience is able to help
you in some way.

------
ryan-allen
I'd say a good reason to try writing a web app using other tools is because a)
you don't know why because you have no experience and b) lots of other people
are doing it.

Isn't that enough reason? While languages like Ruby and Python were not
designed 'with the web in mind', PHP wasn't designed _at all_. You won't
understand this until you've had some reasonable experience with real
programming languages. Enjoy!

------
MatthewB
I know PHP pretty well and enjoy it. I just started learning Ruby on Rails and
it is VERY fun. It is simple and with rails it is quick to launch apps. I
don't think i'm experienced enough yet to see the downside with RoR...but for
now I'm happy with what I see.

~~~
jarin
Most of the time, when people have problems with Ruby on Rails it's because
they fight with it instead of doing things "the Rails way".

It used to be that a big downside of Rails was deployment, but with things
like Passenger, Moonshine, and Heroku, deployment is a snap now.

------
charlesju
I've been building web applications for almost 10 years. I can build a Rails
app about 5 times faster than a similar PHP app. I know there might be some
PHP frameworks out there, but even with those in-mind, I would say Rails is
probably 2 times as easy to develop and deploy because of things like Heroku.

I know these are rough numbers from my perspective, but the efficiency and
effectiveness of the framework really adds up.

~~~
shykes
You can deploy a php app just as easily on dotcloud :) <http://dotcloud.com>

(Disclaimer: I work there)

~~~
ceejayoz
Even without things like dotcloud, setting up a PHP app takes about 15 minutes
on Linode/Slicehost. `apt-get install php5 apache2 mysql-server` and you're
about 75% of the way there.

------
yichi
To really answer your question you pretty much have to write your own
Django/Rails app. Why don't you give it a try in a new project?

~~~
iAmSpartacus
I would echo this advice as well. As a mainly PHP developer I have learned a
lot of cool ideas and techniques from Ruby on Rails that I have brought into
my PHP code.

For example, the idea of the "flash" and how to properly do MVC.

Just learning another language (programming or not) opens your mind to new
ideas and ways of looking at things. If those aren't reasons enough, then what
about increasing your work skills and marketability?

------
true_religion
Because modern web apps are more than just a thin layer over the database.

Here's my recent experience:

1\. An image server cobbled together using RabbitMQ, OpenCV, and Imagemagick.
ElasticSearch is used for title/description searches.

Sure this could technically be done in PHP, but 80% of the code has nothign to
do with the web in particular so its better to use a general purpose language
that was designed from the start to be that rather than PHP which was a domain
specific language that evolved to where it is today.

2\. Hedge fund manager using Quantlib and NumPy. There's no equivilent in PHP.
There's no easy way to interface with C-code. Cython and Cytpes make it easy.
Doing so in PHP means _hand writing_ a C-extension. I've done that before and
let me tell you the Zend Engine not a pretty thing to work with.

3\. Any project that has a rich client side interface built in javascript will
get gains from using Python over PHP. At that point your server is really just
a message backend controlled via REST or JSON-RPC.

------
zmmmmm
Productivity with PHP peaks near the time when you start your project (when it
is great and beats out a lot of other technologies) and without a lot of work,
goes downhill from there. Put simply, it is not designed to scale well in
terms of code size and complexity. It is very concrete and doesn't encourage
any use of abstraction by default. For some types of apps & sites this is no
problem and the simple and flat design of PHP will actually be of benefit.

There are frameworks that alleviate some of these issues (Cake, etc.) but they
are really compensating for the language deficiencies that cause the problem
rather than solving them. Other languages give you a little more overhead, are
a little more generic, but in return they give you far stronger tools to deal
with the complexity burden that (inevitably) hits at some point for many
projects.

------
cmelbye
If you're going to write a well-designed PHP web application (and that's
subjective, but I believe most people would have a similar idea of well-
designed,) you're going to end up writing or using a "web wrapper" (or in
other words, framework) anyways.

------
jschuur
For me the issue isn't whether another language or framework is better for the
job at hand than the tools you've spent time building up an expertise in. The
thing that matters is that you don't develop a closed mind which prevents you
from looking at ANYTHING else out there.

Evolving your sklls and constant learning is the hallmark of a good developer,
not whether they learn Rails or Python now. Curiosity and a willingness to
admit that something new and better might be out there matter more than pseudo
religious battles between ardent users of one or the other piece of tech.
That's going to keep you in software development for the next 25-50 years.

------
ianl
For me, I started using Python because I could write the front end (web-
facing) and back end code in the same language.

Meaning I can write back end services like mail server and share models and
other code across both.

You could argue that you can write back end services in PHP, however, it was
no designed with that intention and in my honest opinion it does not translate
very well because the infrastructure in terms of open source libraries just
don't exist as PHP is primarily a web language.

~~~
eropple
My experience is diametrically opposite to this.

What infrastructure and open source libraries don't exist for PHP?

~~~
risotto
Full stack web servers like Mongrel or CherryPy.

Server fabrication and automation tools like Chef, Puppet, Fabric.

Process management tools like God.

Parallel worker systems like Resque or Celery.

PHP is great for web apps, but the further I've gone into systems programming,
the more I need Python/Perl/Ruby (or C).

~~~
eropple
You are not answering the question that was asked. ianl's post was directly in
reference to web application development, not systems programming. Of course
you wouldn't do that with PHP. That's like saying "yeah, it's a great knife,
but it can't change my oil." Well...sure. Nobody's saying it can. But it does
what we're actually talking about just fine, and I am skeptical of ianl's
claims that there are missing pieces of the infrastructure _for web
development_.

(BTW: Puppet not playing nicely with PHP is new to me as I use it regularly.
And I don't think you get much with Mongrel that nginx/FPM don't do well
enough.)

~~~
mnutt
How about evented frameworks like Tornado (python) or Goliath (ruby)?

~~~
eropple
That's actually a good point, and I'm a big fan of Tornado and Manos (C#)
myself.

------
cconroy
It is interesting to think of a language specifically designed for web apps as
_different_ from a general-purpose language. This would of never occurred to
me unless I only knew PHP.

I suspect if you tried to make a good web app language it would look like ruby
or python, and really good web app language -- one very scalable -- look like
haskell or scheme.

But to answer your question directly there are too many benefits to mention
and they are language specific. I think transitioning to ruby and rails
environment would be rewarding. I myself like Scala much better than ruby even
though it's static typing is painful at times, and choose the rails-like
framework Play! (<http://scala.playframework.org>). The front page shows you
examples of the language expressiveness.

------
DanI-S
A nice side-effect is that you'll come out of it knowing another language that
is useful for more than just web stuff.

------
code_duck
You can't really say PHP was designed for web scripting... for the most part,
PHP wasn't designed at all.

By the time you get to more advanced apps, the advantages of PHP disappear and
all you're left with is a somewhat messy language.

------
petervandijck
There's really little reason to _not_ use PHP, except in special usecases,
like real-time services, or massively multiplayer, for example.

Facebook is, even today, basically still a monolithic PHP script.

~~~
eropple
This isn't really true. Facebook has some PHP (although a lot of their PHP is
actually compiled to C++ - it isn't in a meaningful way "a PHP script," but
rather "a PHP program) and a pretty wide variety of technologies in their
service layer (and any website that actually _has_ a service layer is
difficult to call "just a script").

It is _certainly_ not "monolithic."

~~~
petervandijck
I got that literally from a recent presentation from a FB engineer. Here it
is: [http://www.infoq.com/presentations/Evolution-of-Code-
Design-...](http://www.infoq.com/presentations/Evolution-of-Code-Design-at-
Facebook)

~~~
brown9-2
That same presentation walks through some OO code patterns they use; that's
far from "a giant script".

------
ignifero
There is nothing related to web development that you can do in other languages
that you can't do with PHP. That should suffice for your first question: Do
not rewrite any of your apps. If you want to learn another language, there are
tons of stuff you can do with Python, from numerical programming to openGL.

There is a widespread opinion that PHP is not as sexy as other scripting
languages, and that it is too domain specific. That may be true. There is
another opinion that with PHP you can only write spaghetti code. That one is
false, it's up to you to organize your code. I 've been maintaining PHP
scripts for years and didn't have that problem. Plus achieving good
performance is easier with PHP, and that comes handy with high traffic sites.

I like python for non-web projects. If only Android or iOS was written in
python.

------
VB6_Foreverr
"I recently considered moving all my web apps from PHP to something else,
mainly because I was bored and it was an excuse to get proficient with another
language."

It's just about the worst excuse going if your apps are of any value
whatsoever

------
sunstone
Because you're not a blathering imbecile with an IQ under 60.

