Solution by proximity

It’s a weird feeling. It’s sometimes frustrating too. I’ve felt confused, confounded and conflicted. Before I tell you more, I need to tell you about…

The wise sorceress

Polgara the Sorceress was famous, respected and feared. At a king’s house, she’s well received. Of course, the fact that she could turn His Majesty into a toad might have something to do with the warm reception.

But she’s really a nice person. And when she happened to stay, sometimes, in the mornings, people come knocking at her door. Like the queen. Or a good friend. They’d knock at her door, and be surprised when she calls them in by name, even though they didn’t speak, only knock.

Hesitantly, they’d open the door and enter her room. “Tea?” offered Polgara, holding a cup of her own. Some small talk would ensue, and then they revealed the real purpose of their visit.

“Oh I don’t know what I should do. Perhaps I could…”
“I want to do that. What do you think?”
“I suppose I could talk to him. Do you think he’d listen?”

Inevitably, they’d come to their own conclusions, and decide for themselves, and thank Polgara for her assistance. Polgara didn’t really say or do much. She nodded and encouraged them during most of the conversation.

“Another cup of tea?” she offered.
“Oh no, thank you. I know exactly what to do now. I really should be going. Thank you.”

Manifestation of a super power

It started when I was studying in the university. I was in the computer lab doing the programming homework tasks together with more than 10 other students. Having completed the core programming task, I set out to refine the code, what was termed “beautifying the code”. You know, making it presentable and hopefully scoring a better grade.

So my friend, knowing I’ve completed my homework, came over to my work desk and asked for help. She said she’s been getting segmentation faults and had been poring over her code, but couldn’t find out what’s wrong. She tried different stuff, recompiled her code, got other kinds of errors, fixed those errors, and still wound up with the segmentation fault.

So I walked over to her desk with her, and she sat down, and on a whim, recompiled her code. She ran her program, and amazingly, it worked. She swore it failed just seconds ago. Well, she didn’t exactly swear, but she was fairly certain of the existence of the error.

Computers by Kohlerphoto
[image by Kohlerphoto]

I didn’t really do anything. I just walked over and stood there beside her. I nodded at the appropriate points in her explanation. That’s it.

Over the course of my undergraduate days, more than a few of these similar incidents had errors miraculously correcting themselves. Cannot compile program and don’t know why. Entered input and got a wrong output. The errors all went away and all I did was stand beside the frustrated coder.

This even carried into my professional career. A colleague told me he got a server problem, and asked me to take a look. So I walked over to his computer, and when he’s replicating the cause of the error, he couldn’t. The server became fine.

These sorts of incidents don’t happen a lot, but they occur frequently enough to catch my attention. Do I have a hitherto unknown super power? The power to solve programming errors by simply being near? Oh dear, my ego’s going to burst… *smile*

Sometimes, they already know the answer

Seriously, I’m not an egotistical buffoon. Ok, please forgive a slight laxity in modesty. You are a great programmer. Perhaps our awesomeness in programming is so awesome that the light from our awesomeness can wash away the evilness of compilation errors. Simply by being awesome, I mean, being there.

Anyway, I got to thinking. Maybe, just maybe, those people who ask you for help already know the answer. Or they’ve already gotten an answer, but didn’t know they did. They ask you, because you’re a nice person, and they respect you, and frankly they’d much rather ask you than spend another minute with that insidious error mocking them.

All you need to do is offer encouragement, and sometimes hope.

Psychic debugging skills are cool. I also think it wanes in awesomeness compared with Polgara’s power of solution by proximity.

Have you solved someone’s problem lately by simply being near?

Solve the given problem first

Solve the given problem first
Ignore other thought tatters
Like water filling need of thirst
It’s the only thing that matters

Pondering the problem by Paul Kline @ iStockphoto

You’ve been given the software requirements. The problem is defined. The tasks are laid out. Yet half-way through coding, you start deviating. You think up cool new stuff to “enhance” the application. You’re distracted by the wonderful “features” you can add to make the application better. You’re not getting the project moving, and as such, you’ve become a bottleneck.

This isn’t about solving the actual problem, where the underlying problem is obscured by a superficial but seemingly real problem. It’s about coding against whatever is already discussed, decided and defined. It’s about doing what’s needed before doing what will be nice to have.

That rotozoom effect will be so cool!

Yes it will. Right after you finish coding the basic camera movements first. And that texture loading function. And that resource file management class.

