28 September, 2007 | Written by Vincent Tan 1 Comment

Undersized development team - Are you in one?

Are you in a software development team with less than ten members? Less than five members? Just three, including you?

In a small sized team, priorities and responsibilities may start getting mixed up, where each member can generally take the place of another. This is fine, and there’s an additional condition. Each member must also be extremely well-versed in an area of the team’s responsibilities.

For example, in a team of three, one member (usually the team leader) takes on documentation, business logic and the overall big picture. One member takes on the back end process flow, making sure the backbone of the project is running smoothly. And the last member takes on the front end application design.

Why is this segregation important? Let me contrast this with a larger sized team first. With more people, a task may be assigned to several people, and the collective knowledge of this group is used to solve the task. Any team member can also more or less take on roles and responsibilities of another team member in this smaller group.

As the team size gets smaller, this collective knowledge and role flexibility shrinks. When you’re dealing with a small team, every member counts. Each member has to be an expert in their own circle of responsibility, or the effectiveness of the team suffers. Treating each member in this situation like a plug-and-play component is a disaster waiting to happen.

So how can you help yourself? Learn to say no. Multitasking with other team members’ responsibilities is the fastest way to drain your energy and compromise your own output quality. In the event that you have to take on another person’s tasks (say the person’s on leave), then prioritise. Find the tasks that helps the team most, and then do those, even if they aren’t originally your responsibility. This way, the team moves forward, the project gets closer to completion, and the users are happier with the support.

If you can, get good help. Even one or two more team members can help the overall effectiveness of the team (try these for some hiring arguments). This is different from adding people to projects to make them go faster. What you want the additional members to do is alleviate some of the independent tasks off the existing members. Then slowly spread out tasks more evenly amongst the team members.

26 September, 2007 | Written by Vincent Tan 1 Comment

Back to Basics - Sierpinski Triangle

I remember back when I was first learning C, and one of the assignments was to draw the Sierpinski Triangle. I didn’t know what it was, but sequential steps were given to iteratively create it. The steps were roughly like so:

  • Generate a triangle on a plane with 3 points
  • Set the centre of the triangle as the current point
  • Randomly select one of the triangle points
  • Get the mid-point between the current point and the selected point
  • Plot the mid-point and set it as the current point
  • Randomly select one of the triangle points
  • Get the mid-point between the current point and the selected point
  • Plot the mid-point and set it as the current point
  • Continue till iteration limit is reached

I was told to visualise the plane as a matrix, and the plotted points were to be printed as asterisks on the screen.

It’s been years now, and I still think the screen output of my Sierpinski Triangle sucked because of the low resolution. Now, older and wiser, I can come up with a better representation.
Sierpinski Triangle

Download the full source code.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace b2bSierpinskiTriangle
{
    class Program
    {
        static void Main(string[] args)
        {
            const int cnSize = 512;
            const int cnLimit = 50000;
            int[,] points = new int[3, 2];
            points[0, 0] = cnSize / 2;
            points[0, 1] = 10;
            points[1, 0] = 10;
            points[1, 1] = cnSize - 16;
            points[2, 0] = cnSize - 16;
            points[2, 1] = cnSize - 16;
            Bitmap bm = new Bitmap(cnSize, cnSize);
            Graphics g = Graphics.FromImage(bm);
            g.FillRectangle(Brushes.White, 0, 0, cnSize, cnSize);
            int trianglepoint = 0;
            Random rand = new Random();
            int currentx = 0, currenty = 0;
            int previousx = cnSize / 2, previousy = cnSize / 2;
            for (int i = 0; i < cnLimit; ++i)
            {
                trianglepoint = rand.Next(3);
                currentx = (points[trianglepoint, 0] + previousx) / 2;
                currenty = (points[trianglepoint, 1] + previousy) / 2;
                bm.SetPixel(currentx, currenty, Color.Navy);
                previousx = currentx;
                previousy = currenty;
            }
            bm.Save("sierpinski.bmp");
            g.Dispose();
            bm.Dispose();
        }
    }
}

