Re: xmalloc string functions
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 11:10:54 -0000
"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
Malcolm McLean said:It depends on the costs.
<program snipped>
There's a program to print a file,
...which exhibits undefined behaviour because you call a variadic function
without a valid function prototype in scope.
prepending the line number. See how
simple it is, because we don't have to do any error processing?
Correction: see how simple it is, because you didn't *bother* to do any
error processing.
The computer on which I type this is connected to a UPS. Since the power
hardly ever fails, why do I bother? The UPS has a mains lead ending in a
plug with a fuse in it. Since it hardly ever happens that too much power
goes through the lead, why bother? The plug fits into a surge protector.
(In fact, the UPS is surge-protected, too.) The router also plugs into
this surge protector. But why bother, since surges are so rare? And the
surge protector has its own fuse. Why bother with /that/? And if we /are/
bothering with that, why bother to fuse-protect anything that plugs into
it?
You seem to have fundamentally misunderstood the importance of
defensive programming.
Here we've taken virtually all the error-processing out and passed it to xmalloc, which will exit with an error message if anything goes wrong. We could write the program so that it is not line-based at all. Then it won't crash out if someone passes it a malformed line. But it would be harder to read and understand.
The main cost of a program is usually the development cost, and then the costs of maintainence. That's what you've got to attack. Convoluted logic for every bit of string processing, because the machine might run out of memory, isn't helping anyone, unless the application really must never terminate.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: xmalloc string functions
- From: santosh
- Re: xmalloc string functions
- From: Richard Heathfield
- Re: xmalloc string functions
- References:
- xmalloc string functions
- From: Malcolm McLean
- Re: xmalloc string functions
- From: santosh
- Re: xmalloc string functions
- From: Malcolm McLean
- Re: xmalloc string functions
- From: vippstar
- Re: xmalloc string functions
- From: Malcolm McLean
- Re: xmalloc string functions
- From: Richard Heathfield
- xmalloc string functions
- Prev by Date: Re: xmalloc string functions
- Next by Date: Re: xmalloc string functions
- Previous by thread: Re: xmalloc string functions
- Next by thread: Re: xmalloc string functions
- Index(es):
Relevant Pages
|