I'm working with a huge software system with a lot of people being involved in the coding through many years. I'm noticing more and more that there is a lot of bad code, especially get methods here and there with huge side effects, which you totally not expect.

So it crossed my mind that it would be great with a unit test that detects side effects in get methods and reports them so we can clean up that bad code. But it seems kind of difficult, you would have to analyze the code somehow and make sure that nothing but returning of objects takes place.

Anyone have any experience of this and how to detect bad coding practices like these?



Recommended Answers

All 2 Replies

get methods with huge side effects? what exactly do you mean by that? can you show us an example (doesn't have to be actual code, just an example of what you mean)

Well, for example a get method that, if the object that one asks for is null, creates that objects, and inserts it into some datastructure, populates its values etc..

I've also come across get methods that persists stuff to the database as a side effect. Theres nothing inherently wrong with this, but its simply bad code practice and makes everyone confused.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.