Brent Simmons gave me a sleepless night.

I had a really sleepless night last night, and it’s all down to Brent Simmons’ Black Box Parsing post on his weblog.

Why am I blaming him? Because it finally brought to the fore that I really need to clean up my code and make it far more object orientated (OO), something that has been nagging me for quite some time.

I’m afraid I’m a bit of a perfectionist, and this is probably one of my biggest sources of procrastination, something I realised just recently when listening to The Procrastinator’s Handbook: Mastering the Art of Doing It Now. Wanting to do something perfectly, is most definitely the reason I procrastinate the most, the idea of not getting something done to a high standard creates a lot of fear in me, and can stop me in my tracks.

However, I’ve already developed some of my application in a way which is congruous with OO development, and each time I add a new feature or need to modify a bit of code, I improve it a little and usually move it towards better using the OO features of RealBasic, probably because I’m learning so much more each time I sit down and start developing. I’m now at a point though that I really need to clean up a core part of my project, there are some new features I want to implement and can not do cleanly and efficiently with the current layout and communication between the data model, gui objects and controlling functions (see what I did there, Model-View-Controller :-) ).

What’s really bad is that I’ve been fully aware of the benefits of the Model-View-Controller (MVC) pattern for a year or two, since I first started looking at development on my Mac. Objective-C is a great OO development platform, and I’ve played with it and run through a number of tutorials and created a few play apps using the great free IDE called XCode on OS X, usually using the MVC pattern. So, why is it I didn’t use MVC properly from the outset when I started doing some serious development? Who knows, maybe I’m just lazy, or maybe I’m not lazy enough to use the productivity gains when OO is used to its full potential. Or maybe, I just got carried away and fell into the trap of whipping up a quick prototype, but not enforcing the fact that it really was a prototype and that it should be thrown away and developed afresh correctly with longevity in mind. Mind you, there are some people that believe a prototype should never be thrown away, that it should simply be improved upon and brought up to scratch rather than writing off the investment in it. I think I may go down the hybrid route; I can easily save elements of my project as classes, and even enforce this in my mind by making them external classes that can be picked up by other projects if I wish. This will help me get started in shifting the code around to get rid of some of the dependencies I built in between the model and view, and allow me to work on parts individually and swap in improved objects as necessary. That’s where the Black Box approach really comes in handy.

So, I’ve decided that next week will be an architecture design week, I will sit down and design the architecture of my app properly, making sure to keep the model, view and controllers separate, and to ensure that I allow the application to use different models without changing anything in the view, and only adding one hook in one of the controllers. I want to make my app able to switch between different database schemas with so much ease that I can quickly and easily add new models as new databases come to market in the area I’m targeting.

Should be fun, and once I’m happy with my design I may start sleeping properly again, until the next big idea hits that is!

No comments.

  1. I generally write the code and get it working, and then refactor it into objects. Or rather, a more accurate thing to say I do is I fire off a new project, write the function in the window’s open event, then move it’s functionality into a class or module and put it back in my original project. ;)

    MVC is nice, as are some of the other patterns, but remember that they are only guidelines, and whatever makes your code make sense to you is what you should do.

    (P.S. Nice blog :)

  2. Jonathan,

    Well, it sounds like so far I’ve pretty much been following the same coding pattern as you then, nice to know I’m in good company! :-)

    Thanks for the compliment about my blog, I must say I like yours too, just added it to my bloglines list, looks like I’m the first to do so on bloglines.

    I’ve just read a number of your articles on your blog, whooosh, straight over my head in most cases! However, I read your article on O’Reilly the other week, what a great article, I really enjoyed it and built the web server in not time at all myself from your instructions. Hope you can keep up the tips on your blog and have a chance to write some more RB articles on O’Reilly, great stuff.