Posted by sjasja
on November 22, 2005 at 9:34 AM PST
Ever seen a newbie coder (or even a seasoned one on an off day) write a statement like "someString.toUpperCase();" and thinking someString is now upper case?
There are methods whose return values shouldn't be ignored.
Random idea of the day: an annotation known to the compiler. When a program ignores the return value of a method that is defined with @PureFunction, the compiler (optionally) emits a warning.
* Bloat! Bloat! Bloat!
* There are some semi-pure functions. Would Iterator.next() be pure? Usually you want to use the value but not 100% necessarily. C's lint uses casts to void to mean "I'm ignoring this on purpose"...
* Could also be the reverse: an annotation that means "it's ok to ignore my return value". But that ship has sailed; would cause warnings for all existing code. @PureFunction is non-invasive; you can annotate your methods any time or not mark them at all.
* @PureFunction is a misnomer; it does not mean no side effects. Opening a database connection surely has side effects but it would still be marked "don't ignore my value." Needs a better name...
Thoughts? Rotten fruit?