Category Archives: Learning to program

Programming Unleashed – Or should it be Leashed?

Unleashed by the Book

If you browse in the computer-book section of any well-stocked bookstore, you will usually come across two or three books titled “Xxx Unleashed” where xxx is something to do with software. Developers can choose from titles like Java 2 Unleashed, JavaScript Unleashed, or PHP Unleashed. For system administrators there are titles like Windows Server 2012 Unleashed. (If I was a company’s IT manager, I’m not sure if I would want my sys admins, with their digital powers and privileges, to be really unleashed.) And if you want to take a break from screen and keyboard for a few minutes, there’s Doodles Unleashed to help you goof off productively.

I have a bit of a contrarian streak, so I thought to myself that it would be amusing for someone to publish a “leased” book. What might you learn from a book called Java 2 Leashed if it existed? (It turns out there are some “leashed” books but they are found in the romance and fantasy sections and have covers that would discourage anyone from reading them on public transit which may explain why most are available only for e-readers.)

What is an Unleashed Programmer? Two Views

However, having observed software being developed  by professionals, I am starting to think that there might be something serious with this contrarian idea. Perhaps production software could benefit from developers choosing to have a “leashed” mindset. Let me explain.

The term unleashed brings to mind two separate meanings:

  1. Able to roam anywhere. This unleashed dog in the park roams to any corner of the park and snuffles around wherever it likes. Similarly, an unleashed programmer can roam to any corner of the documentation, understand it, and figure out how to use any feature that the programming system offers.
  2. Able to act without restraint. This unleashed dog does whatever it wants in the park: jumping up on adults, knocking over little kids, and leaving doggy doo surprises. Similarly, an unleashed programmer can use whatever programming tricks, copy-pasted program snippets, or code hacks he can think of until his code passes the documented test cases. Continue reading

Examples of Recursion: The Good, the Bad, and the Silly

What we need: a really good example

The programming artefact of recursion, also known as “writing a subroutine that calls itself”, is well known to generations of students of computer science. Recursion is a reasonably simple yet a remarkably powerful concept. That is, it’s a reasonably simple concept once you understand it, but unfortunately, it can take some effort to get that understanding.

Teachers of computer science are faced with the challenge of finding good examples of recursive programs to offer to their students. The ideal example will demonstrate the principle of recursion clearly while hinting at its power, and thus show why it’s a compelling concept. Over the years I have come across examples of recursive programs, enough now that I think I can classify them into three broad categories: the good, the bad, and the silly. Here are the categories, each with an example:

The Good: Towers of Hanoi

Drawings made around 1884 of a Towers of Hanoi puzzle, showing the initial state, an intermediate state, and the final state.Towers of Hanoi is a puzzle that consists of three posts, and a set of disks of different sizes with holes in the middle so that the disks can be stacked on the posts. You start with all disks stacked on one post, ranging from smallest to largest, top to bottom. Your job is to transfer the stack from the first post to the third, using the second post for temporary storage. You can only move one disk at a time, and you can never place a larger disk on top of a smaller disk.

The puzzle can be solved easily by breaking down the job into smaller jobs. To move the entire stack of disks from the first to the third post, do these steps:

  • Move the (slightly smaller) stack of all but the largest disk from the first to the second post,
  • Then move the largest disk from the first post to the third,
  • Then move the (slightly smaller) stack from the second to the third post.

The middle task is a simple step – just move one disk – but the first and last steps each require solving again the Towers of Hanoi puzzle but for a smaller stack. In other words, solving the full puzzle requires solving two simpler instances of the puzzle. Continue reading