I remember trying out as a hobbyist game programmer. I’ve played lots of role playing games. I know about sprites and 2D maps. I know about polygons and isometric maps. I understand orthogonal views and culling planes. I learned about colour mappings and Phong and Gouraud shading.

Coding the basic game code structure is incredibly boring and tedious. I’ve written “Hello World” equivalents for OpenGL and DirectX rendering, to test the basic code template. I’ve written functions to generate simple geometry objects such as spheres, cubes and pyramids. I’ve written custom import facilities to take in a 256 by 256 pixel bitmap as the game font, and render the individual letters correctly (try thinking about fixed and variable width fonts).

I was a student then, and didn’t want to shell out money to buy third party game frameworks. Besides, it’s fun to learn from the start. I just didn’t realise it involved so much work.

So I understand that sometimes, it’s easy to get sidetracked and go do something more interesting. Now older and wiser, I’ve gained the resolve and discipline to finish the basic stuff first. The fancy stuff can come after that.

I wanna do sorting as well

There was an incident where I did a quick impromptu tutoring on C for John (as I’ll call him). John was a freshman, and just started C programming as one of his courses. I was asked to help him with one of his assignments.

The assignment was a standard question where a list of students with their test scores were given (or were to be input). They were then to be given a grade, calculated by the answer program. Say 70-100 would be an A, 60-70 would be a B and so on.

The actual requirements in the assignment were simple. I helped John understand some of the compiler errors, and gave hints on how to go about coding some of the tasks. But he already had plans…

The lecturer set it such that there would be extra credit for, well, extra stuff (probably because the assignment was easy to begin with). What kind of extra stuff? “Well, you go figure it out!” the lecturer said (paraphrased). He did however dropped hints like user manuals, extra input information about students, and sorting.

John was obviously still in the process of understanding “missing semicolon” errors, and why scanf needs an ampersand before the variable name (if not scanning character strings/arrays). I was there at his house for a visit. It’s almost by coincidence that I was there. He obviously wanted me to help out as much as possible, preferably the whole assignment and the extra credit part.

So he asked me how to do sorting, for extra credits. He had difficulty understanding how to slot student scores into grade levels, which involved if-elses and “smaller than, greater than” comparisons. I’m not sure how much he could take in about sorting.

I told him to solve the basic assignment first. He wasn’t even done with all the required tasks. I advised him that all the extra credit means little if the actual assignment wasn’t even completed. I doubt his lecturer would award him full marks for that kind of work.

Beautify later

I’ve often had to resist the urge to add in extra display help, or create a better looking graphic. It could wait. I’ve already planned out the AJAX required for that snazzy display text. I’ve already decided which design elements needed polishing. But I needed to get the application working correctly first, right then.

It would be more user-friendly for the user. It would look more impressive to the customer. But it had to work first. What’s the point of it looking pretty if it doesn’t work?

Bake the cake first. You can add icing later.

Solve the actual problem, not the illusion

Have you ever finished a software project, only to find that the user really needed something simpler or even totally different? Ever solved your user’s software problem with an application only to find that it didn’t solve the big picture problem?

Are you solving the actual problem?

The one with the Excel report

There’s this project where my user wanted a consolidated report from one of the web pages in an existing web application. He just wanted to be able to have one more option from a dropdownlist, and he’d select that and be able to get the report he wants (there’s an export function to Excel).

I thought about it, and told him that it would require some effort as it affects some other parts of the application (even though it’s just one more list option). I asked further why he needed the report to have that functionality, and how he would use that exported Excel report.

It turns out that after he exported that report (once the additional change was finished), he’d use the summation function in Excel, and sum up one of the columns to get a figure. All that work just to get one number. I repeated what I understood to him, and he really just needed one number. It’s a monthly task he does, and he usually exports the entire report into an Excel file.

Due to the way the web page was structured, he had to export once for every option in that dropdownlist, then sum up the numbers in each of the exported Excel files to get that final number. Not very efficient, hence his request.

I want to emphasise this now. He doesn’t really want that extra dropdownlist option, because he would still have to do a summation. There are a lot of records and Excel has this internal 65536 row limit (pre-Office 2007), so it might not even be feasible to put all the records into one Excel file as he requested. What he really wants is a monthly sum total figure.

So I told him, I’d design a web page that specifically lets him export a report that is exactly what he needed: an Excel file with a month column and a sum total column.

