views:

769

answers:

14

Every time I see Ruby or Python discussed in the context of web development, it's always with a framework (Rails for Ruby, Django for Python). Are these frameworks necessary? If not, is there a reason why these languages are often used within a framework, while Perl and PHP are not?

+3  A: 

I can only speak towards Ruby - but, no, you don't need a framework to run Ruby based pages on the web. You do need a ruby enabled server, such as Apache running eruby/erb. But, once you do, you can create .rhtml files just like RoR, where it processes the inline ruby code.

Matt
+3  A: 

"Need" is a strong word. You can certainly write Python without one, but I wouldn't want to.

Python wasn't designed (like PHP was, for example) as a direct web scripting language, so common web-ish things like connecting to databases isn't native, and frameworks are handy.

EDIT: mod_python exists for Apache, so if you're merely looking to write some scripts, then Python doesn't need a framework. If you want to build an entire site, I'd recommend using one.

warren
A: 

By no means are those development frameworks required. But as with most development environments, your productivity will increase exponentially if you have a supported framework to reference and build your applications on. It also decreases the training needed to bring others up to speed on your applications if they already have a core understanding of the framework that you use.

Adam Carr
A: 

Any language that can "print" can be used to generate web pages, but frameworks handle a lot of the HTML generation for you. They let you concentrate more on the content and less on the details of coding the raw HTML.

Ron

Ron Savage
A: 

For python, the answer is No you don't have to. You can write python directly behind your web server very easily, take a look at mod_python for how to do it.

A lot of people like frameworks because they supply a lot of the boilerplate code in a reliable form so you don't have to write it yourself. But, like any code project, you should choose the tools and frameworks on their merit for your problem.

Simon
A: 

You can certainly write CGI scripts in either language and do things "raw".

The frameworks (ideally) save the trouble of writing a pile of code for things that other people have already handled (session handling, etc.).

The decision probably comes down to what you need to do. If the framework has the features you need, why not use it. If the framework is going to require extensive modifications, it might be easier to roll your own stuff. Or check out a different framework.

The python library has numerous modules for doing cgi, parsing html, cookies, WSGI, etc:

http://docs.python.org/library/index.html

Dana
+1  A: 

As to the why:

The most plausible thing I can think of is that Perl and PHP were developed before the notion of using frameworks for web apps became popular. Hence, the "old" way of doing things has stuck around in those cultures. Ruby and Python became popular after frameworks became popular, hence they developed together. If your language has a good framework (or more than one) that's well supported by the community, there's not much reason to try to write a Web App without one.

Adam Bellaire
+1  A: 

A framework isn't necessary per se, but it can certainly speed development and help you write "better" code. In PHP, there are definitely frameworks that get used like CakePHP, and in Perl there are many as well like Mason and Catalyst.

theraccoonbear
+1  A: 

The frameworks aren't necessary. However, a lot of developers think frameworks ease development by automating a lot of things. For example, Django will create a production-ready backend for you based on your database structure. It also has lets you incorporate various plugins if you choose. I don't know too much about Rails or Perl frameworks, but PHP frameworks such as Zend, Symfony, Code Igniter, CakePHP, etc are used widely.

Where I work at we rolled our own PHP framework.

CoolGravatar
+2  A: 

The short answer is no, they are not necesary, in ruby for example you have .erb templates that can be used in a similar way as you use PHP pages. You can write a site in ruby or Python using several technologies ( Rails-like frameworks, Templates or even talking directly with the HTTP library and building the page CGI-style) Web frameworks like Python's Django or Ruby's Rails (there are many ) just raise the level of abstraction from the PHP's or ASPs , and automate several process, (like login, database interaction, REST API)S wich is always a Good Thing.

AlePani
+2  A: 

Framework? Heck, you don't even need a web server if you're using Python, you can make one in around three lines of code.

David Hicks
A: 

PHP has a lot of frameworks. Probably more then most. In Ruby most use Rails so thats what you hear, and Django for Python is mentioned more then not. But with PHP you have many to choose from.

List of web application frameworks

OIS
+1  A: 

From a Pythonic point of view, you'd absolutely want to use one of the frameworks. Yes, it might be possible to write a web app without them, but it's not going to be pretty. Here's a few things you'll (probably) end up writing from scratch:

  • Templating: unless you're writing a really really quick hack, you don't want to be generating all of your HTML within your Python code -- this is a really poor design that becomes a maintainability nightmare.

  • URL Processing: splitting a URL and identifying which code to run isn't a trivial task. Django (for example) provides a fantastic mechanism to map from a set of regular expressions to a set of view functions.

  • Authentication: rolling your own login/logout/session management code is a pain, especially when there's already pre-written (and tested) code available

  • Error handling: frameworks already have a good mechanism in place to a) help you debug your app, and b) help redirect to proper 404 and 500 pages.

To add to this, all of the framework libraries are all heavily tested (and fire tested). Additionally, there are communities of people who are developing using the same code base, so if you have any questions, you can probably find help.

In summary, you don't have to, but unless your project is "a new web framework", you're probably better off using one of the existing ones instead.

Tony Arkles
You can of course do all of those tasks using separate, unrelated library modules; you don't necessarily have to use an over-arching framework to control the lot. The lower-level WSGI standard gives us enough to glue these components together.
bobince
+1  A: 

Are these frameworks necessary?

No. They, like any 'framework', are simply for speeding up development time and making the programmer's job easier.

If not, is there a reason why these languages are often used within a framework, while Perl and PHP are not?

PHP and Perl were popular languages for building web sites well before the idea of using frameworks was. Frameworks like Rails are what gave Ruby it's following. I'm not sure that Python or Ruby were that common as web languages before they were backed by frameworks.

These days, even PHP/Perl web developement should be backed by a framework (of which there are now many).

Nathan