Programming Pearls Clmn 5

A Big Matter of Programming

Lu Shengliang
Programmers Don’t Read Books

--

Scaffolding

My understanding of scaffolding is a skeleton of your code.

Let’s say there are 3 main procedures/levels of my code/building. What I need to do first is build up a skeleton/scaffolding. I put this skeleton or scaffolding suitable for my main function, after which I can do construction of certain parts of my code/building.

Coding

Coding is just construction of each level of your building. This part contains functionality implementation, integration and build.

Testing & Debugging

Testing is totally different from debugging.

Testing is trying to proof that your code is wrong.

Debugging is trying to make your code always right.

Timing

China Kung Fu believes that, the speed is the most important part of Martial art.

I can say, a fast program and a good time can make you be proud of yourself.

5. Partial checking for unsorted array

There is no “correct” answer here. So I just share my solution.

I. Firstly, I thought we can just compare the adjacent element. For example, I got the final location at x with target found or not found (doesn’t matter). I can use a[x-1], a[x], x[x+1] to form a tuple with element in increasing order. If so, this might not be unsorted.

Obviously, this is not safe.

II. Secondly, I checked the answer which suggests us find a log(n) algorithm. So I would like to do another test:

If a[1], a[2], …, a[x/4], a[x/2], a[x], a[x*2], …, a[x*2^k] (x*2^k < n) is in an increasing order, the we could say that the list is sorted.

Again… this is not safe. LoL.

I will add more ideas here, if I found some. ^_^

Bug in your code is not a magic show. Remind yourself that the impossible is not possible!

--

--