Against enforce()

Kagamin spam at here.lot
Fri Mar 18 09:08:38 PDT 2011


Steven Schveighoffer Wrote:

> 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.


More information about the Digitalmars-d mailing list