How do you eat an elephant?

One of the largest struggles novice programmers have difficulty with is disassembling large problems into a logical set of smaller, solvable problems.

There is no code that is hard to write.  Writing code is not the hard part about being a programmer.  Take any problem and break it down into small enough sub-problems so that they’re solvable, and it’s all easy.  A large part of the skill required in being a programmer is in the ability to break large problems into small problems.

Novice programmers aren’t the only programmers who struggle with this skill either.  You can take a look at any piece of source code and make a pretty good assessment of the author’s ability to break problems down just by looking at the average line-count of the methods they write.  Generally speaking, coders who author longer methods are coders who aren’t breaking problems down far enough.  If they did, they’d have five methods instead of one–and they’d all be significantly shorter than that four-hundred line monstrosity they wrote (and they’re probably proud of it too because it probably felt difficult).  When you break your problems down far enough, you’ve naturally extracted your code into logic groupings that make sense as individual methods.  And this make those chunks of code far more reusable.

So, how do you eat an elephant?  One bite at a time.

You can’t possibly fit an entire elephant into your mouth, so pull out your fork & knife, and dissect that sucker into digestable chunks.  Eat one piece at a time.  Solve one programming problem at a time.

I recently saw a question posted online that read something like this:

How do I write an iOS app to randomly display a new image from file every 30 seconds?

That’s a big elephant.  The question is worded in such a way that implies that the user knows next to nothing about iOS app development.  There’s nothing wrong with being a novice, but when you’re asking this question without the slightest clue of where to begin, the only way anyone can answer this question for you is essentially by writing the entire app for you.  You’d be better of asking:

Does anyone know of any iOS apps I can download on my phone which randomly display a new image from file every 30 seconds?

So, let’s break this problem down.  Given this specific problem statement, what problems must be solved?

  • How do I create an iOS app?
  • How do I display an image from file?
  • How do I something every 30 seconds?
  • How do I select an image on file at random?

A novice programmer might know how to do all of these individually.  Or, they may know only how to do some of these.  They may even know how to do none of these things.  But no matter what they know, at this point, the problem statement has been broken down into digestable, solvable bites.

The first point (“How do I create an iOS app?”) is a large one which would take quite some time for a more experienced programmer to explain to a novice, but there are plenty of tutorials available on the web for getting into the absolute basics of iOS app development.

The next three points are all easily solvable with the tiniest bit of Google-foo.  If you can’t find an answer to all three of these problems on Stack Overflow (without posting a new question), you’re not looking hard enough.

Of course, every scenario is different, and all problems will break down into their own unique subset of smaller problems, but if you search online for a solution to your problem and you can’t find the answer, there’s a good chance your problem can be broken down still further.  Some of these small problems you won’t know how to solve, but some of them you will.  Start by solving the ones you can, then re-assess which ones you can and can’t solve with your current knowledge.  Chances are pretty good that in solving some of the other problems, you somehow figured out the solution to one of the other problems.  And even if you didn’t, if you broke these problems down into digestable chunks, chances are going to be quite high that someone has already posted the solution to this problem online somewhere.

And don’t forget, this particular advice can be applied to all facets of life.

Disassemble your problems so you can assemble your solutions.

Leave a Reply