6 ms·
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?
- MatthewB 15y agoI 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 15y agoMost 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.
- deleted 15y ago[deleted]
- captaincrunch 15y agoUse what you want to use, want to learn Python? Or code that C++ CGI Web App? Go for it... 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.
- cmelbye 15y agoIf 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.
- porter 15y agoCleaner 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!
- citizenkeys 15y agoCleaner code? Really? While I admit that a good percent of php code is sloppy, when done well it can be very clean. One of my attractions to PHP is its straight-forward C-style syntax. I like my curly braces and my switch() keyword, thank you very much. Never been much of a fan of python/ruby/perl/lisp syntax.
- zepolen 15y agoI would say you're not a fan because you haven't tried them. For one, perl is very similar to php.
- Ixiaus 15y agoPreface to this comment: I started life as a PHP programmer (a core committer for many years to the KohanaPHP framework too) and stayed that way for 5 years - I am now a professional Python, Erlang, and Scheme programmer and will never go back to PHP. 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 readable by other people. Python has more high quality and easy to use standard and 3rd party libraries than just about any language in existence (remember, I said "easy to use"). Python also has a wonderful mix of functional features (list comprehensions, anonymous functions, etc...) and imperative features as well as a really powerful set of standard data structures. Want to test to see if the letter "h" is in the string "hello"? Well, in PHP you would do this: if(stristr('hello', 'h') !== FALSE {echo "found!"} in Python: if 'h' in 'hello': print('found!') Python has had a lot of thought put into its design and it is evolving every single day to become an even clearer and better language. Still, Python is not a silver bullet for everything (although it is definitely used as glue in just about everything). Python does not support concurrency well at all (you have to goto stackless, but even then, it doesn't compare to Erlang). Erlang is like LSD - it's so wonderful is such a strange way. Concurrency, fault-tolerance, hot code loading, and it's a functional language - Erlang uses pattern matching exclusively (if you haven't used pattern matching, you don't know what you are missing), tail recursion is something I love to use, and I love the naturalness of this: dolist([H|T]) -> do_something_to_the_first_list_element(H), dolist(T); dolist([]) -> io:format("List has been processed!"). Whereas in Python that would have looked like this (no recursion): def dolist(lst): if not lst: print("List has been processed!") for i in lst: do_something_to_the_first_list_element(i) print("List has been processed!") Scheme? Oh man. Scheme is my favorite language - data-as-language, functional. That is all I will say. I'm babbling on now - what I will say is this: if you're closed minded, this whole thing was wasted on you - but from one PHP programmer to another: broaden your horizons. Every language has pros and cons. Every. Even PHP. PHP's strengths are its wide adoption and low barrier to entry it's the perfect html templating language (honestly). But you won't become a better programmer because of PHP. You won't learn the beauties that I've seen in all of the languages I've described. There's more too - more languages that can stretch your mind in ways you probably can't even appreciate right now. Get out of your pidgeon hole and learn something. Appreciate the fact that every tool has its application and that there is no "one size fits all" language.
- akshaykarthik 15y agoOne 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 15y agoThis is the same advantage as Ruby - the community for both languages has been more vibrant and interesting than PHP for years.
- OstiaAntica 15y agoHardly. 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.
- ianl 15y agoFor 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 15y agoMy experience is diametrically opposite to this. What infrastructure and open source libraries don't exist for PHP?
- OstiaAntica 15y agoAgreed. For example, I've worked on apps using the phpmailer library for nearly a decade, delivering 100 million optin emails without issue.
- eropple 15y agoYep. And if you use something like Thrift ( http://wiki.apache.org/thrift/ http://wiki.apache.org/thrift/ ) building a SOA that includes PHP service components is fairly simple.
- risotto 15y agoFull 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 15y agoYou 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.)
- DanI-S 15y agoA nice side-effect is that you'll come out of it knowing another language that is useful for more than just web stuff.
- yichi 15y agoTo 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 15y agoI 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?
- naqabas 15y agoI completely agree with this. Up to a couple weeks ago, I had only programmed in .NET and php. I got bored one day, and decided to learn python. I loved it right away, and now I'm learning Django and building my first web app in python. You can ask other people about which they think is better, but you're going to always get different opinions, so the best thing to do is try to figure it out yourself.
- gfodor 15y agoGood 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 15y agoThat'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 15y agoIt'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 15y ago> 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.
- freshfunk 15y agoIMO, 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 15y agoI 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.
- tshtf 15y agoThere 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.
- petervandijck 15y agoThere'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 15y agoThis 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."
- hedgehog 15y agoIn a conversation with a couple FB devs a few weeks back they mentioned that their codebase is now less than 50% PHP.
- petervandijck 15y agoI got that literally from a recent presentation from a FB engineer. Here it is: http://www.infoq.com/presentations/Evolution-of-Code-Design-at-Facebook http://www.infoq.com/presentations/Evolution-of-Code-Design-...
- brown9-2 15y agoThat same presentation walks through some OO code patterns they use; that's far from "a giant script".
- cconroy 15y agoIt 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 http://scala.playframework.org). The front page shows you examples of the language expressiveness.
- VB6_Foreverr 15y ago"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
- jschuur 15y agoFor 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.
- charlesju 15y agoI'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 15y agoYou can deploy a php app just as easily on dotcloud :) http://dotcloud.com http://dotcloud.com (Disclaimer: I work there)
- ceejayoz 15y agoEven 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.
- thenduks 15y agoEh, 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 15y ago"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.
- ryan-allen 15y agoI'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!
- zmmmmm 15y agoProductivity 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.
- true_religion 15y agoBecause 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.
- sunstone 15y agoBecause you're not a blathering imbecile with an IQ under 60.
- code_duck 15y agoYou 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.
- ignifero 15y agoThere 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.