If you’ve ever done any serious development in VB or the old VBScript, you’ve probably done something like this:
1 2 3 4 5 |
|
…which is highly readable, but a huge pain to debug, especially when trying to cut-n-paste into the query window. How many of us have learned BkSp-BkSp-BkSp-Down-End-repeat-ad-infinitum? In fact, if you were to take every ‘” & _’ and ’ “’ I’ve ever deleted and stack them up on top of one another, you would probably end up with a stack… well, several inches high. Let’s face it, electrons just aren’t that big.
Fed up with this state of affairs, many of us moved to C# for development, leading to:
1 2 3 4 5 |
|
In the computer industry, this is called “progress.”
Of course, if you wanted to make debugging simpler, you could stuff the entire string on one line:
1
|
|
…which is a lot easier to cut-n-paste, but a lot less easy to read.
Which is where Ruby comes in. Same query in Ruby:
1 2 3 4 5 6 |
|
Isn’t it bee-yoo-tee-ful? Readable, functional, and oh so copy-pasteable. Also, it does not require extra punctuation to patch together a simple multi-line query.
There are about 19,000 different ways to define a string in Ruby, but it’s the simple timesavers like this that make the language really shine.
Of course, if you were using Rails, you could just
1
|
|
…which just goes to show how much smarter and more sexually attractive Railers are than everybody else.
NOTE: Originally, I was going to include connection and execution of the query, but that would have blown the VBScript and Ruby examples up an extra four lines of code each. Using recommended practices, it would have bloated the C# code up another 15 lines, plus a stored procedure definition.
The Rails example would still have been only one line. Simplicity ftw!