Short and sweet. Instead of printing to the command line screen, I plotted the points to a bitmap. I still remember printing my program listing and the Sierpinski asterisks output. Though pleased with the required output, I thought it looked a little unrefined around the edges.

Printing to a bitmap at pixel level makes it look much better…

24 September, 2007 | Written by Vincent Tan 1 Comment

Path of a Polymath Programmer Part 5

I’ve talked about how stories, typing, role playing, console games and self-learning Japanese so far. Quick links here for reference:

Continuing the console game part, I started noticing more about the games than actually playing them. I marvelled at the graphics (it was mostly pixel art then), and appreciated the game music. Immersed in the story plots, I identified with the characters (I still have sniffles when I think of Celeste losing her grandpa in Final Fantasy VI) and got lost in the fantastic worlds the game creators forged.

I was in the Chinese orchestra then, so I had begun learning about music. It was at this point that I found I could separate distinct music pieces in the same song played by different instruments in my mind! There’s the main melody, the supporting melody, and the bass or beat carrying the song through.

Fast forwarding… got drafted into military service. Learned to harden will and tons of self discipline and self reliance. Fast forwarding…

University life!! I would eventually major in applied math and computational science. What’s the difference between computer science and computational science? You can read the short description here. You will also notice that a lot of my sample program source or topics tend to focus on math and science related stuff.

With university life came a lot more freedom in how I use my time. I watched tons of television shows. Ed. Friends. Gilmore Girls. Ally McBeal. Charmed. CSI. Andromeda. Alias. Sliders. I also watched tons of movies (my friends usually find out about the latest movies from me). Lots of stories and plot lines. Improved listening skills and English language (I’m in Singapore, and sometimes the English spoken here leaves a lot to be desired…).

Also with university life, I needed a computer. So finally, I got a proper computer so I could print notes and reports, and do some light programming. If you’re doing C/C++ programming on the Windows platform, I suggest the Dev-C++ software. I was writing code on the *nix platform, but sometimes I needed to test my code without going to the university labs.

Then I started mucking around with computer graphics software. There’s Terragen™ for generating incredible landscapes, Bryce 4 (version 6 as of this writing) for creating quick scenes and texture generation, and trueSpace 4 (version 7.5 out as of this writing) for object modelling. I used the different software for the function it provides best, then export the results to another software for the purpose I need. For example, I could model something in trueSpace, export it into Bryce, and render the object there with a texture I created. Or I could

  • render scene in Terragen and export as picture (resource 1)
  • create texture in Bryce and export as picture (resource 2)
  • import resource 1 and 2 into trueSpace
  • map resource 1 onto cylinder and place on scene to use as backdrop
  • map resource 2 onto an object modelled in trueSpace
  • render entire scene in trueSpace

Learn to use the tool that is most efficient at what it does. More importantly, learn to use the results from that tool with other tools.

Then I learned about Hyper Text Markup Language (HTML) and Cascading Style Sheets (CSS), and played with the code. It looks very nice and all, but it’s only on my computer. The web was all the craze then, so I thought I might as well get a place to put my brand new spanking HTML page up, so I searched around for web hosts. I went for free hosting for a while, but eventually got a paid package. I was still a student then, so this cut me back quite a bit.

Sometime around this period, I was taking computer graphics and 3D geometry classes. One of the professors mentioned a computer graphics contest, and the deadline was only a few days away. I don’t know what came into me, but I spent the next few days coming up with a theme and the scene. My weekend was burnt because I was busy scanning textures. I worked through the night before the deadline because I was slapping on textures and tweaking the radiosity settings and rendering and rerendering the scene.

It was terrible. I don’t think my submission even got noticed. The other entries were way better looking than mine. But I thought I had a better theme. All those days and nights gone… oh well, at least I tried.

Time passed and suddenly I was in my final year. The thesis topics available weren’t interesting, so I talked with my advisor and finally came up with something. I would be doing a study on computer virus epidemiology. Ok, big word there. Simply put, I’d be studying how computer viruses behave during an epidemic, and I’ll be using existing information on biological viruses as a comparison.

