Back to basics
Wednesday, September 30th, 2009I brought my unfinished sudoku solver code out of retirement as a chop builder this past weekend.
I was noodling around with it, primarily adding test cases (as I hadn’t worked on it since I’d built my C++ unit testing framework) and surveying the state of the code.
I was struck by how overengineered it was. Classes and objects flying all over the place. Sure, methods were relatively small (after some banging around) and to the point. But the whole thing seemed pretty damn overwrought, with an awful lot of the code being designed around managing the code.
It occurred to me that the couple/few algorithms were buried in this structural schlock, removing any possibility of elegance.
So I thought to myself I thought “self? YOU need to prove that you actually know how to program.
The best way I know to do that is by being forced to get rid of all that crap.
I’ve decided to go back to C. It’s the only way I’ll be able sure I’m not just hiding behind abstraction layers.
And so yesterday I kicked off a project with the simplest of makefiles, my testloop script and “main.c”.
It took some wrangling to get started (do I want to represent a sudoku board as char[9][9]? Or just as char[82]?) But once I’d proven that I could parse and serialize the boards (making creation of test cases a breeze) I was off to the races.
Two or three simple functions on top of that and most simple to easy boards were solved.
The wisdom of the approach became clear when I realized that I spent 20 minutes unable to determine why:
sprintf("[%s]\n”,serialized_board);
segv’ed all over the place.
Looking forward to finally getting my C legs back.

