Thursday, January 14, 2010

const char* versus const char* const

From the "WTF/programming" department.

This is one I've learned and forgotten more than once. Maybe writing it down will make it stick. We'll see.

In the C programming language const-ness of pointers can refer to the pointer itself as well as the object being referenced.

const char* foo = "Foo!";

Here foo is a mutable pointer to an immutable C string.

char* const bar = "Bar!";

Now with bar we have an immutable pointer bar to a mutable C string.

const char* const baaz = "Baaz!";

Boom. Now we have baaz: an immutable pointer to an immutable C string.

So what's up with the bizarre syntax? I mean, the trailing const style is almost never seen in actual C code. It's not just me that finds this obtuse.

My poor dyslexic head can't keep this sort of nonsense straight. I mean it all makes sense now, but next week I'll only remember "const char* const" means something useful. And of course all this is compile-time only and can be fairly easily circumvented with casting.

WTF. Take away is (as it often is): don't get too clever.

Tuesday, January 12, 2010

Crowdsourcing: the uninformed masses

Crowdsourcing is meant to tap into the power of the Wisdom of the Crowds. But does it work? The wisdom of crowds is meant to tap into the power many people arriving at a better answer than any one individual. Crowdsourcing does this via various Internet means.

The critique of crowdsourcing is that it is too highly influenced by public opinion, similar to groupthink. (An article in the December 2009 issue of Communications of the ACM discusses this point, and the Wikipedia page on The Wisdom of the Crowds has a similar argument.)

Looked at from another angle, crowdsourcing suffers from participants having uninformed opinions. The wisdom of crowds works when everyone is making educated guesses. Crowdsourcing breaks down to an uninformed mob. Conversely crowdsourcing should work when the target crowd is fairly knowledgeable.

Leo Laporte's TWiP podcast has chat rooms filled with fans during the live podcast. This group tends to know quite a bit about technology and so "crowdsourced" questions to them result in nice answers. Good. But then digging through product review forums on random websites shows quite a number of people yammering on about products they don't own and giving lame and often incorrect generalizations to questions. Bad.