So amidst the graph theory, coding theory and Frenet apparatus from my math classes, and more matrix calculations than I ever want to see in my computational science classes, I was busy researching on both biological and computer viruses. I had to understand the math models used in epidemiology so I could transfer the relevant properties over to my simulation program.

Oh, I didn’t tell you. I was writing a computer virus behaviour simulation program that mimics real world results. And no, it’s not a computer virus. I was interested in its behaviour, not its method of spreading (though I got bombarded with information on payload and security and what-not during my research).

Then my ability to use tools and interchange results was put to the test. I wrote my simulation program in C and ran it in Unix. But I didn’t know how to produce a graph or chart with my results. Then I remembered Matlab, so I changed my C program to output something Matlab could take in. Then I used Matlab to generate the chart.

I was using LaTeX to generate my thesis document, and I had had to write small programs to generate code for some LaTeX commands. I also imported the Matlab generated charts into my thesis document. I remember one of my fellow students being kind of smug about his knowledge of document generation, because he co-wrote a few papers with his professor. Oh well…

In the end, I wrote a 40-page thesis, complete with research findings, charts, math formulas, proofs, topological models and my proposed model and program for computer viruses. That fellow student was kind of smug about his 100+ pages of material. Whatever

Next came the thesis dissertation. I figured that my presentation would have more impact if I could show the computer virus propagation. I needed a Windows port of my simulation code. Oh my goodness! Luckily, I tinkered with Windows code before, so I dug up the remnants of a working template, and translated my C program simulation logic into the Windows code equivalent. My original simulation program had no interface to speak of (it was supposed to just run for hours and blip out a bunch of numbers), so I had some work to do. I also had to display the viral propagation in real time, so I had to code in some basic charting function.

I got the Windows program up in time, and all in all, the dissertation went well. Whew…

So… a preview for the next one in this series, I’ll be talking about game development and demos. Keep coding!

Continue to part 6

21 September, 2007 | Written by Vincent Tan Leave a Comment

Pitfalls of a polymath programmer

I’ve talked about how a polymath programmer can greatly benefit any software development team. So, what’s the number one advantage of being a polymath programmer?

Polymath programmers are skilled at many programming related tasks.

But do you know the number one disadvantage of being a polymath programmer?

Polymath programmers are skilled at many programming related tasks.

The story of that fateful day…

It was a morning like any other. The sky was a soft blue, the morning air crisp with a hint of the Singapore afternoon heat, and I was friggin’ tired from the programming frenzy the night before.

I reached the office, greeting people along the way, and sat down in my office chair. The subtle difference? There’s no one in a 5 metre radius from my seat for the entire morning.

By a fluke of coincidences and emergencies, all the members of my team were not around. I would be the lone contact, the singular representative for matters directed to my team for two whole days. Some of you might think, “Wow! Power! Command!”.

No such thing.

My team was already small in size, so each member begun to take on more specialised areas of the team’s effort. I’m primarily in charge of most web application development, as well as a few complete systems, a few servers, software installation… anyway, I’m in charge of a lot.

What happened? Like a uncanny manifestation of Murphy’s Law, things started falling apart rapidly on my first day alone in the office. Users started to barrage me with requests and queries. Programs started to fail for the most unfathomable reasons.

Being the sole point of contact for my team members, the users who usually bug them, now bug me. They started with the innocently enough “Hi Vincent. I sent an email to so-and-so, but he’s not around. His out-of-office autoresponder email says to look for you. Can you help me?”, which escalated to the “You. Clear data. Now”

For the entire day, I did everything that my other team members would be reasonably expected to do on a normal work day (serendipities, misfortunes and all). This was in addition to what I would do on my normal work day. Programs failed, files weren’t sent, so I debugged C programs and shell scripts. A user asked for web application assistance, so I helped. Some users got new computers four times better (hard disk and RAM) than mine, and they’d be positively unproductive without the software programs developed by my team, so I went to install the programs.

