Home > Blogs > Goofy API functions

Goofy API functions

By  Apr 16, 2008

Topics: Programming, Windows Programming

Sometimes I wonder if API designers think about how people will view their functions.  A good example is the Console.ReadKey method in the .NET Runtime.  

Console.ReadKey is a simple enough method.  It just reads the next key from the console input.  This is a lower-level function in that it will return function keys, cursor movement keys, etc.  There are two overloads:  ReadKey with no parameters returns the next key and also echoes it to the console.  ReadKey(bool intercept) optionally echoes the key to the console.  It's the description of that intercept parameter that makes me wonder:

Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.

Nothing like a little negative logic to start your day off on the right foot.

I suspect that the programmer who designed this method was following the logic in whatever Windows API function (ReadConsole, perhaps) that ReadKey eventually calls, but he should have swapped the meaning of the intercept parameter so that we could pass true to display the key.  "true to not display" is just wrong.

Become an InformIT Member

Take advantage of special member promotions, everyday discounts, quick access to saved content, and more! Join Today.