The state of C# code contracts
If your following defensive programming principles, a good function should always check its inputs to protect itself from receiving bad data. If you are writing an API library that will be used by other upstream applications or via a publicly available resource, then you need to ensure that the parameters that are passed to its API don’t contain illegal arguments. If there is a bug in production then ideally I would like an exception to be raised and the error to be logged somewhere . For example, the following two functions don’t contain any defensive measures: class Program { static void Main(string[] args) { CreateUser(null, null); SetAlarmTime(1234567); } static void CreateUser(string firstName, string lastName) { // will this function work when nulls are passed in? } static void SetAlarmTime(int hours) { // will this function work if hours is greater than 24? } } As a reader of the above code, you can’t tel