If I had followed on his request as it was, I have done coding which didn’t help my user at all. He’d still have to do some calculations and manipulations with the resulting Excel file.

The one with the DataGrid columns

There’s another instance where the user asked me to do some table column width adjustments. The DataGrid displayed an HTML table that she didn’t like. She wanted me to shorten some columns and widen some columns.

And you know what? She doesn’t really want me to do all those column width changes.

What she really wanted was for all the displayed data to be on one line. Due to the column widths, the columns with more data (such as text descriptions) wrapped into 2 lines, making the HTML table longer in height. She’s still on her 800 by 600 pixel resolution screen, so scrolling up and down when there’s only like 10 records was making her cranky.

So I manipulated the table column headers instead. I broke some header text into 2 lines, thus shortening those columns. Hmm… let me show you instead. Say this is the HTML code

<table border="1" width="360">
<tr style="background-color:#eeeeee"><td>Text</td><td>Month Text</td><td>Total</td></tr>
<tr><td>This is the first description</td><td>200708</td><td>34</td></tr>
<tr><td>This is another description</td><td>200709</td><td>45</td></tr>
<tr><td>Oh my goodness, yet another description</td><td>200710</td><td>56</td></tr>

This is how it looks like
Shortening table column

What my user wanted was to lengthen the “Text” column and shorten the “Month Text” column. She believed it’d help a little if she gave more explicit instructions. What she really wanted was for all the data to be on one line, never mind the header text.

So what did I do? I forced the “Month Text” to break into 2 lines (even though it’s already broken into 2 lines by the browser) using the br tag, ending up with
Month<br />Text

With the forced break, the column “Month Text” automatically shortens, and because the table is on a fixed width, the column “Text” automatically lengthens, thus fulfilling her desired outcome.

If I had coded explicit widths into the td tags, it might not scale properly when other data is displayed. I’d also have the beginnings of a maintenance nightmare.


So what have you learnt? Sometimes, when users ask for something, they’re really looking to solve something else. What you need to do, is find out what that is, then solve the actual problem, not the illusory problem the user thinks they’re solving.

Two trains and a bumblebee problem

Bumblebee on flower @iStockPhoto/Eric DelmarI was intrigued by this math problem a while ago. It took me a couple of pages of calculations to get the solution. Then I kicked myself because the solution was actually staring in my face.

I can’t find the original problem now, although there seem to be other variations of it. So I’m going to give you my (highly embellished) version. Then see if you can get the answer. Here goes the story of Blitz the bumblebee and the fateful encounter of two trains…

Blitz the bumblebee and the meeting of two caterpillars
Blitz the bumblebee was an adventurous kind of guy. He’d wander further out in the fields than his fellow bumblebees. Now he’d seen these huge black caterpillars (trains) spewing out lots of grey and black clouds passing his fields before. Now Blitz, despite his big size, could fly very fast. But these caterpillars zoomed past him, leaving him in a whirlwind spiral as he tried to get back into control.

So one sunny morning, he decided to test his limits. He waited for one of these caterpillars, and when he heard their telltale “choo choo” from a distance, he started flying as fast as he could in the direction where the caterpillar would move. When the caterpillar moved close to his level, Blitz simply flew to the head of the caterpillar and hung on.

What a thrill! The wind was howling around him and the scenery was speeding past him. Then Blitz wondered where the caterpillar was going. So, using the caterpillar’s speed as initial momentum, Blitz took off.

To his surprise, he flew even faster than the caterpillar! So Blitz shot straight ahead. After some time, Blitz was starting to worry where he’s going, when he heard the “choo choo” coming from in front of him. Before he realised it, he bounced off another caterpillar. Somehow Blitz survived the bounce and flew, out of instinct, back in the direction where he came from.

This is fun!” Blitz thought. And wondered if he’d meet the first caterpillar again. Sure enough, the first caterpillar appeared, and Blitz bounced off it, and flew towards the second caterpillar. Through this bouncing and flying, it never occurred to Blitz what would happen when the two caterpillars meet.

When the two caterpillars were within sight of each other, Blitz realised that his bounces were getting more frequent. By the time this revelation came, he found he couldn’t stop nor get out of the bouncing cycle anymore.

They’re gonna crash! I’m too young to die!

And Blitz promptly fainted, while the two caterpillars amazingly brushed past each other and continued on their merry way…

The end.

