| [ | Tags | | | automated tests, bdd, breakpoints, conditioanal breakpoints, debug, debugger, debugging, decrement, fold, increment, inject, perl, programming, qa, reduce, regexes, regexps, regular expressions, rspec, ruby, tdd, test-driven development, testing | ] |
| [ | Current Location |
| | Home | ] |
| [ | Current Mood |
| | accomplished | ] |
| [ | Current Music |
| | Christina Aguilera et al - Lady Marmelade | ] |
Ahoy mateys! Arrrrrrrrrr! Happy Talk
Like a Pirate Day!. In the piratey spirit, I decided today to get my
act together, and start working on a project I've intended to write. Since
I've been learning the Ruby programming language lately, I decided to write it
in it, to learn more about Ruby and to experiment with it. In this post
I'd like to blog about some of the facts I discovered that surprised me in
Ruby.
First of all, I discovered that Ruby regular expressions don't have Perl 5's
"\G" and /g feature that can be used to incrementally parse a string using
regular expressions. The closest thing I could find was using .sub! (with the
empty string), which does an in-place subtitution of a regular expression
The second thing I discovered was that Ruby did not have ++ or
-- operators - one has to use += 1 and -= 1.
When Ruby tried to parse a line containing "++" it yelled at me with
an obscure error, that caused me to need to incrementally comment-out
code until I found out what the problem was.
Another fact that disappointed me was that the Ruby debugger (ruby -rdebug)
does not seem to have conditional breakpoints (i.e: break at a certain line
only if a condition is met).
Finally, when I tried to do .inject { BLOCK } ("inject" is Ruby's
list reduce / fold method), without a starting element, I discovered that
it used the first element as a starting point instead of 0 or nil or whatever.
Doing .inject(0) { BLOCK } in my case fixed it. This fact is
documented in the documentation.
Otherwise, Ruby seems likable and I've been feeling I'm productive in it. I've
been using RSpec for writing my automated
tests. It's a so-called "Behaviour Driven Development" library,
which is the
same as Test-driven development, but RSpec is still nice.
|