Flutterby™! : Software Engineering Rant OTD

Next unread comment / Catchup all unread comments User Account Info | Logout | XML/Pilot/etc versions | Long version (with comments) | Weblog archives | Site Map | | Browse Topics

Software Engineering Rant OTD

2001-09-25 22:03:16+00 by Dan Lyke 5 comments

"Correctness" is great in theory, but usually ends up inducing huge loads on subsequent programmers. If, in an API, you see a common mistake being made, the right solution is not to demand that users of that API fix their code, it's to allow for that mistake. Luckily it's my API and those objecting don't have the time to look at my code...

[ related topics: Software Engineering ]

comments in ascending chronological order (reverse):

#Comment made: 2002-02-21 05:32:49+00 by: TheSHAD0W

> ...The right solution is not to demand that users of
> that API fix their code, it's to allow for that mistake.

Or to improve the error-checking so when someone makes that mistake, it's pounced upon and reported concisely.

#Comment made: 2002-02-21 05:32:49+00 by: Dan Lyke

I disagree. If it's critical to the operation, sure, but in quite a few places (and the place where this is a specific issue), all that error checking does is confuse the new programmer.

If you had a user interface where you could puzzle out what the user really wanted to do, would you set up to give them instructions on how to do that, or would you just program around it to do it? Too often, especially at the API level, we give them an error which is essentially just a way to give them instructions on how to do what we knew how to do in the first place.

#Comment made: 2002-02-21 05:32:50+00 by: pharm

Sounds like what you describe implies that the API is malformed.

In general, not reporting an error to a user sounds like the easy road to ruin to me :)

#Comment made: 2002-02-21 05:32:50+00 by: Dan Lyke

The issue was over an API that passes a begin and end pointer to an XML chunk. If the XML is '\0' terminated, and the end pointer points to the byte after the , then the XML parse fails (obviously). But when people started to use the API, practice suggests that passing this around as a '\0' terminated buffer, and being able to write xmlparse(buf, buf+len) where len is the length of the buffer including the '\0' terminator, was sometimes the obvious way to call.

The debate was "return the error, or insert while ('\0' == *(end - 1) && end > begin) end--; at the beginning of the function.

In ages past, I would've advocated returning the error. Nowadays I'm quite happy to program around it. Reducing questions and confusion rather than enforcing a rigid style has become my guiding principle.

#Comment made: 2001-10-02 14:05:19+00 by: pharm

So this implies that the API was ambiguous. In this case, recoding the library to take account of common usage (so long as that doesn't lead inevitably to more problems elsewhere) doesn't seem wildly unreasonable.