The real math problem
Alright, maybe the original problem wasn’t phrased like that, so I’ll give you the short version.
Two trains and a bumblebee problem diagram
There are two trains running at 45km/h in opposite directions towards each other on two separate (straight) tracks. Assume for the discussion that the difference caused by the separate tracks is negligible. A bumblebee is positioned at the head of the first train. When the trains are 90km apart, the bumblebee flies at 60km/h towards the second train. When the bumblebee meets the second train, it returns and flies back towards the first train. It continues to fly back and forth in this manner until the two trains meet. What is the distance covered by the bumblebee?

I wrote down tons of calculations and numbers. I scrutinised my work and finally found a relationship between the numbers. Then I used mathematical induction to convince myself that the relationship can be written in the form of a geometric progression. The ratio of the geometric progression turned out to be less than 1, so that simplified the equation further. And the answer was … 60km.

Immediately after I got this answer, I found that since the time taken for the two trains to meet is 1 hour (time = distance / speed = 90km / (45km/h + 45km/h)), it also means the bumblebee only flew for 1 hour. With the speed of 60km/h, flying for 1 hour means a distance of 60km covered. I spent about an hour or so and a couple of pieces of paper to figure this out…

Moral of the story? Sometimes, it’s better to think through a problem instead of jumping on the first solution that pops up in your head.

Mathematicians make better programmers

Prove root 2 is irrationalMany programmers I know graduated either with a degree from computer science or obtained a professional certificate in programming. Yet simple programming errors or lengthy solution constructs still exist. These programmers only know the how, but not the why. Given a math graduate and a computer science graduate, both with similar academic results, you’re better off hiring the math graduate.

Abstract thinking
In solving problems, a mathematician comes up with a theory given what is known, and work towards a solution. For example, the Königsberg Bridge Problem was solved by translating what is known (the layout of bridges and land) into a mathematical equivalent, a graph of nodes and connections. Solving the graph theory problem is then equal to solving the bridge problem.

This ability to transform problems from unfamiliar to familiar grounds is crucial. Business requirements often have ridiculous conditions defying normal programming laws. An experienced programmer can draw upon his vast knowledge and piece together a solution. A mathematician can come up with an equivalent problem but is easier to solve. Tip: Hire the math graduate. He’s cheaper.

Naturally logical
I have seen program code with wrong if conditions, such as incorrect inverse disjunctions like if (!(p || q)) is equivalent to if (!p && q). It is disastrous to form wrong tests for conditional statements and loops, 2 commonly used programming constructs.

Mathematicians exhaustively explore all test conditions to ensure a complete solution. This ties in with their chain of thinking. A solution with sequential steps is only correct if all the steps are correct. If A then B. If B then C. If C then D. Therefore if A then D. What if B is false? Then the whole thing collapses. Mathematicians are used to checking their OR’s and AND’s.

Elegant solutions
In my university days, I used to fear the Terrifying Triple, consisting of a 4-letter, 5-letter and 7-letter word. They are “Show”, “Prove” and “Justify”. I get a lurch in the stomach whenever one of these words start off a problem.

  • Show that [whatever] is equal to [whatever]
  • Prove that [whatever] is true
  • Justify your answer

However these exercises made me shrink my answers to the most concise solution I could think of. The less of a solution to be picked on by my professor, the better.

I find that some programmers simply write a solution code to the problem at hand, and if it compiles, oh yeah! And if it does what it’s supposed to do, woohoo! Next! Unbelievable… This is why the following code exists:

void SomeFunction(){
   int i;
   i = 0;
   abcd[i++] = 111;
   abcd[i++] = 222;
   abcd[i++] = 333;

Either the original programmer don’t know that a literal number value can be used as the array index, or he just found out about post-incrementing and is absolutely ecstatic that he can apply his new found knowledge.

Problem solving
Mathematicians are used to grabbing theorems from say calculus and apply them to chaos theory. They are accustomed to interdisciplinary thinking. Thinking out of the box is good. Sometimes making the box larger is better.

Then there are the programmers who copy and paste example code without giving a hoot to what the code is actually doing or why the author coded it that way. Then they compile and test it, and ask why it didn’t work. The situation is different for the copiers and a slight change is required to make the example code work, yet the effort required to understand the code is beyond them, thus escalating the slight change into a major shift in thinking.

Programming is simply giving instructions to the computer to solve problems. Learning to program for the sake of programming is limiting to the focus on problem solving. Sure, math isn’t the be-all-end-all of interdisciplinary thinking. But it’s a start.