Tuesday, August 11, 2009

Pseudocode Programming Process

Today I had to implement a feature on project I'm working on. The feature was not a trivial one. It was rather complex. I had a general idea how it could be implemented. The implementation I was having in mind involved several complex data structures and some recursion function calls as well. After short thinking about the problem I started to do the actual implementation in C#. To be more precise I tried several implementations, but I kept failing, and found myself rewriting the code over and over. I was completely lost in complexity of the problem and all the details (complex data structures and recursion calls). I kept doing so for about 1.5 hours (maybe two), and I still had no working solution. Then I realized that I have to change my problem solving approach.

If you have read "Code complete" book you probably remember Pseudocode Programming Process (PPP) that Steve described in the book. Pseudocode Programming Process is a way of designing algorithms in pseudo code. Basically, this means that an algorithm is described in high-level English-like way. You can find more about the PPP on following links:

Anyway, after writing down the algorithm in high-level English and then making every line of comment into a line or fewof code (applying PPP practices), I had working solution in about 20 minutes. YES, 20 minutes including pseudocode and C# implementation. How that compares to 1.5 hours spent for literally nothing? I can only but recommend PPP as way of handling complex algorithms.

1 comment:

  1. Hi,

    What I usually do is write my goals down. Then I write solutions:
    this forces my mind to think of multiple solutions. Then I pick the best one. This was for the problem solving approach.

    For programming I use the *tree* approach with boxes.
    If Situation 1 happens then Action1 then....

    Slavi

    ReplyDelete