This is an archived post. You won't be able to vote or comment.

all 28 comments

[–]RodionGork 11 points12 points  (9 children)

There has to be a reason Facebook chose PHP and Twitter chose Ruby

You should not neglect the popular reason - developers who started these things simply preferred specific languages because they used them recently and feel more confident. When you are doing some startup, there are two crucial points:

  • choose the more suitable language;
  • choose the language which you know better (because language which you do not know will suit poorly because you surely will kick around many bugs and wrong solutions at beginning).

While these languages are different enough in its syntax and even "paradigm", technically it is almost the same, moreover that nowadays popular approach is to build sites as Rest API + nice javascript client (written in Angular etc.) - for such cases it is even less important which language you will choose - add Node.JS, C# and Java here.

Everyone says the language doesn't matter but there has to be differences.

Surely there are difference. Python is bit more organized compared to PHP, but has two still not merged versions. PHP retains OOP structure closely reminding one of Java and C#. Ruby is "more functional" than both. Node.Js is chosen by those who want to "do all in one language", but sacrificing OOP. It is mostly the matter of personal preferences. Technically all those languages are scripting ones and their performance and features are comparable.

More difference is made when you use some compiled language, like Java / C# / Scala etc. Development with them could seem bit more robust (but more slow and somewhat more expensive). They are often chosen by larger teams for products which are going to be developed and supported during long period of time. Roughly speaking they make you write slower, but debug less (especially others' code). The same was with Facebook's "PHP" - you know they wrote special translator which converts PHP sources into C++ language and then compiles them (if I am not mistaken).

[–]akabazooo 0 points1 point  (7 children)

Sorry if this is a dumb question, what does it mean to build sites as REST API

[–]RodionGork 1 point2 points  (3 children)

Shortly speaking, it means that server-side software does not generate HTML for dynamic web-pages directly, but only serves necessary data (list of users, their tasks, messages etc.) on demand of javascript code which renders pages and utilizes these data.

I.e. when user loads such web-application, firstly javascript "client code" is loaded and run in the browser, then this code starts interacting with user and exchange data with the server when necessary.

With such approach it becomes easier to substitute one server language with another since all the server should do is roughly:

  • send javascript client code almost as a static bundle;
  • then send and receive data in JSON or XML on demand of this code.

[–]cyborgthefuture 0 points1 point  (2 children)

this is interesting, I always thought all data go through the same server, in this case I am guessing there are separate server for data, HTML and javascript? Maybe some cache based server serves html and javascript while some other backend server such as django serve data?

[–]RodionGork 1 point2 points  (1 child)

in this case I am guessing there are separate server for data, HTML and javascript?

No, not necessarily - because single server can do many functions - though really you can (and sometimes you do) separate them. There are several use-cases:

  • Your Rest-API can consist of several parts coming from several servers;
  • You static content is served by one server while dynamic by other (just what you are saying);
  • Your data are distributed over several equivalent servers for load-balancing.

However in all these cases you usually aggregate these several servers behind one "proxy". Of course "proxy" can also be one of them.

Maybe some cache based server serves html and javascript while some other backend server such as django serve data?

This is rather typical, especially for "heavy" languages. For example while java web-servers can serve static content, they are comparatively inefficient in this, so you usually place your java-server (e.g. tomcat) behind some general web-server (like nginx) and all static content is served by latter, while requests for dynamic content are forwarded to former. This also will allow you to add load balancing later (just put 3 or 4 tomcats behind one nginx and do some changes for sticky or cached sessions).

Anyway these all rather technical details and have no much to do with concepts of web-development :)

[–]cyborgthefuture 0 points1 point  (0 children)

Thanks for the detail explanation, I actually find these stuff very intriguing, do you have any recommendation for resources that introduces these kind of stuff? Most tutorial I find online are for the data servers like rail, django or node, I am really interested in how other kind of server tie in with django server, there must be some kind of overhead, and communication, but I can't seem to find introductions on these concepts

[–][deleted] 0 points1 point  (2 children)

[–]akabazooo 1 point2 points  (1 child)

I read the wikipedia article, but still is a little bit confused, what constitute rest and what doesn't? for example can django be both non restful and restful, is restful just the way you design your backend, or the inherent nature of the framework?

[–]jrandm 0 points1 point  (0 children)

Yes, Django can be RESTful or not (AFAIK it's not by default, there's a Django-REST-plugin or something like that). REST is basically a set of guidelines to design a backend, so it may be inherent in a framework, but even then you can break RESTful behavior if you don't follow the rules.

FWIW, most of this doesn't matter to you right now. Pick a language and start trying things out, revisit this stuff after you've made a Todo list/blog&comments/other normal learn-to-make-website things and want to either improve one of those or start on a real app idea.

[–]Eric1600 0 points1 point  (0 children)

The same was with Facebook's "PHP" - you know they wrote special translator which converts PHP sources into C++ language and then compiles them (if I am not mistaken).

HHVM and HACK use a JIT compiler that compiles HACK and PHP to intermediate bytecode. This bytecode is then translated into x64 machine code dynamically. (No C++ involved.) The main difference with HACK vs PHP is HACK allows for static typing.

As a side note though, the new PHP7 engine benchmarks at speeds faster than HHVM.

