On Multitasking

2011.12.20 - Comments Off on On Multitasking

A short essay on multitasking.



Osama Bin Laden

2011.05.01 - Comments Off on Osama Bin Laden

Celebrating Osama Bin Laden’s death is not only barbarous but it is also counterproductive. It is barbarous because a human being, however misguided, is dead. If his death was a political or military necessity, it should be with a heavy heart that the soldiers tasked to the job performed it. It is counterproductive because it is the celebration and political chest thumping and not the actual death that makes the man a martyr to his admirers. The righteous have a difficult job even when they are right. Anything other than an attitude of resignation and regret for the necessity of the use of force will give the opposition fuel for their ire.

A poem for Japan

2011.03.29 - 2 Responses


Two days ago, I stepped over a plank of wood
    and walked past a barren tree.
My family and I hugged mugs of thin tea
    and huddled around a kerosene heater set to low.
I almost wish it weren't so peaceful.

Yesterday, I watched a heron
    glide along a riverbank.
It's whiteness a stark contrast
    to the fragments of houses and overturned cars.
I almost wish I hadn't seen it.

Last night, I watched a crescent moon
    in a cloudless sky.
The blackness of a city without power
    produced stars unlike I have ever seen.
I almost wish I had just gone to bed.

Today, I stepped over a plank of wood
    and noticed a lone cherry blossom on a branch.
Its pink petals fluttering in the moist wind
    at once delicate and strong.
I almost wish life were not so beautiful
    and so resilient.

Why should I read “Anna Karenina”?

2010.12.12 - Comments Off on Why should I read “Anna Karenina”?

Tolstoy unflinchingly touches on the big questions in life. Why am I here? What is the meaning of life? What is the right social system for a country? What is the right way to model romantic relationships in society?

If you’ve had these questions in your head from time to time, you might resonate with his treatment of them. He doesn’t necessarily try to answer them directly. Instead, he shows what might be the consequences of taking certain stances on the issues. Some of the characters consciously pick over these questions. Others haplessly encounter the results without realizing that there was even a question or a stance to be taken.

The philosophical merit aside, this moving story is still worth a read. It takes you through the lives of people you probably know or will meet. You will learn something about them if not about yourself.

I had some difficulty wading through some of the pages toward the middle of the book but toward the end, I couldn’t put it down. It was well worth the time.

Why should I read “The Count of Monte Cristo”?

2010.12.01 - Comments Off on Why should I read “The Count of Monte Cristo”?

If the word, “epic,” wasn’t careworn and haggard from its recent binge of overindulgence across the interwebs and beyond, I would readily apply it to this tale of revenge. Dumas paints an enormous mural, each section breathtaking.

I’m not a vengeful person so I don’t readily relate to the motivating force behind the arc of the plot but Dumas draws me in anyhow with the beautiful imagery, the deep characters and the fantastic circumstances. He brings you along a journey where only you, he and the count are the ones who really know what’s going on.

I had a hard time keeping track of who was who through most of the beginning of the book. Luckily, Dumas doesn’t introduce too numerous a cast of characters. If you get confused or frustrated by not knowing who is who in the beginning, soldier on anyhow.

Why should I read the classics?

2010.12.01 - Comments Off on Why should I read the classics?

It is not the fault of my many excellent English teachers that my exposure to the classics in high school and college was lean. In high school, I filled my electives with extra math and science. It wasn’t until college that I really started to love literature in all its forms. I made time in my engineering curriculum to read a bit of poetry and some fiction. I even seriously considered changing my major to English but that is another story.

Fast forward to real life. I didn’t remember my love of literature until relatively recently. I dusted off my library card and took a list of recommendations from a friend to my local library and recommenced my education.

This is the first of a series on specific classics of literature. It represents my taking a stand against the obvious trend cheekily intimated by Twitterature that contemporary society’s patience for meandering through beautiful prose or getting goosebumps over a great work of poetry is waning. I will attempt to explain why I think each work is worthwhile. If you don’t already, may this series inspire you to fall in love with the classics.

Using RAII to simplify using the Lua stack when writing C++ code

2010.07.26 - Comments Off on Using RAII to simplify using the Lua stack when writing C++ code

I recently found myself doing a lot of this sort of thing.

bool lua_t::load(const std::string& filename)
    lua_pushcfunction(state_, traceback_function);

    if (luaL_loadfile(state_, filename.c_str()) != 0)
        lua_pop(state_, 1);
        return false;

    if (lua_pcall(state_, 0, LUA_MULTRET, -2) != 0)
        lua_pop(state_, 1);
        return false;

    lua_pop(state_, 1);
    return true;

