As a web developer, it’s important to understand the interconnectedness of the various parts of digital design and development. Like a bridge, each pillar supports the span, and if any one of them fails, the whole thing collapses. Bad design can ruin well-written code as well as badly written code can bury the most sophisticated design solutions. Every part plays a role in the desired outcome – a user-friendly product.
In earlier posts, we have given you some insight into the vocabulary, processes, and tools of web development. This post is going to continue that theme. We’re going to talk about one of the popular tools for web development – Ruby on Rails – and share with you some of its benefits and pitfalls.
Let’s start with a bit of history. Ruby is a dynamic, object-oriented, open source programming language with a focus on simplicity and productivity. Created by Yukihiro “Matz” Matsumoto, the original version of the language, Ruby, was first released in the 1990s. Today, it powers well-known websites such as the original version of Twitter, Hulu, Living Social, Basecamp etc. Many companies use Ruby in some capacity – BBW, Cisco, CNET, IBM, JP Morgan, NASA, and Yahoo – because Ruby has a framework which supports a high level of flexibility for developers.
“Ruby is named after the precious gemstone; it’s not an abbreviation of anything. When I started the language project, I was joking with a friend that the project must be code-named after a gemstone’s name (àla Perl). So my friend came up with “ruby”. It’s a short name for a beautiful and highly valued stone. So I picked up that name, and it eventually became the official name of the language.” said Yukihiro “Matz” Matsumoto, the creator of Ruby, in his interview about the roots of the programming language.
Ruby on Rails is an open-source web application framework for the Ruby programming language optimized for programmers’ sustainable productivity. David Heinemeier Hansson extracted Ruby on Rails from his work on the project management tool Basecamp at the web application company also called Basecamp. Hansson first released Rails as open source in July 2004. Major brands like Amazon and eBay even have Rails projects.
“Rails (Ruby on Rails) was extracted from my work on Basecamp—a project collaboration tool from 37signals. So it was motivated by needs, not predictions. And I believe that’s a big part of why we’re currently enjoying such success. I didn’t try to imagine what some programmers might need for a fantasy job. I just built what I needed to get my work done with a smile.” says another interviewee David Heinemeier Hansson, the creator of Ruby on Rails.
What is Ruby on Rails?
Models. Used to represent forms of data used by the app, they contain the logic to manipulate and retrieve that data. In Rails, a model is represented as a class. These forms of data are not low-level like strings or arrays.
Views. Templates (typically formed of a mix of HTML and Ruby code) that are used to build the data users of web apps see in their browsers or through other clients. They can be rendered as HTML for web browsers, XML, RSS or other formats.
Controllers. Provide the logic that binds together models (their associated data) and views. They process input, call methods and deliver data to the views. In Rails, controllers contain methods known as actions that, generally, represent each action relevant to the controller, such as “show”, “delete”, “view”, etc. The framework can be used with various operating systems such as Windows, Mac OS X and Linux; databases such as SQLite, MySQL, PostgreSQL; and web servers such as Apache and, Nginx.
There are a few core principles in web programming that drive developers’ approach to projects. One of the main ones is “convention over configuration” (CoC). In other words, developers don’t have to spend a lot of time configuring files if they follow standard industry norms. Rails comes with a set of conventions which improve development efficiency.
Another important principle of Ruby on Rails development is “don’t repeat yourself” (DRY). Developers should always look to avoid duplication in their code, and rather isolate functionality in small functions or files. This principle promotes the use of modular code, which is easier to understand, read and debug. When code is duplicated, the outcome becomes more complex, making it more difficult to maintain, and more vulnerable to bugs.
Ruby on Rails for web development uses Representational State Transfer (REST) architecture that governs the relationship between the client and the server. It helps create logic in the app, and produces code that developers find highly intuitive and functional.
Another great extension is RubyGems, a package manager that makes it easy to create and share software libraries (“gems”). It’s referred to as one of the big advantages of Ruby on Rails. RubyGems provides a reliable and simple system to install “gems”. Anyone can upload them to the central RubyGems website, making the “gem” immediately available for installation by others. The RubyGems website is where developers obtain the most recent version of Rails.
Benefits and pitfalls of Rails
Just like any tool or software, Ruby on Rails web development has its pros and cons that you need to consider before choosing it as your development architecture. Let’s take a look at those based on feedback from our developers.
Benefits of Ruby on Rails for developers
Large Community. Rails is more than a development tool; it is a large community of dedicated developers. Members share their work, often use the same tools, and support each other. The informal community provides a diversity of jobs, recruiters, meetups, conferences, examples of businesses building websites with Rails, and clients funding startups. It is no surprise that Rails is popular on the social coding resource Github, which is a great source of support for beginners.
Availability of gems. A “gem” is a software package that contains a Ruby app or library. Commonly it is used to extend or modify functionality in Ruby apps. Some “gems” provide command line utilities to help automate tasks and speed up the developer`s work. They are all publicly available at RubyGems.
Cost-effective. The process of building functionality with Rails is fast because it has a collection of open source code available within the community as well as a set of existing conventions. Ruby on Rails also runs on a free operating system and works with most free databases and web servers. These features mean fewer development hours, faster development process, and a lower overall cost.
Code Quality. Rails uses the Ruby programming language, which has a high level of readability. This aspect increases productivity and reduces the need to write separate documentation or comments, which makes it easier for other developers to pick up existing projects.
Testing. Rails was developed with a focus on testing and has good built-in testing frameworks.
Diversity of tools. Rails provides a tremendous variety of tools that help developers deliver more features in less time. For example, there are built-in templates for common functions and solutions.
Flexibility. One of the biggest benefits of using Ruby on Rails is that it is highly flexible and interacts easily with technologies and frameworks like AngularJS. This factor offers developers the opportunity to separate layers of the app and use multiple technologies.
Potential Ruby on Rails pitfalls
Performance. While Rails apps are often not as fast as Java or C apps, for the majority of them, Rails is fast enough. In general, Rails web apps slow down as a result of bloat, and a highly-skilled programmer can tune the code to improve performance. There is also the option of running the app under JRuby, which has the same performance characteristics as Java.
Hosting Issues. Not all web hosts support Rails because it can be more resource intensive than PHP-based sites. However, there are a number of hosts (Virtual Private Servers) such as Amazon EC2, EngineYard, Linode or Rackspace, which will fulfill Rails developers’ needs.
Popularity. The number of Rails developers is growing year by year as more people switch to it from other programming languages. Yet, Rails is still not as popular as Java and PHP, in all likelihood because the language is relatively difficult to learn, especially compared to PHP. However, one of the main differences between Rails and other languages is a large amount of open source code (“gems”) which is publicly available. “Gems” are helpful for beginners as they simplify the process of web development.
Lack of documentation. It can be hard to find good documentation for the less popular “gems”, and for libraries which make heavy use of mixins. Developers often end up finding the test suite playing the role of documentation and they have to rely on it to understand the behavior of the written code. This aspect isn’t bad in its essence, as the test suite should be the most up-to-date representation of the system; however, it can still be frustrating having to dive into the code, when sometimes written documentation would have been much quicker. That’s why it is sometimes mentioned among disadvantages of Ruby on Rails.
To sum up, Rails is a huge web app framework with a large number of built-in features. It can be used to create either small or large apps, but it tends to use more memory and resources than the other frameworks and performance can be a bit slower. In the majority of cases, Rails apps will be composed of dozens of files tight structure of models, views, and controllers. The framework is becoming increasingly popular because it is powerful, standardized, and well-established.
Check out our other articles on web development