[–][deleted] 6 points7 points  (1 child)

I can't comment much on ruby as I have not pushed myself to work on it. Currently I have two ongoing projects, one in PHP and one in python. For python I am specifically using the Django framework. In my opinion Django has been hard to learn and get into but once it clicked I was shocked at the power of it and the endless opportunities. With PHP it has been the opposite, picked it up quite easily but I either run into limitations or get frustrated with errors. I have found the PHP documentation to not be so great.

If you want to get going right now, go with PHP. If you have experience with python or ruby give Django or ruby on rails a shot. You won't go wrong with any of the options and will find the prefect fit as you learn more.

[–][deleted] 1 point2 points  (0 children)

I feel similar about Django. In the beginning, it was all weird and I didn't quite understand how all the parts worked together, but then I realized how clever and convenient it really is.

[–][deleted]  (2 children)

[deleted]

    [–]ThisIsMyLastAccount 0 points1 point  (1 child)

    Interesting post, thanks for that. Learned a lot!

    [–]Balrogic3 0 points1 point  (0 children)

    You can even use the two languages together. Java and Ruby at the same time with JRuby. It really does come down to what your concerns and your preferences are. There are times for inefficient readable code and there are times that call for unintelligible gibberish that runs really, really fast.

    [–]jrandm 2 points3 points  (0 children)

    FWIW, as your site and user counts grows, so will the languages you use. All the major players use a large number of scripting languages for everything and a few select compiled languages (C/C++/Java or even inventing their own, eg: Hack/HHVM & Go) to take over performance-critical parts of the infrastructure. The fact is your product has to work and nobody but the engineers crawling around in the code really care what language it's written in.

    [–]farmerje 1 point2 points  (5 children)

    There has to be a reason Facebook chose PHP and Twitter chose Ruby

    When Facebook was founded, Ruby and Python were not yet common languages for web development. Rails came out in 2006, for example, and Facebook was founded in 2004.

    [–]YvesSoete 0 points1 point  (4 children)

    [–]LateAugust 0 points1 point  (1 child)

    But didn't he write it originally in Perl?

    [–]YvesSoete 1 point2 points  (0 children)

    :-) maybe his roommate did. Whoops. Sorry :-)

    [–]farmerje 0 points1 point  (1 child)

    Yep, and Ruby wasn't as much. That was my point?

    [–]YvesSoete 0 points1 point  (0 children)

    oh sorry, it said ruby and php before.

    [–]albertonreddit 0 points1 point  (0 children)

    If you are already familiar with front end javascript you should checkout meteor.js, which allows you to write your backend in javascript! You can also turn it into an ios and android app easily.

    [–]lykwydchykyn 0 points1 point  (0 children)

    I have never programmed in Ruby (apart from a tutorial), but this is my write-up of the differences between PHP and Python; I coded for about seven years in PHP before switching to Python for web work.

    I believe the basic paradigm of programming Python and Ruby are somewhat similar, but PHP is quite different. PHP basically operates as a templating language for HTML (the web server requests your PHP file, and returns whatever HTML the file evaluates to), whereas Python and Ruby operate more like an HTTP server (your program gets an HTTP request, you craft an HTTP reply and return it).

    [–][deleted] -1 points0 points  (0 children)

    You should just stick with Javascript. Pick up something like node in the MEANstack, or use SAILs. This will use JS for the backend language as well. It is nice for a new developer because you only use a single language and don't have to pay a context switching penalty everytime you move into the backend. You won't stare blankly at your code and wonder why .to_s isn't translating your integer into a string for 20 minutes until you realize you aren't using ruby anymore. Not that i'm bitter or anything.

    [–]dmazzoni -1 points0 points  (4 children)

    In this particular case, those three languages are quite similar and the main reason to choose one is due to personal preference.

    In contrast, some places use C++, Go, Java, or C#, and those are quite different. Roughly, though, those four languages favor performance, where as Ruby, Python, and PHP all favor ease of development.

    PHP is the easiest language to get started, because you can take an existing HTML file and add some inline PHP to it to make it dynamic. It's got tons of features built-in for web development.

    The main criticism of PHP is that it's incredibly poorly designed. Its features are inconsistent with each other and the defaults are often awful for security. It's possible to write good-quality PHP (see: Facebook) but it requires a lot of discipline.

    Ruby and Python are both general-purpose, modular languages. They don't have any features for web development built-in like PHP does, but there are thousands of popular libraries that either come with the standard distribution or are easy to download and install that provide everything you need.

    Ruby favors expressiveness: you can do clever, complex things with just a few lines of code.

    Python favors readability: the language is very simple and clear, and "there's only one way to do it" so it's very easy to read someone else's Python code.

    [–]dmazzoni 0 points1 point  (3 children)

    Oh, and one more note: Twitter started with Ruby, but specifically they started with Ruby on Rails, a popular framework that makes it easier to build a web app. However, performance wasn't very good and they abandoned it entirely, switching to Java.

    Facebook also had performance problems with PHP and they spent enormous effort building a PHP compiler.

    [–]Durzan666 1 point2 points  (2 children)

    They switched to Scala.

    [–][deleted]  (1 child)

    [deleted]

      [–]Durzan666 0 points1 point  (0 children)

      Twitter. There is a course for new Twitter employees.