My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
In class on Wednesday Venkat explained so well, yet so succinctly, what I'm loving so much about Ruby: the signal to noise ratio is higher in Ruby than in most languages.

One of his examples was to take a program that does absolutely nothing in Java:

public class DoNothing
    public static void main(String[] args)


And compare it to this one in Ruby:

Notice the difference?

Incidentally, the high signal to noise ratio is also what I like so much about Coldfusion. To run a query, you just do it. You don't have to go through the hassle of creating connections, statements, and the like. Just type in your query and go. Of course the drawback in Coldfusion is that in many cases, there is a lot of noise. For example, to create an object I have to write <cfset someObj = createObject("component", "long.Path.To.CFC")>, and let's not mention the tag syntax (at least I can use <cfscript>, though I rarely do).

In any case, I find Java's database access so hard to work with, the last time I used it in any significant context I created a fa├žade to do all the work for me. I'd just create an object of it, and pass in a query to run.

But, there's also a problem with building the queries in languages like Java and C#:

String theQueryString="select columnName from table" +
     " where someColumn = "
+ someValue +
     " and anotherColumn = " + anotherValue + " ... " +
     " order by " + orderBy;

Horrible! For long queries, that can get extremely unreadable. In Coldfusion if you need to create a multi-line string to keep it readable, you can simply do the following:

<cfsavecontent variable="theQueryString">
   put any text you want in here
   and as many lines as you

And I was happy to find out you can do something similar in Ruby:

   put any text you want in here
   and as many lines as you

The next great surprise from Ruby? You can add methods to a class at run-time (there is no compilation) quite easily. Suppose I wanted the absolute value method to work on a string. I could just do:

class String
   def abs
      "absolute value of string"

And no, it didn't overwrite the String class. So far, I am amazed. I know you can do the same thing in Coldfusion, but that doesn't make it any less awesome.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!

Leave a comment

one thing: the way you wrote the java sql stuff is indeed horrible, however this is not the way it is currently done these days - you just put some question marks instead of the string concatenation you just did, then work through prepared statement etc and you are done - and the framework does the encoding for you and everthing works smooth - really, the direct db access is not the place where ruby is way better than java; gotta admit there are others, but not this one...

Posted by Daniel on Dec 08, 2007 at 04:32 PM UTC - 5 hrs

That is quite true, however there are other uses for multiline strings as well - one is that if you have some text you need to process on you can just paste it in the file - no need to read it in from another file or break it into chunks.

You are right though - good catch. Keep me honest =)

Posted by Sammy Larbi on Dec 10, 2007 at 10:39 AM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)


Subcribe to this comment thread
Remember my details

Picture of me

.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Agile Manifesto & Principles
Principles Of OOD
Ruby on Rails

RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner