Resisting the Allure of Instant Gratification

February 4th, 2007

unp.jpgMy sister received a 25USD Borders gift card that she intended to use for another medical dictionary. I persuaded her to regift it to me, and I have been carrying it for weeks. I’ve been to Borders multiple times, and only the appeal of instant gratification kept me coming back. I have been wanting Richard Stevens’ Unix Network Programming, Volume 1: The Sockets Networking API for awhile. I am pretty familiar with sockets programming, having majored in computer science with a specialization in networks and distributed systems, but I am bothered by not having read such a classical text for its field. A traditional Borders store sells the book at cover price: 74.99USD. Buying the book at cover price was not very appealing. Borders.com, powered by Amazon.com, sells the book for 52.49USD, and after applying the 25USD gift card, I was able to purchase the 75USD book for 27.49USD. Averting instant gratification saved me (74.99 * 1.0825 – 52.49 =) 28.69USD!

Struggling with Perfectionism

January 24th, 2007

The question about my greatest weakness has been raised in almost all my job interviews. Many books on job interviews discourage people from construing a strength as a weakness. One of my greatest weaknesses is my drive for perfection. When I perform a task, I want its completion to approximate perfection. Paying attention to details in workmanship and quality is viewed by many people as a positive characteristic for an employee. Being obsessed and compulsive about achieving perfection at the levels that are satisfactory to me actually serves as a big drawback.

My high school English teacher made me aware of my perfectionist nature. She told me that my persistent drive toward perfection would be a source of many failures. With the memory of her warning imprinted on my mind and some introspection, it is easy for me to remember instances when perfectionism caused failure. I state that perfectionism is my greatest weakness for this reason.

As a project milestone draws near, I feel my desire for perfection resurface. My apparent options are to continue developing an environment that will simplify future tasks with the cost of missing the milestone or delay the development of the environment, switch to a brute-force coding effort, and attempt to reach a milestone with a low probability of success. I believe that game theory calls this a “lose-lose” situation. I am, however, driven to lose this situation in such a way that winning future situations is easier.

Although I see perfectionism as one of my shortcomings, I believe that perfectionism or the desire to make future tasks easier is appropriate for the current situation. Sometimes, perfectionism serves as an acceptable heuristic for finding the best path to an optimal solution. One adage that I saw on a whiteboard at a previous company is “do things right the first time.” I shall commit myself to doing just that.

A Hint for Enhancing Software Dev Agility

January 16th, 2007

Just know that when it comes down to the wire, it’s just garbage in and garbage out. Reducing the implementation of software to the practice of accepting data from somewhere and preparing it to be used elsewhere has certainly helped me hit the ground running and get up to speed with existing projects.

新年明けましておめでとうございます!

January 1st, 2007

Before setting resolutions for 2007, I should reflect on my 2006 resolutions of organizing, rethinking, focusing, and succeeding. Workspace organization has improved incrementally throughout the year, and it continues to be a work in progress. I have placed much effort in minimizing my drive for perfection and made myself more comfortable in dealing with systems that are less than ideal. I also started minimizing schedule risk while continually developing solutions by having functional implementations available when schedule milestones are reached. Throughout the year, I’ve been fairly focused on achieving my primary objectives. I have not given much time to other computing interests such as computer graphics programming and open source development. Success that was achieved in 2006 is based on an avoidance of total failure.

Now, for 2007, I will begin allowing myself to fully depend on others. I did not have the ability to depend on others, because of project time or quality constraints. Lack of team involvement will be minimized or eliminated in future projects through sufficient project documentation, subsystem modularization, and module-based implementation assignments. More people will be involved in the research and development of software modules. Localizing knowledge of a system to an individual with an inability to transfer that knowledge to others is a mistake that must be countered this year, and project documentation that is more meaningful will help significantly.

I need to displace some project accountability from myself. Although there may be an increase in schedule and quality risks for future projects, the determination of the team’s successes and failures will be more distributed within the team and less concentrated on me. The team should not fail, because I fail. It should fail, because the entire team failed. This is not to say that I am looking to shirk responsibility. I am merely opening myself to sharing more of the responsibility with others. I will depend on the team to deliver what is requested as the team depends on me to provide them with what is needed.

Code Critique: Duplicate Code within If-Else Statements

December 20th, 2006

I’ve been reviewing and documenting other peoples’ code lately, and I found some vexing patterns that came up constantly. Seeing in an if-else statement that the first (or last) few lines evaluated when the conditional is true match the first (or last) few lines evaluated when the conditional is false was a little bothersome. It is as if someone copied code in their editor and pasted it where they needed it.

An example snippet of code is:

function f()
{
   if( g() )
   {
      // statement_1
      // statement_2
      // ...
      // statement_n
      
      // some stuff
   }
   else
   {
      // statement_1
      // statement_2
      // ...
      // statement_n

      // other stuff
   }
}

Firstly, if a sequence of code is present in two or more places, wrapping the sequence within a function and calling the function may make the code just a bit more elegant. Wrapping identical sequences of code within a function localizes the code that needs to be updated when the sequence of code needs to be changed. Localizing common sequences of code within a function eliminates the need for programmers to track down all identical code sequences where and when an update is desired.

Wrapping statement_1 through statement_n in a function, h(), results in the following code:

function h()
{
   // statement_1
   // statement_2
   // ...
   // statement_n
}

function f()
{
   if( g() )
   {
      h();

      // some stuff
   }
   else
   {
      h();

      // other stuff
   }
}

The code’s annoyance factor can be further minimized by noting that h() is the first statement that is evaluated after the if-else conditional expression evaluates to either true or false. Since h() is evaluated without dependence on the if-else conditional expression, it seems sensible to move h() out of the if-else statement.

The resulting code is presented here:

function h()
{
   // statement_1
   // statement_2
   // ...
   // statement_n
}

function f()
{
   h();
   if( g() )
   {
      // some stuff
   }
   else
   {
      // other stuff
   }
}

I noticed the issue after writing pseudocode that closely matched existing code and looked like this:

1a. if variable_A is non-zero
  1a – i. connect to database_server_A using host_A, login_A, password_A
  1a – ii. use schema_A as the default schema
  1a – iii. do stuff
1b. else
  1b – i. connect to database_server_A using host_A, login_A, password_A
  1b – ii. use schema_A as the default schema
  1b – iii. do alternate stuff

I thought that the following pseudocode would be easier to read and more concise:

1. connect to database_server_A using host_A, login_A, password_A
2. use schema_A as the default schema
3a. if variable_A is non-zero
  3a – i. do stuff
3b. else
  3b – i. do alternate stuff