Sunday, October 7, 2012

Ruby Is Better Than Everything

It was bound to happen.  I was an easy target, after all.  In any case, I expect the flying seraphic yaks of the sky-hipsters will be along to whisk me over the mountains to Portland any moment now.

In the meantime: moar tasty blag.

I've always been a little put off by the fact that posttest and pretest loops are so named.  Call me crazy, but if a loop were really posttest, wouldn't it come... after the test?  And before the test for pretest, right?  Makes sense to me, at least.

Here I join my voice to the communal "Whut?" regarding Python's inclusion of an optional else clause with its for loops that's been initiated by Cara over here.  This is a singularly useful abomination, though, and I could honestly see myself writing one of these in the future.  Readability be damned (not actually, but I don't see how it interferes with readability so much).

Why is it that so many languages, including Python, have constructs like range(x) return all the numbers up to but excluding x?  Strikes me as a little counter-intuitive.  I'm sure they have their reasons, though...

And one last thing:
It sure is neat that we can use something like

for (ptr = root; ptr!=null; ptr = traverse(ptr)) {
//tentatively fixed, because I think the book
//may have erroneously printed ptr==null for it's control expression
...
}

to traverse our data structures.  I didn't realize this before 8.3, and it's a swell thing.

2 comments:

  1. The "pre-test" "post-test" ambiguity you highlight extends outside programming languages as well. For instance, when doing a study, you might have participants take a pretest, do something, and then take a post-test to see what they-learned.

    I can see how you could read it either way.

    ReplyDelete
  2. Ah, see, in that case I think it makes sense. You're having them take a before-test or an after-test, as the case may be. The problem I have with the programming language application is that we sound like we're referring to the loop itself as "pretest" or "posttest", rather than it simply being a loop WITH a pretest or a posttest. If that makes sense.

    ReplyDelete