Regarding Ruby (and Ruby on Rails)


Your colleague Manton is talking about how Ruby on Rails is poised to take over for PHP as a better solution for rapid web-application development. In general, you agree with him – but there are some issues that a person new to programming should be aware of before they decide to start off on the path to Ruby (and Rails). This is because Ruby’s syntax – and its underlying process – isn’t as traditional as many other languages. Starting out with Ruby (as many people undoubtedly will) may make the transition to other languages down the road a bit of a challenge. More on this later.

You’re really writing this post for a colleague of yours – and anyone else – who’s been toying with the idea of learning Ruby as a first language. You think they should learn Java first and Ruby second. This post attempts to justify your reasoning on the subject.

Low vs High: A Quick Explanation


When people describe a programming language as being either high or low-level, they are talking about how much the lanugage “handles” for you behind the scenes and, quite often, how “readable” the source code is. In general, higher level languages, while often easier to code with, don’t offer quite as much control over the deeper functions of the computer. Things like this apply more to native application development (software that runs on the local machine, like a web browser or word processing application) rather than a web-application, where the programmer rarely cares about things like memory management or screen buffers.


Assembly Language is probably one of the lowest-level languages you’ll find, followed by C and C++. Languages like Ruby are much higher level.

A Disclaimer


You’ve been programming since you were a kid, starting sometime in the year 1983 on an Apple II using BASIC. You’ve moved through a number of languages over the years, including Modula, Turbo Pascal, a bit of C and C++, Perl (when you were a sysadmin), ColdFusion, a little Python and Ruby, a few days of Objective-C, a lot of PHP, and quite a bit of Java.


At the end of the day, your favorite programing language is still Java. It’s clean, structured, and generally well-behaved. It lets developers do things their own way but imposes a set of rules to help keep them in line. It handles the ugly things (like memory management) for them, but leaves enough wiggle room for them to do some pretty interesting things. There’s a great community surrounding Java development too, and that’s a real asset to beginners and experts alike.


You’ve even built some Mac OS X applications in Java, like the first two versions of the Enkoder, tying the behind-the-scenes Java code to a front-end built in Cocoa, built using Interface Builder and Xcode. It was a “native” OS X application that looked and felt just like any other OS X app. It was hard to do it this way because Cocoa’s Objective-C documentation is much more robust than the one Apple provides for Java. But it worked, and you felt that with more practice, it would have gotten a lot easier.


Sure, Java can be a bit long winded at times, and quite a bit of a developer’s time writing Java code is spent staring at the API. It’s also somewhat unfortunate that JSP, Java Server Pages, can be so tough to work with. It’s not a rapid way to develop web-applications, and the implementation details can be a challenge. Struts seems to help, but it’s far from perfeect. And good luck finding a reliable webhost that supports a well-known servlet container like Tomcat effectively – or at all. Java technologies like JSP and EJB work very well in the Enterprise, but for typical web applications, it takes a trememdous amount of work to do even the most simple things.

PHP


PHP is everywhere. It often ships pre-installed with Apache in many operating systems, including Mac OS X. Most if not all UNIX and Linux-based webhosts include PHP with even their most basic hosting plan. Because PHP is so easily installed and configured, it’s popularity has increased – and the inverse is also true.


Despite PHP’s shortcomings, you’ve learned to appreciate it. In fact, you code in PHP almost every day. You started with PHP in the late 90’s and have seen the language evolve quite a bit. Over time, you’ve created methodologies in PHP that make developing web-applications much more straight-forward. You’ve settled on conventions that help make the source code you write more readable and understandable. But these steps build on your experience with other languages and also take time – extra time. And this extra time negates one of the benefits that PHP was supposed to provide: rapid-application development. Once a PHP developer has built a framework they’re comfortable with, the rapid-aspect returns to their development and the turn-around time decreases, but too few PHP programmers go to this level. Too often, code just gets “hacked-together.”


Sure, developing an application in PHP is still a bit faster (and less humiliating) than building something in JSP, but it’s not as rapid for new developers as it could be if there were a solid, well-implemented web-application framework that had been married to PHP early on … like the one Rails provides. With Rails, even first-time programmers start with a coherent, documented foundation. PHP gives you nothing. It’s up to each individual programmer to figure out the right way to do things … and to define what the “right way” really is. Unfortunately, only experience can help define that, and by the time most programmers have reached this point, many poorly-implemented systems will have been developed, deployed, and delivered, landing like a plague upon their recipients.


So then, why do you code in PHP at all? Mainly because the web-applications you’ve been developing in recent-times have been deployed on UNIX, Linux, or Mac OS X platforms. They needed to speak to MySQL databases, had to ship with source code, and often needed to be developed quickly. In most cases, PHP was actually specified or required for the project. Other times, the servers you’d be deploying on wouldn’t have the needed sub-systems, like Tomcat or JBoss, in place to deliver a JSP application.


