java - Excessive checks vs Future extensibility tradeoff -


i can sure 'my code' called returnlist() never going return null. not null pointer check when loop in enhanced loop. but, looking maintenance not appear practice, since in future can modify code base inadvertantly or override call , overridden function may not prudent enough return empty collections.

   public class extendedforloop {      public list<integer> returnlist() {         // compute.         if list == null ? collections.emptycollections : list;     }      public static void main(string args[]) {         (integer : returnlist()) {              system.out.println(i);         } } 

so making question generic, question intended know best practices of draw tradeoff line. understand there not defined rule such cases, seeking best practices.

  1. adding excessive checks in self written code adds clutter ensures safe future modifications.

  2. reducing checks because 'you know wont return null' makes code clean, live risk of accidental modification.

if care such aspect of code's evolution, should:

  1. write proper javadoc documentation
  2. write proper unit tests
  3. setup ci environment

documentation designed consumed developers, developers under pressure adopt fast reading techniques reduce understanding of details.

if code test asserting all required properties of code, can remove such checks clients. however, note tests have mantained. while ci, default, ensure running tests passes, says nothing missing tests.

unfortunately can't enforce required unit tests have been written in ci process. can do, enforcing minimum code coverage of 100% ensure minimal number of reviews of code.
but code won't perfect, nevertheless.

the best practice do payed for, honestly.
means if coding prototype or application doesn't need reliable, should not care such concerns!

on opposite if coding (say) surgery-robot's controller, should ensure @ least 100% coverage test, , updated documentation (and still prepared cause few deads).

reliability feature other: should estimated, payed , measured.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -