When writing large systems, it is very common to stub out methods that haven't been fully implemented and return to them later to complete the internal logic.
Often we need to use the method prior to it being implemented, so the default logic is placed in the method body and adding a TODO tag to remind us that we need to complete the method at a future date.
private bool ValidateUserDetails(string userName, string password)
{
return true;
}
This allows us to use the method in our development process, but if the TODO isn't picked up, this can lead to the method not being implemented correctly, often causing our applications to fail in real-lfe scenarios when shipped.
A common approach to ensure that we get round this is to throw a System.NotImplementedException()
exception.
private bool ValidateUserDetails(string userName, string password)
{
throw new System.NotImplementedException();
}
However, this doesn't allow us to use the method during development, so the two approaches are combined by using the #if[^] preprocessor.
private bool ValidateUserDetails(string userName, string password)
{
#if DEBUG
return true;
#else
throw new System.NotImplementedException();
#endif
}
This allows us to use the method in our development process, but this can be dangerous, as it is possible that if not all code paths are tested fully in release mode, then unexpected code can be shipped.
However, by combining this approach with the #error[^] preprocessor, we get the following:
private bool ValidateUserDetails(string userName, string password)
{
#if DEBUG
return true;
#else
#error Not Implented
#endif
}
This allows us to use the method in our development process, but when the project is switched into release mode, it won't compile, so incomplete code can't be shipped.
References:
MSDN has the full list of C# preprocessor directives[^] available.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.