[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Make sure numbers are numbers
- From: Henk Boom <henk@...>
- Date: Fri, 16 Apr 2010 19:39:20 -0400
On 16 April 2010 06:59, Matthew Wild <mwild1@gmail.com> wrote:
> mystring1 < mystring2 is also perfectly valid thing to do in statically
> typed C, which will also give you a useless answer. In my view type
> checking is not a substitute for tests and code reviews. And if you
> have those, there is little reason left for strict type checking.
But mystring1 and mystring2 are clearly strings, since they've been
manually labelled as having the type 'char *'. There's no opportunity
to mistake them for numbers.
Beyond that, C is an example of a language with a very poor type
system, and its limitations often require circumventing the type
system entirely (e.g. void * casts).
I'm talking about type checking in general, which is just making sure
that values correspond to a contract. (i.e. I have a very broad
interpretation of the word 'type.') Asserts would have worked just as
well, assuming 100% test coverage.
---
A bit of a digression, but I feel uneasy when people suggest that
every part of a program should have tests that ensure its proper
functioning. Not all programs lend themselves to automatic tests. If I
write a game, how to I automatically verify that the behaviour of a
player's controls are correct? They are hand-tuned to satisfy the
contract that they "make the player move fluidly and intuitively,"
with the particular calculations behind them being implementation
details which might change at any time.
It seems at that point the only role tests perform is to detect
crashes, not actually verify (or even suggest) desired behaviour.
(I'm not trying to hate on tests here, type checks (static or dynamic)
can do no better, and in this case don't even accomplish as much as
tests)
henk