Week 3 Day 5 - define_method(:meta_program)

Today: solo

As others have remarked, because of the holidays, the weeks and days are just pointers to lesson plans, and not actual days and weeks. I actually got to the end of the day yesterday and asked someone "what day is it?" honestly hoping that they'd say Wednesday. It felt like a Wednesday.

It wasn't Wednesday.

(week 4, day 2)

Today was all about meta-programming, centered around the ActiveRecord Lite pet project. Real ActiveRecord does a lot of the work of writing repetitive code for you, and our toy AR did a lot of the same things, albeit not as gracefully. Meta-programming itself revolves mostly around defining methods at runtime that build out in predictable ways, so you can do all that cool stuff for free.

It's actually quite nifty, if only you are able to keep track of who will be calling each of the methods you write and where. In essence, Ruby offers faculties that permit you to give methods to a class or an instance (or an instance of a class…); variables can be local, or belong to the instance, class, or class instance… I'm still not totally solid on all the distinctions. My coding style today was essentially "keep changing whether you say self or self.class or self.name or nothing at all until the damn thing passes."

Aside: A potential project for a later date would be to make a simple file full of classes, instances, and modules, and see how different things behave and what they think they are. To wit: I could make a Module that extends a Class, and see what that module's methods say they are, and then include the same module in the same class and see what the methods do when they're called by instances of the class…

A huge part of reading and understanding code centers around being able to simulate system state in your head, or at least to scan idioms and interpret them subconsciously. Like reading English, you can only leave so many pieces as null references, hoping to pick up their meaning through context, before the main idea of the block is completely lost.

Anyway, so I felt like I was lagging all morning, and yet again, once lunch had passed I picked up a lot of steam. (There's gotta be a better way to get through the morning doldrums!) I managed to complete the exercises with five minutes to spare, and it felt really good.

I was much more patient and thoughtful today than during Checkers. At lunch I thought this post would be starting with a discussion of my demons, but being aware of them and having to face them a solid day at at time seems to be working.