views:

247

answers:

4

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?

+10  A: 

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
thanks.. that was helpful.. so u mean php is enough??
dineshbabu
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
Oh.. Im getting to know things now..
dineshbabu
As if anybody would care about Turing Completness...
pmr
@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
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
"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
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
@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
+5  A: 

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
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
Chris, check out HotRuby - http://ajaxian.com/archives/hotruby-run-ruby-on-a-javascript-interpreter
Annie
@Annie - That is the coolest thing I've seen in a while.
Chris Lutz
+3  A: 

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
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
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
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
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
+3  A: 

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