Against enforce()

Kagamin spam at here.lot
Thu Mar 24 03:30:22 PDT 2011


So how do you solve the problem?

---------
> > This is a good example of why it's difficult to decide what "user input"
> > is.  One could consider that the 'user' in this case is the developer
> > using the library, but I don't think that's the right choice.
> > 
> > I'd say it's a bug, this is clearly a contract, since the data being
> > passed into the ctor can easily not be user input (i.e. it's most likely
> > two literals that will never depend on a user).  If it is user input, the
> > caller of the ctor should enforce the user input before passing it to
> > iota.
> 
> You can't validate all user input, so external data ends up spead across
> your entire application. So I don't understand obsession with -release
> switch, because contracts most of the time do validate user input. If we
> think about -release switch as a HP-hack for exotic code, there will be no
> ideological difference between assert and enforce.

As has been point out, the problem is in cases where it's not clear whether you 
should treat input as user input (and therefore needs to _always_ be checked and 
have exceptions thrown on error) or whether you should treat input as being from 
your program and guaranteed to be valid (at which point you use assert to check 
that that guarantee actually holds).
----------


More information about the Digitalmars-d mailing list