by kruffin · 13y ago · 0 comments
You can do this, but if you want it to be maintainable, you'll also want to detail in the function comments this technical debt. If you don't, someone else will come along and see your sweet method (looking only at the comments) and use it where the input can be null.
Ex:
/**
* This does some stuff.
* @param entry Does something with this
* DEBT: Assumes the input entry is not null.
*/
void doSomething(SomeObject entry) { }Depending on your user-base (i.e. if you distribute headers to other developers with precompiled code), the documentation may be necessary on its own... but it's much weaker than an assert.
For anyone who needs to look it up like me: http://en.wikipedia.org/wiki/Reference_(C%2B%2B)
If people want to pass lazy NullPointerExceptions, it's their fault.