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?

8
  • 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 2, 2010 at 9:20
  • 1
    @Mark: I think he is not much aware of "Ruby on Rails" or probably he forgot to write. Jan 2, 2010 at 9:22
  • 1
    @dineshbabu: Each language has its own flavour :) Jan 2, 2010 at 9: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 2, 2010 at 9:24
  • 8
    I speak Enlish, Turkish and Danish. What is the role of French, Finnish, Spanish and other languages in communication. Jan 2, 2010 at 11:30

4 Answers 4

9

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.)

6
  • 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 2, 2010 at 9: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 (en.wikipedia.org/wiki/Brainfuck) to be used to run websites.
    – Chris Lutz
    Jan 2, 2010 at 9: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 2, 2010 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 2, 2010 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. Jan 2, 2010 at 12:02
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/

2
  • 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 2, 2010 at 9:25
  • 1
    Chris, check out HotRuby - ajaxian.com/archives/…
    – Annie
    Jan 2, 2010 at 9: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

4
  • 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 2, 2010 at 9: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. Jan 2, 2010 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. Jan 2, 2010 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 Jan 2, 2010 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.

1
  • 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. Jan 2, 2010 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.