Because I knew enough of my team members’ work, I filled in their shoes and covered for them. It didn’t make it right or wrong. It was just unfortunate. I was plug-and-playable, and that day pushed that quality to the limit.

It was a very tired and dejected man who stepped out of that office in the evening. That man used every ounce of whatever energy’s left to write this post too…

Just because you can do everything, doesn’t mean you should.

20 September, 2007 | Written by Vincent Tan 1 Comment

Back to Basics - Newton’s Method

I recently joined the Dream In Code family, and found that there’s a higher than expected number of responses from (university freshman) students asking for programming help. Then I read this article about classic computer science puzzles. There’s mention of an expert go player who still reads through fundamental go problems. The goal of rereading? To solve the problems faster than before.

This gave me the cool idea of revisiting my freshman computer science textbook. I graduated from a computational science course, as opposed to a computer science course. My lecturer gave this explanation for the distinction:

Computational science students use programming to solve scientific problems. Computer science students focus more on the programming.

For computational scientists, the main goal is to understand and solve science problems, be they from the realm of mathematics, physics or other sciences. Programming is just a tool to the solution, because using a computer to do calculations is so much faster than doing it by hand.

After years of programming and real world application experience, I wanted to find out how I would have solved those textbook problems. So I dusted off my textbook, and flipped through the programming exercises and found something interesting. The given problem was to use the following formula to find approximate roots:
Newton's method
The function provided was
f(x) = x3 - 3
and the derivative function was
f'(x) = 3x2
So basically we’re finding the cube root of 3.

There’s a brief mention that it’s the Newton’s method for finding roots of equations in the exercise question. Since a derivative of the function is required, I think the lecturer gave it to us back then, in case some of the students weren’t familiar with math differentiation. All that’s left was to code it.

The textbook was based on the C language, but I’m adapting it to C#. Here’s the code (download the full project)

const double epsilon = 0.000001;
double currentx, nextx;
double fx, fprimex;
int i = 1;

currentx = 1234;
// our best guess for cube root of 3
nextx = 1.5;
while (Math.Abs(currentx - nextx) > epsilon)
{
    Console.WriteLine("Iteration {0}: {1}", i.ToString("d2"), nextx);
    ++i;
    currentx = nextx;
    fx = currentx * currentx * currentx - 3.0;
    fprimex = 3 * currentx * currentx;
    nextx = currentx - (fx / fprimex);
}

I remember some key points about these kinds of assignments discussed during university days. They usually revolve around some sort of iteration process. So while loops and for loops were my constant companions. Loops were used to slowly refine a solution to a better one, hence the iteration process.

You might have noticed I used a const variable epsilon. Solutions at one iteration step are compared with the solution at the next step. The comparison usually involves comparison of their difference with zero. Since doubles are used, and zeroes don’t usually play nice with floating point variables, a small number is used, such that if the difference is smaller than this small number, then it’s deemed to be accurate enough.

Then comes the next pitfall: the infinite loop. If the difference never becomes small enough to terminate the loop, the program crashes. Sometimes, you might have to solve an equation where you don’t know if the iteration can terminate.

So comes the additional loop terminator: the number of iterations as an upper limit. I can’t tell you how many iterations to run before declaring it a failure. 10000 is usually a big enough number to try though. If the loop terminates when you know the solution can be further refined, then try increasing the iteration limit. I didn’t add this for the given code because I know the iteration process is very stable, and terminates after few iterations.

There’s also usually variables invariably named current, previous and/or next. It’s a characteristic of the iterative methods to be coded.

So what can you get out of this?

As a programmer, you will eventually come across something where the theory behind the (business) logic is unknown to you. Take heart that you might not even have to understand it! You only have to transform whatever it is into code.

This ability to bring theory into code is more important than understanding the theory itself.

There’s always a mathematician who can explain why Newton’s method works, but you’re the only one who can code it.

Next Page →