0

Please bear with me experts i'm a newbie in web dev.

With html,css can take care of webpages.. javascript,ajax for some dynamic content.. php for server side scripting,accessing databases,sending emails,doing all other stuf...

What role do these programming languages play? Can they do any other important task which cannot be done by PHP?

Dinesh Babu K G
  • 528
  • 6
  • 23
  • Why did you not mention Ruby? Ruby on Rails? What is this alternate existence you come from where people write web apps in C++ but don't even give a mention to Ruby on Rails? Is it a deliberate omission or did you just forget it? – Mark Byers Jan 02 '10 at 09:20
  • 1
    @Mark: I think he is not much aware of "Ruby on Rails" or probably he forgot to write. – Prasoon Saurav Jan 02 '10 at 09:22
  • @above all.. im really sorry guys.. i forgot abt it.. – Dinesh Babu K G Jan 02 '10 at 09:23
  • 1
    @dineshbabu: Each language has its own flavour :) – Prasoon Saurav Jan 02 '10 at 09:23
  • 6
    @Mark - Why did the OP not mention a lot of things? Most of these types of questions are rather misinformed, mentioning two unrelated languages without mentioning a lot o related ones. Rather than getting your feathers (rails?) ruffled over someone's lack of knowledge, teach them and correct that lack. – Chris Lutz Jan 02 '10 at 09:24
  • 8
    I speak Enlish, Turkish and Danish. What is the role of French, Finnish, Spanish and other languages in communication. – Sinan Ünür Jan 02 '10 at 11:30
  • @Sinan hmmmm... can i take ur comment as it is? :P – Dinesh Babu K G Jan 02 '10 at 13:17
  • You might want to look at http://stackoverflow.com/questions/824730/when-should-i-use-perl-cgi-instead-of-php-or-vice-versa/825380#825380 – daotoad Jan 02 '10 at 19:28

4 Answers4

10

All languages can all do basically any task any other one of them can do, as they are all Turing complete.

PHP works as a server-side scripting language, but you can also use Perl, Python, Ruby, Haskell, Lisp, Java, C, C++, assembly, or pretty much any other language that can access standard input and standard output for CGI communication with web content.

PHP is widely used because a) it's easy to learn a little and go, and b) the rather tedious CGI protocols are skipped, as the language handles them for you, so you can just plug your PHP script into an HTML page and not have to know how your program reads the information at all. This makes web programming easier for PHP, but the PHP interpreter is written in C, which does all the heavy lifting, so logically if PHP can do server-side scripting, so can C. Since most other languages are written in C, they too can do server-side scripting. (And since C compiles down to assembly, assembly can do it too, and so can any language that compiles down to assembly. Which is all of them not already covered.)

