Programming styles and books

I confess, while I have my CS degree and am well-read, I’ve never read many of the “classics”: Clean Code, Refactoring, The Pragmatic Programmer. So with Sandi Metz’s “99 Bottles of OOP” on offer, I thought I’d make a start there.

I’m trying to be disciplined about finishing old books/courses before starting new ones, but I was so intrigued and dived in.

The book starts with an exercise that you’re supposed to spend 30 minutes on: Write the code to output the “99 bottles of beer on the wall” song.

I completed the exercise in 16 minutes with what I considered an elegant solution that was neither too abstract nor too concrete. I made a lot of “YAGNI” (You Ain’t Gonna Need It) calls, for example.

But here’s the kicker: it’s recursive!

public function verses( $start, $end ) {
    if ($start === $end) {
        return $this->verse($start);
    }

    return $this->verse($start) . "\n" . $this->verses($start - 1, $end);
}

I’m sure that this is not optimal in many ways. But the fact that, while working in a hurry, this solution came to mind tells you something about how I was taught computing. I’m very curious about where this book goes and what I learn from it.

So on we go…with an open mind!