|
Advertisement |
RAILS vs STRUTS
Posted On July 8, 2010 by Shruthi S filed under Open Source
In this article, the author presents the merits of Ruby-on-Rails over Struts and also asserts why Ubuntu+Netbeans is preferable for Rails development.
My tutorial is about developing a Ruby-on-Rails application in Linux platform, as it is open-source and free platform. Ruby language and Ruby-on-Rails framework also are open-source and free. So they make ideal combination.
RUBY-on-RAILS is a Modern Web Framework. It offers the following special features.
a) OPEN SOURCE & FREE
b) BUILT-IN ORM
c) IN-BUILT MVC
d) ALL PLATFORMS
e) AJAX –ENABLED
f) AGILE ( UNIT TESTS)
g) RESTFUL WEB SERVICE
Ruby is a language ,developed by Matz ( Matsumoto) in Japanese in Japan. It is object-oriented & scripting language.
Ruby language was developed in 1996. It was in the same year that Java language also appeared. Ruby came to be used in USA only in 2000.Even in 2000, Ruby was not known much.
But in 2005, a framework known as Ruby-on-Rails was developed by DAVID HANSONN. ( Hereafter , I will refer to Ruby-on-Rails( R.o.R) simply as Rails.)
Rails made the usual Web-Database application very easy and so it has now become very popular. Database operations are mostly of two types.
a) general query like
'select * from table1'
b) CRUD operations.
C stands for 'create' a record
R ,, for 'read' a record
U for 'update'
D for 'delete'
RAILS framework does not use SQL queries directly but performs CRUD by using Object-Relational mapping, very easily.
For the past ten years, ( from 2000), WEB-ENABLED applications have become more and more important. There are essentially, three streams in software world.
a) Microsoft stream.
b) Linux stream
c) j2ee stream
The Web Technolgy for Microsoft platform is known as ASP.Net.It makes use of either VB.net or C#.Mono is an open-source and free software which aims to use C# and ASP.net in Linux platform( as XSP). It is yet to succeeed.
In Linux stream, we have LAMP .
L stands for Linux.
A stands for Apache Web Server
M stands for MySql Databse.
P stands for Perl, PHP and Python.
The merit is that everything in LAMP is absolutely free and open-source. MySql is a wonderful Database software. The latest version is MySql5.
It is becoming suitable for Enterprise applications. It is open-source and free. It rivals other costly databases like Oracle, Microsoft SqlServer and IBM DB2. SUN MICROSYSTEMS has adopted MySql project and is giving lot of financial and technical support. Perl, PHP and Python are all scripting languages like Ruby. Any scripting language can be readily used in any platform.
So, we can run Perl, Python, Ruby and PHP programs in both Microsoft Windows platform and Linux platform. Apache server itself can run in Windows machines. But, we will have to pay for the platform. And virus related problems in Windows platform are well-known and well documented facts.
That is why we give importance to Linux and Unix versions like Solaris( open-source and free like Linux).
Similarly, J2EE programs also are platform independent. They can run in Windows and Linux/Unix without recompiling. Most of the advanced software in J2EE world like JBoss application server, GlassFish application server,
Many database products like Apache Derby, Struts framework, JSF, famous ORM tools like Hibernate and many more are absolutely free and open-source.
Why then, more and more people, even many java-veterans are adopting Rails?
I will try to give a rough idea, now.
---------------------------------------------
Any modern web-application should provide the following features.
i) MVC ( Model-View-Controller Architecture)
MVC -> MODEL-VIEW-CONTROLLER
MODEL deals with data & business logic
VIEW deals with user's input page and
result display.
CONTROLLER works in the
background.It manages the flow.
ii) ORM ( Object-Relational-Mapping)
Object in memory has attribute-values.
Row in a Table in Database has
corresponding columns
A mapping-document connects these
two.This is known as ORM.
Famous ORM tool in J2ee is Hibernate.
RAILS offers ACTIVE RECORD
iii) Validation
iv) Unit-testing facility.
v) Ajax facility.
vi) easy web-service facility
I have done work in j2ee using Struts and Apache Axis. I have also done some work in ASP.net using C#. From my personal experience, I know how difficult and time-consuming, it is to develop Struts programs. I will now compare Struts based work and Rails framework.
1)) Struts does not provide any 'model'.
model in MVC stands for persistence ( database) and the code for interacting with data. So, we have to use either jdbc or hibernate for this purpose. It gives option not to use ORM like Hibernate.
ORM means, persistence in database table takes place automatically without our writing any sql script like 'insert into table1' etc.
Rails incorporates the model in MVC in the form of ActiveRecords. ORM is the more modern and indispensable feature in Database
nowadays. Rails imposes this discipline by providing ready-made ORM.
2) VALIDATION
Next comes Validation. This was the main purpose of Struts originally. When a user fills up a form and submits it to the server for processing, if he has done anything wrong in entries, the form should be returned to the user. All the entries already there should be preserved.
An error message also should be sent to indicate where the error occured.
But Struts requires another framework known as Validation Framework for advanced validation. This framwork has its own XML file and creates headache.
Rails provides very easy and built-in arrangement for validation work.
3) LAYOUTS
Moreover, the view in Struts framework requires knowledge of Tiles Framework with its own XML entries.
In Rails, there is a simple layout file easier to edit and use. And layout is not external to Rails but a built-in feature.
4) UNIT-TESTING ( AGILE METHODS)
Unit testing has become the standard practice in large-scale project development. Struts does not provide any built-in unit-testing facility. We have to use JUnit.
Rails provides built-in unit-testing facility
5) MVC
MVC principle in Struts means the following.
JSP is used for accepting data input from the user and also for displaying the result to the user.
Beans are used to hold the data and for carrying out the business logic( data operations).
Servlet is used for co-ordinating the exchange and flow( controller) by using Struts-configuration file.
The configuration files in servlets and struts make use of XML.It is very confusing to make entries in these files. Even a small mistake will lead to wrong results.I had to waste a lot of time in trouble-shooting these files.
But, in Rails, I do not deal with any XML file atall.
6) TAGS
Struts insists that we should not use scriptlets in JSP but only tags.
There are a lot of tag libraries and the corresponding TLD( tag-library-descriptors) should be correctly placed and we should refer to them correctly.
Rails simply uses scriptlets( scriptlets are code fragments placed between delimiters).Actually, Rails does not use tags at all ! It is a great relief.
7) WEBSERVICE
XML-Webservice has become the latest standard.
All technologies like ASP.net and J2EE and even PHP make use of terribly complicated XML based standards like SOAP, WSDL and UDDI.
But Rails has provided a simpler and more elegant webservice model based on REST principle.
8) AJAX SUPPORT
Ajax is a recent technology. It refers to contacting a server for data without submitting the form. It sends a small chunk of data only to the server and not the entire form. So it gives quicker response.
So all web-tier technologies are now forced to provi0de Ajax facilities. Thus we have ASP.Net Ajax, Google-webtoolkit and such.
Struts does not provide in-built ajax.
But Rails provides built-in Ajax written in Ruby itself .
I have thus given the basic reasons why Rails is a nice alternative to Struts.
-----------------------------------------------
I will now argue why we should develop Rails applications in Linux and not in Windows.
Windows is a proprietary platform and there is no use in developing Open-Source and free applications like Rails in Windows. That is why, we should adopt Linux for developing Rails programs.
Linux platform has many distributions like
Ubuntu,
Mandriva ,
Suse,
Redhat Fedora,
Debian
Ubuntu is gaining great popularity nowadays, compared to its rival , Redhat.
Ubuntu in desktop is very user-friendly . So, it is becoming very popular.
In our lab also, we have got Ubuntu installed in my system. And I developed Rails demo in Ubuntu. The procedure for installing Rails in Ubuntu can be slightly different from installing it in Redhat-Fedora. We have to experiment and confirm for each Linux distribution.
Whatever be the platform, developers like to have an IDE ( Integrated Development Environment), like Visual Studio in Windows platform.
Netbeans project was founded by Sun MicroSystems to develop such IDE for developing Java /j2ee programs.
Both Netbeans and Eclipse have now become very popular and they are now used not only for Java development but C/C++, Ruby, Perl and Python programs also.
Both Netbeans and Eclipse are Open-source and Free projects and are based on Java language.
The current version of Netbeans is 6.6 and of Eclipse is 3.4. I have already developed and written about Rails develoment in Windows and placed my tutorial in DeveloperIQ. If we use Netbeans IDE, there will not be much difference in procedure for any platform.
It is very easy to develop Rails programs in Netbeans.( Mr.Madhan Sekaran has written many tutorials on that, in DeveloperIQ).There is very little difference in Netbeans work in Windows and that in Ubuntu. Thus, I suggest that readers should adopt Rails and Ubuntu.
==============================================





