|
|
|
|
|
by ndriscoll
1 hour ago
|
|
That's just a nonsense answer though. Like if you have an Account class and a Book class, do you test what happens if you do an invalid, forced typecast to pass a Book to a function that expects an Account? Of course not. You'd have to check that every function "correctly" handles every possible invalid input. Otherwise where do you draw the line? Or you just rely on the type checker to say you're not allowed to pass a Book to a variable of type Account, and you never use casting (incidentally, I don't remember where, but I remember Clean Code having some example of "good" code that relies on casts, which shows the mindset). Then you literally can't even write a test case for this, because it's impossible to write the illogic at all. If the compiler produces wrong code, all bets are off. Your tests can also miscompile. Your unsafe code could modify another thread's stack memory between instructions and act as an evil gremlin so that literally no line is trustworthy, so even your null check is pointless. Or you could... not do that, and treat your programs as logical reasoning. Charles Babbage even addressed this: > On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. |
|