Ask HN: Why Would I Write Web Apps In Anything Besides PHP?
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.
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?
71 comments
[ 3.5 ms ] story [ 141 ms ] threadIt used to be that a big downside of Rails was deployment, but with things like Passenger, Moonshine, and Heroku, deployment is a snap now.
Wondering what the best language is for you to use? Probably the one you know best. When you out-scale PHP - you'll be on the beach drinking tropical drinks, and likely not care.
This statement indicates your ignorance and lack of experience with those languages. Each of those languages you just listed has different syntax, styles, idioms, and cultural influences.
Lisp's s-expressions are the best representation you can have for a language-as-data and data-as-language programming language (if you don't know how powerful that paradigm is, then go learn it because I won't waste my time trying to explain it).
Python's whitespace significant syntax makes readable consistency of source code a language feature. If you don't know how cool that is, then you haven't spent enough time digging through other people's PHP/Perl code (which is typically a complete mess).
Ruby's syntax is influenced by Python's and Perl's. It takes the readability of Python's syntax (minus the whitespace significance) and joins that with Perl's symbols - symbols are used a lot in Ruby to make statements very terse and short. I'm not personally a fan of this style of syntax, but it does have its merits.
Perl's syntax is great for what the language is great for: text processing. PCRE came from Perl, that in itself should speak to the power of Perl. But is perl great for readability and large maintainable projects with multiple people working/reading the source? Not really, IMHO.
PHP's syntax is interesting. I find some of it to be friendly, some of it to be offensive, and some of it to be downright stupid. Why the schizophrenic nature of the syntax and API? (functions names aren't consistent, order of arguments are wtf) Because PHP has been cobbled together by a large mix of professional programmers, amateur programmers, and people that never knew what they were doing.
Erlang's syntax, people think is very ugly. But after you get used to the language you realize how absolutely perfect for the language it is! It is extremely simple, powerful, and side-effect free. The syntax is amenable to writing large, fault-tolerant, and concurrent programs. I actually think Erlang's syntax shouldn't be changed - it's so well suited for what facilities the language itself offers I don't really think it could be offerred up in any better way (although people are trying with different front-ends to the Erlang VM)
----
Here's my subjective opinion on each language with respect to web application programming. I will begin with PHP because that's the language I first learned how to program in:
PHP is great for precisely what it was built for. This isn't it's acronym but Personal Home Page sums it up well - PHP is really well suited for small projects. Projects that need to get thrown up quick. Say you want little website for your daughters soccer team with a guest list form - I wouldn't pick anything else but PHP to do such a small task in. Getting everything setup in Python or Ruby would not be a trivial task; in PHP it is trivial. PHP absolutely sucks for really big projects (again, just my HO) most PHP frameworks end up spending 40% of their "feature set" development on compensating for PHP's own shortcomings as a language and most PHP programmers learn methodology and processes that are PHP specific because most of it is "getting around" the warts in the language that are simply common sense and intuitive in other languages.
Oh, Python/Ruby don't lose because they "wrap" the web request as an "after thought" - even PHP has to "wrap" the web request. It just does it behind the scenes for you. With Python and Ruby, you're exposed to most of that so you actually have far more control than that which PHP gives you. PHP's strength is, ultimately, its weakness.
Python is wonderful for web applications - Python + Pyramid (framework) is probably the cleanest, logical, and innovative combination I have seen for web application programming yet. Python is easily ...
So if you look at it from that angle, it makes sense to code in a language that tends to have pretty code, rather than one that doesn't.
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.
PHP is a mature language and isn't trendy, but it is far more vibrant, broad, and interesting than Ruby or Python.
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.
Security updates routinely break functionality with no warning or knowledge on core and modules, and the community is architected to make it far more difficult to contribute new modules than necessary (not to mention submitting patches). I won't even update the Date module - ever (http://drupal.org/project/date); I can't count the number of times an update has introduced more bugs than it fixed. It's irresponsible.
PHP is a great language, and there are a lot of great tools, frameworks and websites written with it, but it doesn't mean it's the only game in town. What is most important is using the right tool for job, whatever it may be. Sometimes it's Drupal/Wordpress, sometimes it's Rails. Github's language page illustrates that pretty well: https://github.com/languages
Size doesn't matter. Utility does. Lots of good languages exist, but they're all just tools to be used by the programmer. I use Ruby because the community is rapidly developing fantastic, useful gems and tools that meet my needs and make my life as a developer easier. PHP does not meet my needs in the same way. Thankfully, the existence and usefulness of one language/platform does not negate the existence and usefulness of many others.
First, PHP is a great language. It definitely has its strengths. It was the second language that I ever used to create web sites (right after Perl).
With that said, the number of people using something does not inherently make it superior to all of the other choices. PHP, Python, Ruby, etc all have their proponents and they all have their valid use cases. Which one someone chooses to use is largely a matter of personal preference.
Drupal is a great package, but I found it to be cumbersome and unwieldy for my purposes, which is why I started fiddling around with Django. Choices are good - HipHop, Wordpress, etc do not innovate in a vacuum.
Innovation is facilitated by maintaining an open mind and looking to offer improvements and variations on existing solutions. There is no war between the languages. Everyone can learn from each other - and they often do.
Now, as to maturity. Both PHP and Ruby have been around since roughly 1995. (People sometimes mistakenly believe that Ruby did not exist until Ruby on Rails, but it was around for quite a bit of time before that.) Python has actually been around (publicly) since 1991. All three languages are mature by any definition of that word.
As to broadness, I think that it is worth noting that Python has really come into its own in the area of scientific and mathematic applications. I have always found Ruby to be an amazing general purpose text processing and scripting language (in addition to web programming). PHP, on the other hand, I have not actually seen in extremely heavy usage outside of the web environment. I would be pleased to know of any though, but you must admit that the usage of PHP in developing web sites fairly drowns out its usage in more general cases.
As to community size, I believe that quality not quantity is what counts. Both Python and Ruby have a lot of bright people working on a lot of really great projects. Of course, PHP does as well, but there is no reason to be outright dismissive of alternatives (you know, Perl is actually pretty neat too, but I rarely use it nowadays).
Additionally, where do you have numbers to support your assertion that Ruby is in decline? That is a rather strong statement - you should have numbers to back it up, and TIOBE is not a very good source of data for this.
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.
What infrastructure and open source libraries don't exist for PHP?
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).
(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.)
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?
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.
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.
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.
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.
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.
A big one, you can use native threads.
you can also grab a java machine learning library and use it directly in jruby, you can use lucene directly in your process, you can write hadoop jobs in jruby without using the streaming api, etc, etc.
Just think of java libs that don't exist in php and that's the benefit.
(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.)
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.
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.
Facebook is, even today, basically still a monolithic PHP script.
It is certainly not "monolithic."
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.
It's just about the worst excuse going if your apps are of any value whatsoever
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.
I know these are rough numbers from my perspective, but the efficiency and effectiveness of the framework really adds up.
(Disclaimer: I work there)
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.
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.
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.
No need to manually escape strings, no build system, 4 different JSON libraries!? Seamless (you don't even need to call it most of the time) to_json. The list goes on.
Yes, you have to know about appropriate libraries to use Ruby for webapps, just like you have to know about the functions available in PHP. It's fortunate that PHP has some of that core stuff built in, because it's package manager blows. If I need to encode json I just incant `gem install json` (but it's probably installed already, or maybe I would have to start right at the beginning with `gem search -r json`?) and call `to_json`.
The point is, use what makes you productive. Not being 'designed for web scripting' is meaningless today.
This seems like a great problem to have.
If you are writing a trivially simple webapp, then you would be correct that you could hack together something with just the core language features of PHP.
It makes perfect sense to point out that most anyone using a normal alternative to PHP such as Python or Ruby is probably using a framework where output is escaped by default, such as Django. How about that - a system that does it automatically, you don't need to call htmlspecialentities.... or html_special_chars.
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!
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.
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.
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.
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.