Ruby Joy #2 - tight code

Posted on December 11, 2006 at 09:03 PM by John Repko

Ruby is a high level language, which means you can do generally something in Ruby in less language than it takes to describe it.

This is a life/time-saver in creating large systems, and with Ruby and Rails a little code goes a long way. For instance, in my manufacturing system Pikaplanner, if I'm assigning a product to a product family, I can create an HTML select statement that finds and collects all the product families in a single line of RoR code:

<%= select 'product', 'productfamilyid' , ProductFamily.findall.collect {|p| [ p.familyname, p.id ] } %>

A lot happens in that one line - I query the database (find_all) for all the product families, create an array of them (collect), and fill an HTML Select statement so that if the name of a family is chosen, the id of the family is assigned to the product.

A thousand lines of RoR can produce a useful system, and the blog code that underlies this post is about 3,200 lines of code, with 1,000 of them test code.

A good developer can keep 10K - 100K lines of code in his/her head. If it takes millions of lines of code to make a system, then you'll need a lot of developers, and nobody will understand the whole system. With Ruby/Rails, a single developer can create whole, usable systems, with the benefit of the consistency that comes from understanding the whole system. THAT is TIGHT.

Tags: Pikaplanner, Rails, RoR, Ruby, code
Hierarchy: previous, next

../themes/pikasoft/views../../themes/pikasoft/views../../themes/pikasoft.