For you personally, PHP often just makes the most sense. With the framework you’ve built, you can stand-up a solid, reliable PHP application quickly and focus on adding features and improving usability. Because you’ve spent so much time with PHP, you’ve learned how to make it behave. If the developer is careful to use the conventions learned by developing for other languages like Java (which, as mentioned, enforces structure), PHP can take on some decent qualities and stretch into a decent platform for web-application development.


Unfortunately for newer PHP developers, this is rarely the case. They’re on their own.


Ruby on Rails offers an object-oriented development platform and a solid web-application framework. It seems like it may eventually replace PHP, which itself seems destined to the life of an over-implemented, omni-present scripting language embraced by new, overzealous programmers who create low-quality code they barely understand.


To be sure, you’ve seen far more bad PHP code than good – but most often, this isn’t the fault of the developer as much as the nature of the language itself. One needs to work hard to create good PHP. It takes effort! Manton makes this point well when he describes PHP as having “haphazard function naming, poor object-oriented features, and difficulty [when] designing large applications.”

Back to Ruby


Rails provides developers with a solid platform upon which they can start building applications quickly and easily. As Manton points out in his article:


Rails is a perfect fit for anyone who develops for the web on its own terms, and the people behind apps like Basecamp, 43things, and the upcoming Odeo match that profile.


The potential for Rails is huge and the window of opportunity for its success is opening wide. There’s a good chance for it to leap out and become much more mainstream.

Ruby Is High Level


On its own, Ruby is a great language. It’s fast, complete, and effectively implements some of the best things from other languages like Java, PHP, and Python. Add Rails to the mix, and Ruby makes rapid application development a reality.



Some may argue this point, but it’s your opinion that – perhaps because of its easy syntax and simple implementation – Ruby may not bethe best language for people new to software development and programming. Ruby makes a great second programming language, one that more experienced developers looking for a way to rapidly build and deploy an application might look to. But because it does so many things for the programmer – and in such a unique way – moving from Ruby (as a first language) to another language like Java or PHP later on could prove to be a huge challenge with a big learning curve.



You’re speaking from experience here: In your early days as a programmer, you remember the struggle in moving from Turbo Pascal – a higher level language – to a lower level language like C. It seemed frustrating to worry about things like memory allocation – something even beginning C developers have to consider. But the power that experienced C and C++ programmers weild over their applications is considerable. So there’s a trade-off.


It’s The Goal That’s Important


If the goal is to become a software developer, it’s always best to start with a structured language that doesn’t do too much work for you. Java is often used as a teaching language for new developers. While it’s a higher-level language than something like C or C++, there are similar foundations there that translate well in both directions. That is to say, if you want to become a programmer, learning Java first will lend itself well to learning both higher and lower level languages down the road. Sure, Java handles things like garbage collection and memory allocation for you – and doing this manually can be tedious (at first), but programmers will truly appreciate the benefits of the time-saving features Ruby has to offer – without being limited by them! Developers who start with Java or C – or even PHP – will truly know what they’re gaining (and losing) with a higher-level language like Ruby.



Further, PHP is often a person’s first experience with and exposure to programming. Adding PHP to a web page is often as easy as changing a file extension from .html to .php and adding a tiny snippet of PHP to the source. In this way, PHP is the “gateway language” to other programming languages.


A Brief, Misplaced Example


Consider something like the implementation of the for-loop in Ruby. Taking an example from Ruby’s own documentation, if someone wanted to display the numbers 1 through 5 in Ruby, they might do it like this:



5.times do |i|
print i
end


The benefit of syntax such as this is that it’s easy (enough) to read, and shows off one of Ruby’s great strengths: it’s truly object-oriented nature. Ruby knows that “5” is a number, but intelligently treats it as an object. The number “5” suddenly has methods, one of them called times. Executing this method tells Ruby you want to repeat something based on the value of the number/object “5”.



If you ran that code, you’d get this:



12345


But consider how you’d do the same thing in a language like Java:



for (i=1; i < 6; i++) {
System.out.println(i);
}


A bit tougher to understand at first glance than the Ruby, but now look at the similarities between the above example in Java, and the example below in PHP:



for ($i=1; $i < 6; $i++) {
print($i);
}


It’s almost identical to the Java. Now, here’s the same thing in C:



for (i=1; i < 6; i++) {
printf(“%d”, i);
}


Again, almost the same as Java. Finally, here’s another example, this time in Perl:



for ($i=1; $i < 6; $i++) {
print($i);
}



It’s identical to the PHP, which is similar to the C, which is almost identical to the Java code. The point here is, as nice and compact as the Ruby is, it’s different enough from every other language that a new developer who knows only Ruby will have a steep learning curve when trying to convert their skills to a new language or a new job. And the differences only increase as the software becomes deeper and more complicated.




In many ways, they’ll be starting over.


At Last, The Conclusion



So what are you really saying, here? You’re saying that Ruby on Rails is great, and may eventually take over for PHP as the web application development language of choice for small and medium sized projects.




But new programmers should remember that there will still be a big learning curve down the road to translate there experience with Ruby to something lower like Java, C++, or even PHP.

More articles in the Archive →