Tuesday, November 03, 2009

Open Source Projects and Volunteers

Why only a handful of projects attract attention of developers/volunteers?

Moshe Bar and Karl Fogel in their book Source Development with CVS points that In a system that relies largely on volunteer energy, convenience is not a mere luxury—it is often the factor that determines whether people will contribute to your project or turn their attention to something with fewer obstacles to participation. Projects are competing for volunteer attention on their merits, and those merits include not only the quality of the software itself, but also potential developers’ ease of access to the source and the readiness of the maintainers to accept good contributions.

Point taken.

Saturday, October 10, 2009

Coding standards do no harm

Coding standards aid in picking up new code faster, it can help in debugging too. For example it's almost safe to skip a const qualified method while debugging a problem (just make sure that there are no mutable members).

Lately I had crazy time debugging a problem that eventually boiled down to non adherence of coding standards. Here it goes ...

A new API that looks as simple as below was added to a self sufficient component which compiles clean after the change was made.
    int process_data( const char * str, char delim = '  ' );
Suddenly another component that depends on the modified header fails to compile with error C2143: missing ')' before 'string'. That's a bit of shock!. By the way the other component doesn't use the new API at all.

It turned out that other component has defined a macro which is neither long nor uses UPPER_CASE. Of course it's their choice!
    #define delim TEXT(" ")        // and
#define TEXT( str ) L##str // just token pasting ...
You are punished for using a simple looking identifier (delim) and it takes efforts to understand that you are being punished!

Saturday, August 01, 2009

Defining INT_MIN

It's always better to take a hard look at warnings. Warnings are potential Errors. Recently I came across an interesting warning with VC++.

warning C4146: unary minus operator applied to unsigned type, result still unsigned

A bit of googling revealed that above warning can be dangerous. To understand the underlying problem, here is my own version of INT_MIN.

#define INT32_MIN -2147483648

As 2147483648 is greater than max 32-bit signed int value (MAX_INT), it is treated as unsigned int. With this, type promotion kicks in and would fail the following condition.

if ( 1 > INT32_MIN ) // comparing two unsigned values
std::cout << "I am sure, 1 gt INT32_MIN";
else
std::cout << "Surprse! it says, 1 lt INT32_MIN";

To correctly define our own version of INT_MIN, see how it is defined in limits.h. The trick is to not to let the value to cross (signed) 32 bit int limits. The correct version should look like below.

#define INT32_MIN (-2147483647 - 1) // don't forget to put the braces around

Refrences:

1. More detailed explanation is available here
2.
warning C4146

Tuesday, June 23, 2009

Quote from IBM GTO 2008

Good quote from IBM's Global Technology Outlook 2008.

A computer, like anything else, works best when it is built and used for a specific purpose. Though far more complex than a hammer or saw, a computer is a tool just the same. And all tools must be designed to a task.

Sunday, February 08, 2009

exstr dupms core on lenghty strings

Make messages normally uses exstr to extract strings that needs to be localized. It looks like exstr suffers from buffer overflow vulnerability. It dumps core on Solaris 9 with the following program snippet. exstr doesn't seem to process a lengthy string.


void PrintUsage()
{
std::cout << "#mycmd -option1 -subopt1 -subopt2 -suboption3 \n\
-option2 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
......................... \n\
-option15 -subopt1 -subopt2"
<< std::endl;
}


In order to generate message strings, I had to break the above snippet into ugly looking pieces - quite bad, I had to split the options mid way.


void PrintUsage()
{
std::cout << "#mycmd -option1 -subopt1 -subopt2 -suboption3 \n\
-option2 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
.........................\n\
-option9 -subopt1 -subopt2";

std::cout << " -option10 -subopt1 -subopt2 -suboption3 \n\
-option11 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
.........................\n\
-option15 -subopt1 -subopt2";
<< std::endl;
}

Tuesday, January 06, 2009

VIXIMO's VixML platform for iphone

Looks cool, featuring

- Physics engine
- 2D and 3D visual effects
- Easy to use by non programmers