I'm building the skeleton for a C# app and intend to leave a bunch of methods without implementation - returning dummy values. I intend to get back to them, but don't want to accidentally forget to implement any of them.
I'd like to signal when I reach a method that isn't implemented, and continue execution with the dummy value.
What's the idiomatic way of doing this?
The classic way to do this would be:
throw new NotImplementedException();
which is clear to the caller and easy to find later to fix (in fact, it shows up automatically on some task lists). However, if that isn't an option, maybe:
return 0; // TODO
again, this will show up automatically on tasks lists, and is easily found.
If you want something more obvious:
[Obsolete("not implemented")]
public int Foo() {
return 0;
}
which will appear as a compiler warning at the caller, or:
public int Foo() {
#warning Foo not implemented
return 0;
}
which will appear as a compiler warning at the method.
Traditionally you'd throw a NotImplementedException
for a stub but this, of course, will terminate execution of that path. Other options would include:
Just logging it. Stick a line into your log or console output.
Or, depending on how much pop-ups annoy you, you could use Debug.Assert
/Debug.Fail
to pop a message when these methods are hit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With