Get Rid Of Useless Comments

Trawling through legacy code sometimes you will come across code like the following:

**
 * Insert the method's description here.
 * @since (01/01/1900)
 * @param id String
 * @param a String
 * @param b String
 * @return String
 */

No matter how you look at it. This is is useless code. It adds no value whatsoever. All the information that is contained in this Javadoc block can be gleaned from the method signature.

Whenever I am in a class and I suspect that there is code like this in the class I use the following regular expression to help me identify and delete such code.

(/*([^*]|[rn]|(*+([^*/]|[rn])))**+/)|(//.*)

Happy hunting!

Otasco

When I first heard about unit testing, I immediately thought it was stupid.  Write code that tests your code.  How absurd.  Now I find it difficult to write code without tests.

One of the things that really pained me was writing setters for code that didn’t use them other than for unit tests.  This led me to write a utility called Otasco.  Why the name Otasco you ask?  Well that story is for another post.

Consider the following unit test:

@RunWith(MockitoJUnitRunner.class)
public class InvoiceManagerTest {
    @ClassUnderTest
    private InvoiceManager manager;

    @Mock
    @Dependency
    private InvoiceCalculator invoiceCalculator;

    @Mock
    @Dependency
    private InvoiceDao invoiceDao;

    @Before
    public void setup() {
        manager = new InvoiceManager();
        Otasco.init(this);
    }
}

This above would allow us to test the class under test InvoiceManager without actually having to write useless setters for members invoiceDao and invoiceCalculator.

I hope this helps you out.  It has really helped out our development team to be a bit more productive.  Let me know what you think.

You can check out the source at GitHub.

To use in your Maven project use the following repository:

<repository>
    <id>otasco-releases</id>
    <name>Otasco Releases</name>
    <url>https://github.com/kenyattaclark/otasco-mvn-repo/raw/master/releases</url>
    <releases>
        <enabled>true</enabled>
     </releases>
</repository>