Saturday, March 14, 2009

Nelson Mandela

Nelson Mandela was a prominent figure of the 20th century. A lot of lesson can be learned from his amazing life. I haven't read his biography. However, some of his quotes are worth to be taken (at least) as an alternative way of seeing what life means.

“There is no passion to be found playing small - in settling for a life that is less than the one you are capable of living.” - Nelson Mandela

“I learned that courage was not the absence of fear, but the triumph over it. The brave man is not he who does not feel afraid, but he who conquers that fear.” - Nelson Mandela

“It always seems impossible until its done.” - Nelson Mandela

Tuesday, March 3, 2009

Refactoring "Badly Written" C Source Code for Embedded System

Ok. I'm not an expert on this "Refactoring" subject. I'm tired, sleepless but have to write this because it's very important. I'm gonna lost it on the way to bed if I don't write it now.

So, you have this C code for embedded system written by someone at some hardware company, let's call it X. It's written like someone rushing out to get the next train, and then some other guy come, add some code and some #define here and there. You're the "lucky" guy at another company, let's call the company Y. Y have bought large amount of hardware from X to customize for their specific market. Now, your manager at company Y want you to strip off all unnecessary code from the code that company X releases. In addition, your manager at your company also want you to add some "small" feature not yet exist in the C code produced by X for the specific hardware that your company bought. However, that feature exist in other product from company X which still in the same "family" as the product Y have bought. You found out that the "small" feature is controlled by conditional compilation flag, but with a twist. The flag enables the feature that you need along with some other feature that you don't need. What would you do when the C code cluttered with conditional compilation construct almost everywhere? What would you do to refactor the code so that it can become manageable and you can sleep well at night after that?

Let's see. This is what I would do:

  • Take a lesson (or two) from Busybox coding style. Replace long #ifdef with
    function call. The new function enclosed in the same #ifdef and called from previous location and defined as empty function if not used (feature is disabled).
    Example:

    void func_x()
    {
    ...
    #ifdef ROUTE
    blah = c+a;
    slez = a +z;
    #endif
    ...
    }

    transformed to:

    #ifdef ROUTE
    void optional_init_blah()
    {
    blah = c+a;
    slez = a +z;
    }
    #else
    void optional_init_blah(){}
    #endif // ROUTE

    void func_x()
    {
    ...
    optional_init_blah();
    ...
    }

    In GCC, the optional_init_blah() function will vanish into thin air if ROUTE is not defined. This way, you can isolate the "optional" function to the header file or just place it in the top of the source file to make the code much more readable.

  • Now, say there's a ROUTE_SUPPORT definition. However, upon examining the code, you found that you don't it in its entirety. Only its static routing that you need. What would you do? Just break the ROUTE_SUPPORT #define to STATIC_ROUTE_SUPPORT and OTHER_ROUTE_SUPPORT_THAT_YOU_DONT_NEED.

  • Break every very long function to smaller function. Just small enough to fit in your "mental picture". Let's say, nothing more than 150-200 lines of code.

  • If you found a "cluster" of #define that define consecutive constants and you are sure they all belong to one logical block, it's better to "lump" the constants into an enum. Otherwise, use const int instead of the #define. This way the compiler will help you check for error(s).

  • Every time you think you grasp the idea behind a function, add a comment. I suggest using a doxygen compatible comment. That way, you can automate or at least semi-automate the documentation for the code you're working with.


That's it for now.
This time greetz go to Ayumi Hamasaki for the endless quiet "background sound" that keep me awake.

Ciao.

Saturday, January 31, 2009

The Future of BIOS Disassembly Ninjutsu Uncovered

Now, finally I have latest update from my publisher regarding BIOS Disassembly Ninjutsu Uncovered that I wrote a while ago.

The English version of this book is now out-of-print and will not be printed for a little while until I can find new publisher who wants to acquire the right to re-print it or I might come up with another option(s).

For those who needs this book as fast as possible, please contact http://www.ipgbook.com. They might still have some books left in their inventory.

As soon as I have come up with the solution. I'll post an update in this blog.

If you're asking why it happens, it's because the Russia-based publisher A-list Publishing who publish the book is closing down their US operation due to economic pressure.


As for the Russian version of the book, it will be available as usual from www.bhv.ru.

That's it for the moment.

UPDATE
------------
I have received the contract termination for the English edition of BIOS Disassembly Ninjutsu Uncovered. Please read this post for further details.

Wednesday, January 21, 2009

A Glimpse of Eastern Indonesia


While many Indonesians hardly appreciate the geographical size of their own country, it's not the case for me because I come from a quite far place in the eastern part and now resides in the western part of the country. There are very small number of country in the world that spans three time zones or more. Indonesia spans three different time zones. Of course this means the country _is_ large. I cannot imagine someone who lives in Russia, which has eleven timezones! Imagine you're living in Moscow and your relative is in the far east Vladivostok.

Now, back to Indonesia. The eastern part is very sparse. A lot of islands and very small inhabitants in some of them. Anyway, these are the pictures of the island where my parents comes from.

picture from the ferry (probably on approach to the Island)





View from the mountain



View upon leaving the island (taken on the ferry)



A traditional house in the coastal region of the island



These are the surprising wind towers (I've never seen them before)






Anyway, I come to hate living in the big city quite a bit because you can hardly concentrate and too much distraction. Maybe I'll move to one of those small "isolated" island soon enough. There will be a lot of work for that to happen. But it will, sooner or later.