The “sort of thing” I’m referring to is restoring the state of the Lua stack at every exit point from a function which manipulates it. In the above case, I had to use three distinct calls to lua_pop to achieve this. Today, I found a new approach that can simplify dealing with the Lua stack from C++.

struct stack_bookmark_t
    explicit stack_bookmark_t(lua_State& state_)
        lua_settop(state_, top_);
    lua_State* state_;
    int top_;

The motivating example changes to this.

bool lua_t::load(const std::string& filename)
    stack_bookmark_t bookmark(*state_);

    lua_pushcfunction(state_, traceback_function);

    if (luaL_loadfile(state_, filename.c_str()) != 0)
        return false;

    if (lua_pcall(state_, 0, LUA_MULTRET, -2) != 0)
        return false;

    return true;

At every exit from this function scope, the destructor of stack_bookmark_t ensures that the stack height is restored to its prior state.

Evolutionary contemplations in homeostasis

2010.05.18 - 2 Responses

During a recent conversation with a great friend, I
mentioned a conjecture that maybe our blood salinity and the
temperature of our bodies resembles the salinity and
temperature of the ocean at the time we crawled out, grew
lungs, and evolved into what we are today, that maybe our
homeostatis is like a kind of timestamp marking us as having
become land dwellers at a specific point in time.  My friend
was intrigued by this idea but didn’t offer support or
contradiction.  Hungry for deeper engagement and too lazy to
google it out, I engage you, dear Internet.  Shoot it down
or buoy it up.  Is there anything to this wild speculation?

The beautiful, peaceful people of Canada

2010.04.18 - 6 Responses

I am presently visiting Ottawa, the capital city of Canada.
Late spring finds this delightful place mostly sunny but
still brisk enough to encourage you to keep your coat handy.
My enthusiastic hosts and coworkers met me at the airport
and immediately began showing me their town. What a
beautiful town it is.

I have seen brave young men dropping 4 meters (that’s about
12 feet for the uninitiated) down a waterfall in their
kayaks. Oddly, the drop wasn’t a problem for any of the
daredevils. The tricky currents just after the falls
consumed one very expensive carbon-fiber paddle as well as
the ego of its former owner.

I have ridden my bike along luxuriously wide roads
alongside some of the most polite drivers I’ve ever
encountered amidst green lawns, tree-lined avenues, and
picturesque lakes.

I have visited a bakery, or more aptly, a boulangerie, where
I was greeted with “bonjour” and thanked with “merci”.
Studies have shown that bread tastes better when it grows up
in this kind of environment.

I have visited a world class art museum and have seen the
facilities where a peaceful government conducts its

But mostly, I have been extremely impressed by the people of
Canada. I don’t think they realize how beautiful and
charming they are. They are universally nice and polite.
Despite the busy, eclectic, urban environment, folks smile and
acknowledge you even when you’re not somehow in their way.
They seem generally very healthy, fit, and full of life.
(This could be a fine moment to mention health care but I
will choose not to get involved in the silliness of that

All in all, I am extremely pleased to have spent this
weekend getting to know Ottawa and its people. People of
the world, take note, when you want to find an example to
follow and a city to model yours after, you could do worse
than to visit Ottawa, Ontario, and learn from its peaceful,
beautiful people.

On publishing

2010.02.10 - 2 Responses

In this day of instant gratification publishing, traditional journals, who take their time to cultivate each issue by working with their authors and painstakingly formatting their content are starting to seem somewhat old fashioned.  Nonetheless, I find their vetting process useful in collecting valuable content targeted at specific audiences.

I recently had an idea that I wanted to publish in a C++ trade magazine, any of them would do.  I pitched my idea to Dr. Dobb’s, a rather prestigious computer programming publication and Overload Online, the free journal of ACCU, a community of programmers interested in things C and C++ related.  Overload was interested in my idea and complimented me by reviewing a draft but they noted that another author, Martin Moene, had presented a very similar idea, and encouraged me to write a follow on article.  I ultimately decided against writing the follow on article and, at first, I was crestfallen at being scooped.  Martin’s idea and mine are nearly identical in spirit if a bit different in execution.  But, more important than the individuals involved are the ideas and I’m glad these ideas are now firmly in the public domain where developers can benefit from them regardless of who presented them first.  (I’m laughing at myself a little in writing this last sentence but I resonate with the sentiment.)

So it is with a great deal of satisfaction at both my personal triumph over my own ego and at the honor of being part of this discovery that I present to you my original draft of this technique.


I owe a debt of thanks to Scott Meyers who honored me by giving me feedback on an early draft and for teaching his course on Effective C++ in Embedded Systems which inspired me to look harder for a solution to the problem this technique aims to solve.