Re: Standard library praise and challenge

new topic     » goto parent     » topic index » view thread      » older message » newer message

It would surprise me that a programmer without enough forethought to check to see if a sequence has no length (or ensure it always has some length) before calling min() or max() will have forethought to check for an error code. In the case where a programmer is not diligent, whatever that error code is for passing {}, be it, the bag({}), NaN, PINF, NINF, or "WTF", will be used in the next calculation as if everything is till okay.

Most recently, I was interested in what the maximum tension on a joint inside of a truss system for choosing the kind of joint one should use. The error value would be used to determine what joint type to use. Logical errors propagate through the code until the program says that the weakest joint is okay to use.

This following is an abbreviation of what I wrote for my private library and I use it myself. If you don't want to check for errors you turn type checking off. max and min assume that s[1] exists. There is no need to return nan, PINF, NINF, or "".

type nonemptysequence(sequence s) 
    return length(s) != 0 
end type 
 
function max(nonemptysequence s) 
... 
 
function min(nonemptysequence s) 
... 

Shawn Pringle

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu