3 ms·
The Easiest Way to Handle Errors Is to Not Have Them
- syndicatedjelly 3y agoOtherwise known as poka-yoke in other fields of engineering: https://en.wikipedia.org/wiki/Poka-yoke https://en.wikipedia.org/wiki/Poka-yoke
- josephcsible 3y agoThis seems like the approach that http://thecodelesscode.com/case/115 http://thecodelesscode.com/case/115 warns against.
- 082349872349872 3y agoNot encountering errors is distinct from masking them. The former is poka-yoke or ensuring weakest preconditions; the latter case 115. > "The key to strategy, little Vor," she explained kindly, "is not to choose a path to victory, but to choose so that all paths lead to a victory." —LMB
- josephcsible 3y agoCompare this section: > The primary reason reading from pointers (prepared by other codepaths) may cause an access violation is because code preparing the pointers often makes the decision to (a) return a pointer to some valid and accessible spot, or (b) return a null pointer. In the case of (a), the pointer can be read from without an access violation. In the case of (b), it cannot. > But a simple solution is to prefer option (c) to (b)—return a pointer to a “nil struct”, rather than a null pointer, if (a) fails. This nil struct is allocated up-front and may be stored in read-only memory. Any pointers contained in the nil struct point to other nil structs of the associated type. If there are pointers to the same type, they point at the same nil struct in which they’re contained (in other words, the pointers are self-referential). With this one: > “You take great pains to avoid null-valued objects,” said the master. “You initialize all Strings to empty, and coerce nulls to empty when setting String-valued properties. Furthermore you store the properties of your Data Transfer Objects in primitives, causing null integer columns to be read as zeroes and null booleans to be read as false. Explain.” > The boy replied: “In my experience, our most common production error is the NullPointerException. I seek to minimize the occurences of this.” Aren't both of those saying exactly the same thing, specifically to use valid but dummy values in place of NULL?
- 082349872349872 3y agoThey're not saying the same thing: a pointer to a dummy "nil struct" can be safely dereferenced by the machine (low-level-valid) yet remains disjoint from all the (high-level-) valid structures of that type; however a NULL stored in a DB is not equivalent to (in the case given, should not be confused with) either a '' or a 0 or a FALSE. Null pointers <> SQL NULL