Filing and printing work! Some bugs remain, and need to be fixed. But I now have a working app. YES!
I remain slightly confused about printing. What with the docs being complicated and the APIs “blurry,” I hadn’t expected printing to work when it did. But, I’d rather be lucky than good any day 🙂
I’ve completed a second implementation pass on the code in my major execution loop. I’d performed the first one with a dummied-up input file. This time it was with a “real” file, composed by my preprocessor. That file itself had been “seeded” by yet another pre-processor. While it may seem awkwardly recursive, this approach reduces the program’s task to a minimal effort (lacking “Strong AI”), something like the logarithm of the “brute-force” approach!
I have a short list of next steps to complete:
• Unit test and add a “validation” entry point to the souped-up engine.
• Implement some logic that wasn’t in the cards with its predecessor.
But I’ve taken a brief detour to refactor additional code. This time it felt even better. I got in and out in one session. I’d been coding very conservatively; In the beginning I wasn’t sure about anything. So aesthetics had taken a back seat to getting the program running. Sounds like Fred Brooks: “Plan to throw one away.” But with object programming, refactoring can work wonders.
I spent the day, refactoring part of my codebase. I’d used a “has-a” rather than an “is-a” mechanism to encapsulate some behavior, but felt it was awkward, so I switched over to using categories on NSString and NSMutableArray. My problem arose when I previously hit the wall trying to subclass NSString, which is a “class cluster.” My motto then became: “Never subclass a ‘class cluster’.” Now I’ve revised that to read: “Never subclass a ‘class cluster’; Add a category instead 🙂
I have an interface in which I want the first responder to be whatever control the user clicks on, even if it’s a button. I thought I was missing something, but I guess not. At tonight’s Cocoaheads meeting at Apple, Scott Stevenson suggested that I subclass NSButton and override NSButton’s click method to tell the window to set the first responder to self. It worked!
I used “mouseDown” instead of “performClick” which had initially looked like the thing to do. And the window method is “makeFirstResponder.” For some reason I’d expected it to be “setFirstResponder.” It finally dawned on me to look around the API a bit 🙂
@interface MyButton : NSButton
– (void)mouseDown:(NSEvent *)theEvent;
– (void) mouseDown:(NSEvent *) theEvent
BOOL isFirstResponder = [[self window] makeFirstResponder:self];
It was nice to find this: Google Code Search. I just started using it. I’m still amazed by what it finds. Now I need to develop effective “winnowing” patterns.