Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: best practices to prevent new bugs Date: Sun, 8 Mar 2015 21:05:29 +0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: References: <0518334b-4613-4931-b324-05c36e089154@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 8 Mar 2015 21:05:29 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="15510"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pTIj5M0b0winxfxGNIfg4cQlEBxSBvKE=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:Pagm9tFZzPskyIGiuRisOQpeMo0= Xref: csiph.com comp.lang.java.programmer:31291 On Sun, 08 Mar 2015 13:33:44 -0700, Ajay Paul wrote: > I am looking some best practices while fixing bugs to prevent new bugs > from coming up. Suggestions: 1) Develop a unit test harness and a comprehensive set of tests for each class. Storing a set of validated expected results will allow you to use these three elements to run regression tests each time the class is changed. The test suite for each class must be extended and revalidated each time the classes functionality is extended. I think this should be mandatory for every class that is expected to be used in more than one program, though it may not be practical to carry out such fine-grained testing for classes that aren't intended for reuse. Before you ask, yes I do this for code I write for my own use too and find it pays off in terms of more reliable code and fewer bugs. 2) Insist on having comprehensive class-level and method-level comments and keeping it up to date. Use javadocs to check the comments for readability. While this may not help with debugging when the code is initially written, it will be enormously helpful when the code is changed later. Yes, I do this for my own private code too and I do it because I find its useful. 3) Make sure the team library has a copy of The Practice of Programming by Kernighan & Pike and that junior members read it and take note of its recommendations, while its aimed more at C, its equally applicable to all block-structured languages and is helpful in a Java shop. If the team's development practices are based in its recommendations you'll find you're writing more easily debuggable and maintainable code. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |