Simple tasks are sometimes the hardest to do

Time slowed as her hair gently brushed against my face. I smelled the briefest of whispers of vanilla as she continued to twirl. I caught her to bring her revolution to a stop. I held her right hand with my left, and cupped my right hand ever so gently on her left shoulders. Just as she laid her left hand on my shoulders for support. We danced and danced …

And tried very hard not to step on each other’s toes. I was learning to dance the rumba.

Back in my previous employment, one of my colleagues then persuaded me to join a rumba dance class. He’s biased, since he could dance the cha cha, salsa, rumba and do ballroom dance (he won regional competitions). So after weeks of his persuasion, I decided to go for one of the rumba classes.

First thing I noted was that there were no “young” male dancers (“young” being relative, of course). The class welcomed any male participants, since they almost always lacked male dance partners (Dating advice? Dance classes typically starved for men. Consider salsa).

Second thing I noted was that I was the only first-timer there. Everyone had already taken classes in some other dance, such as salsa or cha cha. This meant I had a lot of catching up to do, since the instructor moved the pace of the class up.

Third thing I noted was my normal work clothes were really not designed for rumba dancing. While I’m not that buff, my pectorals and biceps and triceps fill out my long sleeved shirt enough to restrict freer movement. And although I have a 29 inch waist, I typically buy pants for 31 or 32 inch, because I have muscular thighs (oh, there goes my modesty…). And even then my pants were still fairly tight. Do you know the kinds of things you have to do with your waist in rumba?

Alright, alright, we’ll get back to my dance partner. Her name’s White Snow, translated directly from Chinese. Her family name’s White. What, you have Barry White and Snow White, but we can’t have White Snow? (that said, is Snow White the entire name? Or is there a family/last name?).

She’s pretty enough. I don’t know if she had a boyfriend. I didn’t ask. (Although everyone back at the office was like, “Hey Vincent, that girl there? What do you think?”) I much prefer Caucasian women.

Inner Critic: Is this really the platform to be telling everyone your dating preference?
Me: It’s my blog. I can do whatever the hashbrown I want.
Inner Critic: Why are you using the word “hashbrown”, which isn’t even a wor…
Me: It’s my flying fishball blog. I can use “hashbrown” whenever the hashbrown I want.

The dance instructor (who’s especially tall. And that’s saying something, since I’m 1.78 metres tall) taught a dance routine. We rotated dance partners as we went. Each lesson, he’d teach a new segment of the routine, and we’d practise it. Then we’d go from the beginning of the routine all the way to the new segment.

There were 10 lessons in all, and typically, the instructor would have taught the entire routine only at the 9th or even 10th lesson. For that particular class, I think he finished it on the 8th (or 7th) lesson. That meant the pace was very fast. He also told me I was quick to learn and catch up. For the first few lessons though, it was all I could do to remember what to do with my feet, let alone what to do with my arms.

Which brings us to the basic moves. At the start of each class, we’d go through some basic moves. They were all on the feet movement. However, your hands must be up in the default position. What’s the default position?

Stand up. Go on, I’ll wait. Hold your arms straight out to your sides, as though you’re a scarecrow. Then bend your arm at the elbow, keeping your upper arm still parallel to the ground. So now your upper arms point out to the side, and your forearms point in front of you. There. Now keep your arms in that position the whole time.

If during the dance, your hands are not either holding on to your partner, or twirling her, or doing some particular dance move, your arms go to that default position.

It’s a very simple position, yet it’s critical, because it makes the dancers look good. You’re supposed to be dancing in high energy, with grace and proper posture. My dancer colleague even told me he had to practise smiling even though he’s heaving from exhaustion. Did you know the male dancer is the one leading the entire dance? The female follows the male’s lead. When the female returns to your embrace from her twirling, you’ve got to catch her and hold her steady. And not fall out of balance (I mimed the *boing boing boing* of me hopping on one leg and my friend laughed).

For rumba, that’s the simple task. Hold your arms up. My arms were ready to drop after the first few lessons. It’s very tiring to keep them up the whole time.

It doesn’t matter what it is. Refactoring some code. Giving a good variable name. Taking the garbage out. Thinking or finding out a good algorithm. Replying “No” to that email.

Just because it’s simple doesn’t mean it’s easy.

Working on spreadsheet software library

As a natural and logical extension from my Open XML spreadsheet guide, I’m writing a software library to create and manipulate Open XML spreadsheets. (Never mind that decompiler project I was working on… 2 months of coding… sunk cost… moving on…).

I did some research (ok, an inordinate amount of research…) on the available spreadsheet software libraries out there, both free and commercial, both supporting Open XML (or .xlsx in any case) and the old .xls (Microsoft Excel in binary). I have 2 observations.

First, there’s a plethora of classes in the library. It’s sort of expected. There’s support for a lot of functionality, and it just burgeoned into many classes. Personally, I hate it when I have to learn a new library. There’s a whole bunch of documentation and classes I have to read up on and experiment to just do a simple thing (printing a string of characters is the first thing I try). When I first encountered the .NET Framework, I was crushed. It’s redeeming feature was its extensive documentation, which made learning easier.

Second, even though there’s support for a lot of functionality, it still takes quite a bit of code to accomplish what you want done (granted, much less than if you wrote low level code). Hey I wrote a guide on Open XML spreadsheets, I know how many lines of code needed to just create an empty Excel file, ok?

