For a living I write software applications for Windows using C++, I have been developing software for over 10 years. At home and as an Entrepreneur I am all about Open Source, I use Linux religiously which is an Open Source free OS. I discovered Ruby on Rails when I was researching Open Source solutions that would help me build websites, and I will share with you some things I learned. My own website is, DevMentor.org where you can find things that interest me.
What is this thing Ruby on Rails!
Well if you’re not a hacker, you can be excused for not having heard about Ruby on Rails (RoR). Even if you’ve heard of RoR, you might not understand the excitement surrounding this dynamic and powerful software development tool. For those not entrenched in the world of software development, technical concepts and language can be a barrier to understanding key benefits of a tool or methodology used by software developers. I’ll present the material here so most anyone can understand and talk about the virtues and merits of Ruby on Rails.
When I use the term ‘Hacker’, it’s in the original true sense of the word, someone who enjoys learning and figuring things out by exploring and tinkering. Before we can talk about Ruby on Rails, we need to learn about Ruby.
Ruby the Beautiful
Ask Rubyist and they will all tell you Ruby is a beautiful fun programming language to code in. Ruby is also a powerful dynamic script language, that is primarily run on the server. The term dynamic means that any hacker can extend the Ruby language and become a language designer using meta-programming. This is really powerful, most programming languages are set in stone when they are created by the designer, you cannot alter and extend them like you can with Ruby.
Back around 1995 Ruby made its public debut, its creator Yukihiro Matsumoto, better known as Matz, wanted to create a “fun” language to program in. Ruby took the best ideas from other programming languages at that time (Perl, Smalltalk, Lisp, Ada and Python).
Ruby has excellent regular-expression (regex) support that Perl is best known for. For the non computer science people, regex is a pattern matching text processing language. Effectively it solves the everyday problem of searching and scanning text using “fussy” matching. When you enter a phone number, a credit card number or email at a website, chances are regex is working behind the scene to make sure the format of the input is valid. You may have a need to “scrape” data from a report. For example, you want to get financial data from several accounting reports, or a list of prices and products names from a catalogue, these are all well suited tasks for regex processing.
Likewise Ruby is a true Object-Oriented (OO) language, in Ruby everything is an object. Alright I don’t know what object-oriented means? Please explain! Well object-oriented languages like Ruby follow the convention that software can be modelled in terms of objects that have properties and behaviours. Objects from the same “class” will share behaviours, called functions or methods. Likewise objects of a given “class” will have the same types of properties. Take for instance a “Person” class that knows how to talk, walk and eat (the methods). Each Person can have a name, age and gender property. Think of a “class” as a kind of cookie cutter, that is used to create objects in it’s image. Objects can have relationships, ok not like going on a date, but relations in the same sense that a car object will have with a engine object. This just scratches the surface of OO programming, suffice to say OO languages like Ruby can be a more powerful way to model, organize and construct software.
Ruby makes developers more efficient at writing code that is both concise and easy to read. Beside the productivity boost, you also get code that is easy to maintain. Why is this important? Most of the cost associated with software development is spent on the maintenance life-cycle. I don’t have exact figures but it’s close to 80%-90% of total cost.
Speed Vs Productivity, the Trade Off
Since script code like Ruby is interpreted, it needs to runs on a layer above the OS, in a virtual machine. As a result, you sacrifice a little on the speed. However if you’re really power hunger and need speed, it’s really easy to tap into C/C++ code from Ruby. You can do all the heavy lifting inside your compiled C/C++ code module and then pop back into Ruby land, with Ruby you get the best of both worlds, what trade off! On the Ruby compiled front, there is the Rubinius project that takes a Ruby script and produces compiled code that is as fast as native compiled code written in C/C++. For those interested is producing client side software to run on a desktop, this is a project to definitely checkout.
The great thing about coding in Ruby rather than a compiled code environment like C/C++ is that you can run the code right away. With compiled code you have to deal with project management, compiling and linking code, file dependencies, and makefiles. To get up and running with C/C++ code there is a lot of setup work. With Ruby you’re off and running being productive, just write and run. Ruby also has an immediate interactive mode, known as the IRB. It lets you start-up a Ruby language shell where you can prototype and test ideas. It’s also an excellent environment to learn in and try out new Ruby software libraries called Gems. The IRB gives you immediate access to Gems functionality so you can learn how to use them in your code, this adds to your productivity and learning time is reduced.
Ya but what is Ruby on Rails?
Rails is a Web 2.0 development framework, it allows you to create websites much quicker than tradition web coding. Rails is the chainsaw for website building, Rails is developed using the Ruby programming language and it heavily employs meta-programming techniques. It originally was created at 37signals by David Heinemeier Hansson back in 2004, and is the single reason for making the Ruby programming language popular. Before Rails, Ruby was a fringe language back in Japan where Matz was having fun creating a new language for his doctoral program.
Rails use the Model-View-Controller (MVC) design pattern to separate areas of concern, with these domains it is much easier to understand Rails code. If you want to make changes to how a website page will look, you edit the View. If you need to work with the database, you use the Model. Finally if you want to deal with User interaction, you work with the Controller. Moreover, Rails use convention over configuration, it removes the major cause of frustration dealing with editing configuration files to get some software service working.
Rails makes working with database seem like one is using basic Ruby objects with properties. No ugly complex SQL statements littering your code. With Active Record and Active Model you get the magic of database interaction without the need to specify some database schema or declare database objects with all the fields before you can begin to read, write and update data in the database. You don’t need to create tables, configure a database, don’t even have to write code to connect to the database, it’s seamless and effortless thanks to the power of Rails. Sounds like magic doesn’t it!
As a result, you can easily switch between databases. A site using IBM DB2 as it’s database can be easily modified to use an Open Source solution like PostgreSQL with very little effort. You need to modify the database table “schema”, to add or delete a field, create an index, no problem Rails migration and Rake to the rescue. You write migration tasks in Ruby code not SQL, so you leverage what you already know, then run the task using rake. You don’t even need to write a rake task, the Rails generator takes care of all the grunt tedious boring work, so you can get on with what really matters, building a website.
Can you imagine having to test your entire website? Having to click and view each website page. Having to enter, modify, delete data maintained on the database, or test file uploads, it would be time consuming and just not feasible or scalable. Rails has a solution for this, it comes with a Unit testing framework, which helps to assure the quality of the code. Unit tests aids in catching software bugs early that results from code changes. The test cases make sure the code is doing that one thinks it should be doing, that is handles errors properly when they occur. Having an automated testing framework is great, breaking changes are discovered immediately not days, weeks or months after the code has been released into the wild. Any true Rails developer will tell you they follow the Test Driven Development (TDD) process, where unit test code is written along with production code. Each new function will have one or more test case before it’s fleshed out. This way, production code will have full coverage when it comes to testing. Both Ruby and Rails themselves come fully unit tested.
Ruby on Rails gets really exciting, when you factor in all the Ruby software written and shared by the community as software modules called Gems. You want to create a PDF document, manipulate images, draw charts, there is a Gem out there for each. Since it’s Open Source you will have many hackers using them, with many eyes finding and fixing bugs. This is the true power of open social engineering! End result is better written software with higher quality when compared to someone trying to reinvent the wheel for themselves. With the benefits of these gems, one can easily stitch together ideas and websites much faster.
To round it all up, Ruby on Rails gets you faster to market, encourages good coding practices. Uses conventions which once learned makes it easy for any hacker to understand someone else Rails app. The code is of high quality since it’s been united tested. Ruby lends to clean concise coding making it much easier to maintain and read. Best of all Ruby, Rails and Gems are all free. That’s right, you don’t need to pay some corporation a hefty licensing fee to use it.
These are some of the many reasons I love Ruby and Rails hacking!