Chris Lutz
  • 73,191
  • 16
  • 130
  • 183
  • 3
    PHP is "enough" in that it can do anything you might need done. But if you want to be a better programmer, you will at least dabble enough to recognize and understand a little code in basically everything I mentioned (and more). But all in good time. Learning one language well will help you learn other languages more quickly. (And some may say learning PHP may hurt you, but if you're careful and learn from questions on StackOverflow you'll find it harder to write bad code in PHP or any language.) – Chris Lutz Jan 02 '10 at 09:27
  • 2
    @pmr - I can't tell if you're being snarky or cynical or serious with that, but Turing completeness allows someone to (try to) write a mod_bf for Apache and allow the Language That Shall Not Be Named (http://en.wikipedia.org/wiki/Brainfuck) to be used to run websites. – Chris Lutz Jan 02 '10 at 09:50
  • I'm just upset with people using Turing completeness as means of language comparison. Every language that is somehow in use is Turing complete. Heck, even most of the exotic languages are. I appreciate the theoretical value of turing completeness but it is simply useless as a language attribute if you are looking at something like web development. It just doesn't matter here. What was the last time you used Turing completeness to decide if a language is suitable for a project? – pmr Jan 02 '10 at 11:50
  • 1
    "Every language that is somehow in use is Turing complete." Basic SQL is not Turing complete. Many SQL extensions are, but not plain old SQL. "...it is simply useless as a language attribute if you are looking at something like web development." If a language isn't Turing complete, you won't use it for web development, _ergo_ it isn't useless in the decision-making factor. It may not be question #1, and any languages it filters out may be filtered out before you get to it, but it's certainly not useless in determining if a language can do task X. – Chris Lutz Jan 02 '10 at 12:01
  • You may want to be a little more precise in your opening statement. The OP mentioned HTML and CSS, which are not Turing-complete. Which, incidentally, answers @pmr's objection: HTML/CSS alone are not suitable for building any application beyond a collection of static pages precisely because they are not Turing-complete. – Dave Sherohman Jan 02 '10 at 12:02
  • @dineshbabu - You shouldn't really look for *enough*. You need to evaluate these languages and your use case to decide what fits best. Each one had different strengths and weaknesses. – Noufal Ibrahim Jan 02 '10 at 17:22
5

The language is where the actual logic of your application resides.

Perl, Python, Ruby etc. are all server side scripting languages (although their implementations and deployment methods are quite different).

As for "Can they do any other important task which cannot be done by PHP?", not really. All the languages are equal 'power' wise but the language design and capabilities make the development experience quite different.

Here's a relevant link about some of the things PHP gets right by a rather prolific Pythonista http://blog.ianbicking.org/2008/01/12/what-php-deployment-gets-right/

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • 2
    Theoretically you could write a Perl/Python/Ruby interpreter in JavaScript (or just embed one in a browser) and make them client-side scripting languages, it's just not common (or actually existing at all). I think that would be pretty awesome, though. – Chris Lutz Jan 02 '10 at 09:25
  • 1
    Chris, check out HotRuby - http://ajaxian.com/archives/hotruby-run-ruby-on-a-javascript-interpreter – Annie Jan 02 '10 at 09:33
4

Another difference between your language choice is speed. An app written in C is going to run faster and require less system resources in general then a higher level scripting language. In a small scale app, you'd never notice. If your site is the next facebook, you will.

Here's a good example of a choice of languages having a very real effect: http://developers.slashdot.org/story/09/12/20/1433257/The-Environmental-Impact-of-PHP-Compared-To-C-On-Facebook?art_pos=9

Erik
  • 20,526
  • 8
  • 45
  • 76
  • 2
    Facebook is written in PHP, which doesn't appear to be impacting it's popularity, though you could argue that "it shows." Twitter is written in Ruby, which is significantly slower than most other scripting languages. – Chris Lutz Jan 02 '10 at 09:45
  • 1
    Actually I believe Twitter is no longer in Ruby - it was originally, hence the site's notorious unreliability, but since those days all its backend has been ported to Scala. – Daniel Roseman Jan 02 '10 at 10:06
  • 1
    Obsession with runtime performance is largely a cultural artifact of earlier days. In the modern world, development time is far more important. Using a "less efficient" language to cut a week off development time saves enough in programmers' salaries to buy a second server which will provide a larger speed boost than you'd get from having the code in perfectly-optimized C. You also need to consider the overall system's characteristics; if it takes 2 seconds of network time to connect to the server and transfer data, 0.2 second vs. 0.002 second processing time on the server is irrelevant. – Dave Sherohman Jan 02 '10 at 12:15
  • Facebook's engine is written with C++ (PHP is just the front end). As for Twitter, the most critical piece (message queue) was re-written with Scala – Nemanja Trifunovic Jan 02 '10 at 19:34
3

If you'd like to understand how all of these different programming languages can be used for server-side scripting, read up on CGI.

Annie
  • 6,621
  • 22
  • 27
  • Or, don't. None of these languages rely on CGI for running websites these days, as it's a terribly inefficient way to do things. – Daniel Roseman Jan 02 '10 at 10:03