But these are spreadsheet software libraries!. They’re supposed to make your life easier. In fact, much easier.

I read that when the iPhone was designed, the engineers told Steve Jobs that it needed to have 4 or 5 buttons. Steve Jobs said no. One button (to rule them all). The iPhone now only has the 1 button.

So I took inspiration from that and designed my library to have that quality. Alright, alright, here’s a code sample:

SLDocument sl = new SLDocument();

That will save an empty Excel file named “Book1.xlsx”. What, not Hello World enough for you?

SLDocument sl = new SLDocument();

There. Now the file is named “HelloWorld.xlsx”. What, sheet name? Most (if not all) of the libraries I researched required you to add a new worksheet to an empty file. All spreadsheets have at least one worksheet. Why force the programmer to do it anyway? You don’t see Microsoft Excel forcing the user to add worksheets in a newly created spreadsheet file, right? (Excel even has 3 worksheets added by default).

Alright, fine. The first worksheet’s name is by default “Sheet1”. You can rename it.

SLDocument sl = new SLDocument();
sl.RenameWorksheet(sl.DefaultFirstSheetName, "Hello");

There, happy? So, how do we set cell values?

SLDocument sl = new SLDocument();
sl.RenameWorksheet(sl.DefaultFirstSheetName, "Hello");
sl.SetCellValue(2, 3, 3.14159);
sl.SetCellValue(2, 4, "This is PI");

The cell with row 2, column 3 will have the value of PI. The cell with row 2, column 4 will have the string “This is PI”. Yes, the library supports cell references such as “C2” and “D2”. My opinion? They make better sense to a user with visual interface to the spreadsheet. It’s much harder to use when you’re programming with a non-visual interface to the spreadsheet. Good luck iterating through rows 2 to 500,000, with columns 1 to 1000 (financial reports, I’m looking at you…).

Want to add a new worksheet?

SLDocument sl = new SLDocument();
sl.RenameWorksheet(sl.DefaultFirstSheetName, "Hello");
sl.SetCellValue(2, 3, 3.14159);
sl.SetCellValue(2, 4, "This is PI");
sl.SetCellValue(5, 5, "Why am I not first?");

Hey, a software library is supposed to make your life easy. The second worksheet’s name is *drum roll*, “SecondWorksheet”. The string “Why am I not first?” is in row 5, column 5 of the newly added worksheet. How does the library know which worksheet to add which cell value? By magic. Ok, fine, it automatically keeps track of worksheets.

When a user enters a cell value in Excel, does the user need to know which worksheet? No, because that information is implied. The user knows which worksheet because the user chose it already. And so does this software library.

Oh yeah, I even have basic theme support!

SLDocument sl = new SLDocument(SLThemeTypeValues.Flow);
sl.RenameWorksheet(sl.DefaultFirstSheetName, "Hello");
sl.SetCellValue(2, 3, 3.14159);
sl.SetCellValue(2, 4, "This is PI");

That gives you the Flow theme, one of the built-in themes in Microsoft Excel (note: only the fonts and font colours are supported). You can even design your own custom theme.

System.Drawing.Color[] clrs = new System.Drawing.Color[12];
clrs[0] = System.Drawing.Color.White;
clrs[1] = System.Drawing.Color.Black;
clrs[2] = System.Drawing.Color.WhiteSmoke;
clrs[3] = System.Drawing.Color.DarkSlateGray;
clrs[4] = System.Drawing.Color.DarkRed;
clrs[5] = System.Drawing.Color.OrangeRed;
clrs[6] = System.Drawing.Color.DarkGoldenrod;
clrs[7] = System.Drawing.Color.DarkOliveGreen;
clrs[8] = System.Drawing.Color.Navy;
clrs[9] = System.Drawing.Color.Indigo;
clrs[10] = System.Drawing.Color.SkyBlue;
clrs[11] = System.Drawing.Color.MediumPurple;

SLDocument sl = new SLDocument("ColourWheel", "Castellar", "Harrington", clrs);
sl.RenameWorksheet(sl.DefaultFirstSheetName, "Hello");
sl.SetCellValue(2, 3, 3.14159);
sl.SetCellValue(2, 4, "This is PI");

There are 12 colours you need to define. These correspond to the 2 light colours, 2 dark colours, 6 accent colours, the hyperlink colour and the followed hyperlink colour. “ColourWheel” is the theme name, “Castellar” is the major Latin font and “Harrington” is the minor Latin font. The major Latin font is used when you apply the Title named cell style. The minor Latin font is basically the body font.

What named cell style? A customer suggested supporting the feature.

Named cell styles

So how do you apply it?

sl.ApplyNamedCellStyle(2, 3, SLNamedCellStyleValues.Good);
sl.ApplyNamedCellStyle(2, 4, SLNamedCellStyleValues.Accent1);

I am finishing up version 1 of the library, and it will soon be available. I’m targeting a launch in January 2012. The software library will be called SpreadsheetLight. The primary idea is for it to be simple and clean. Simple for you to use, and you write clean code when you use it.

My internal tests show that SpreadsheetLight runs faster than 2 other free libraries. I won’t tell you which 2, because it’s not relevant, and because I’m automatically biased, and because it’s just not nice to the other programmers who contributed to those 2 libraries. The point is that it runs fast and is effective, which I’m happy about.