October 2005


Questionaire in 11/2005 issue of Software Development.

  1. When it comes to policies, procedures and development standards, I:
    Follow them because consistency is important, but I offer to draft the changes needed to correct or update them.

  2. When writing a project-related document, I:
    Reference other documents or ask questions to make sure I understand what’s required, taking my best shot at it before submitting it to my manager for review.

  3. When I solve a particularly difficult technical problem, I:
    Provide my coworkers and manager the details of the problem and solution, to spare them similar difficulty.

  4. For routine communication with my manager, I:
    Ask her how she prefers to receive routine communication, whether by e-mail, phone or office visit–and then keep in touch accordingly.

  5. When I receive a new project assignment, knowing I already have more work than I can do effectively, I:
    Accept the assignment, but ask hwat priority it should be given in relation to other assignments.

  6. When I receive an assignment I feel is “grunt work”, I:
    Recognize that a certain amount of pedestrian work must be done, and respect my manager’s judgment in the assignment.
    (This is the only one I got “wrong”. I picked “Politely inform my manager that my skills could be put to better use elsewhere”)

  7. My attitude toward keeping current with tools and best practices is:
    I enjoy reading articles and books about the software development profession, even on my own time, for my own personal development.

  8. When demonstrating my development work-in-progress to coworkers, I:
    Take notes of their suggestions and follow up on each one, either making the suggested change or justifying why it isn’t feasible, realizing that they’re trying to help me improve the product.

  9. When reviewing my colleagues’ work-in-progress, I:
    Offer constructive criticism, focusing on the product and not the person.

  10. When my performance evaluation is coming up, I:
    Send my manager a detailed update specifically addressing how I met the performance objectives established for the performance period.

Robin and Insook invited us to the concert at Avery Fisher Hall, because Insook worked with the orchestra before. We got there early, and following Jim’s suggestion had dinner at the cafeteria, and the food is surprisingly ok and unsurprisingly expensive.

It’s actually the first live Chinese instrument concert I’ve been to. I never liked traditional Chinese orchestra, and I probably never will. It’s just too loud and too noisy and too monotonous.

There’re four pieces on the program. First a rearranged traditional piece, then a suite by Zhao Jiping. I don’t like either one. Zhao Jiping’s piece sounds like either soundtrack, or folk festival music. Same goes for the 2nd piece in the 2nd half by Peng xiuwen.

The 1st piece in 2nd half is by Tan Dun, and he went on to the stage to introduce the instruments and talked about the piece and his experiences with Chinese orchestra. His English should be better for someone who has been living in New York for many years. The piece is a very good one, though. It has moments like soundtrack and cliche, but the sound keeps being interesting and the overall composition is much better than the rest. Several musicians went down into the audience and played there, conversing with the orchestra on stage. At some point the musicians was making all kinds of voice, and the coughing and child crying in the audience blended in perfectly. The funniest sound is the whole orchestra flipping the scores rapidly, but later my mum told me that has been done before.

The orchestra played 4 encore pieces without much solicitation from the audience at all, which is pretty cheap. The first one is a very modern piece by a Hong Kong composer who contributed a lot to the orchestra. Second one is 草原英雄小姐妹. Third one is a western folk song. Fourth one is a traditional Chinese piece. All very noisy.

The concert didn’t change my perception about Chinese orchetra, but it’s nice to see Robin and Insook again.

There was an email thread between my colleagues Mike and Joe on this.
In C++, all 3 swap’s work. Only the 3rd one doesn’t incur a temporary object, but it doesn’t swap the original objects a and b, but rather the pointers pa and pb.

class CTest
{
public:
int a;
};

void swap(CTest& ra, CTest& rb)
{
CTest rc = ra;
ra = rb;
rb = rc;
}

void swap(CTest* ra, CTest* rb)
{
CTest rc;
rc = *ra;
*ra = *rb;
*rb = rc;
}

void swap(CTest** ra, CTest** rb)
{
CTest* rc = *ra;
*ra = *rb;
*rb = rc;
}

int main(int argc, char* argv[])
{
CTest a, b;
const CTest* pa = &a;
const CTest* pb = &b;
a.a = 1;
b.a = 2;
swap(a, b);
swap(&a, &b);
swap(&pa, &pb);
}

In Java, nothing works! You just can’t write a simple swap function in Java. You’d have to swap all members in the two objects explicitly (use reflection).

This nice paper on floating point comparison clearly explains why checking absolute difference or relative difference against a threshold doesn’t work in all situations. The problem with relative difference is when values are close to 0, if you do fabs(a-b)/( (fabs(a)>fabs(b)) ? a : b ).

The solution is to directly compare the “integer representation” of the floating point value, i.e. the actual bits of the float.

// Usable AlmostEqual function
bool AlmostEqual2sComplement(float A, float B, int maxUlps)
{
// Make sure maxUlps is non-negative and small enough that the
// default NAN won't compare as equal to anything.
assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
int aInt = *(int*)&A;
// Make aInt lexicographically ordered as a twos-complement int
if (aInt < 0)
aInt = 0x80000000 - aInt;
// Make bInt lexicographically ordered as a twos-complement int
int bInt = *(int*)&B;
if (bInt < 0)
bInt = 0x80000000 - bInt;
int intDiff = abs(aInt - bInt);
if (intDiff <= maxUlps)
return true;
return false;
}

ULPs stands for Units in the Last Place.