Re: xmalloc string functions




"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
Malcolm McLean said:

<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.

It depends on the costs.
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

.



Relevant Pages

  • Re: xmalloc string functions
    ... because we don't have to do any error processing? ... see how simple it is, because you didn't *bother* to do ... ending in a plug with a fuse in it. ... router also plugs into this surge protector. ...
    (comp.lang.c)
  • Re: Canada says no plan to get rid of the penny soon
    ... Good merchants avoid anything that causes discontent, ... and those who don't like to bother with exact change because ... To stop striking cents would not save a substantial ... essentially none of those core costs are reduced. ...
    (rec.collecting.coins)
  • Re: Non-geographic numbers: future?
    ... "We have effectively done away with any extra call costs on our ... fixed line phones by using the mobiles for almost all the calls and therefore ... 18866 give me peak rate calls if I need them and don't cost me any monthly subs. ... My spend with them is now almost zero, but why should I bother cancelling? ...
    (uk.telecom)
  • Re: xmalloc string functions
    ... without a valid function prototype in scope. ... see how simple it is, because you didn't *bother* to do any ... The plug fits into a surge protector. ...
    (comp.lang.c)
  • Re: ABC scraps new "Circus of the Stars"
    ... cast, the Alphabet decided to pull the plug on its project earlier ... Didn't seem to bother them on Dancing with the Stars... ...
    (rec.arts.tv)