4 ms·
A lot of these seem to be attempts to fit into existing "best practices". Unit tests that prove nothing. Boilerplate Java code that does nothing. Maybe we shou
by collyw 13y ago
A lot of these seem to be attempts to fit into existing "best practices". Unit tests that prove nothing. Boilerplate Java code that does nothing.
Maybe we should reevaluate some best practices. I have debated before on here that many unit tests seem useless as the units are too small, and you essentially end up testing your language or framework which you already know works. Integration testing on the other hand makes a lot more sens.
When I started with Java, it seemed appropriate to put hundreds of getter / setter methods. Is there much advantage to that over allowing the variable to be accessed directly? (Perl felt very strange at first having getter and setter methods combined as one method).
As I get more experienced as a developer, my skill set has grown but my coding becomes simpler. Don't use every language feature to show how knowledgeable you are. Use it when appropriate, and when it makes the code more readable / reusable / simpler. Sometimes a higher level abstraction is more difficult to understand , but is overall better choice. An example would be a map as opposed to a for loop. Less chance of side effects in a map, as we don't have to track the iterator variable, but a map is not as intuitive for less experienced coders.
- mbillie1 13y agoThe fact that you can write bad unit tests is orthogonal to the notion that writing unit tests is, in general, a good thing to do.
- sanderjd 13y agoI always feel happiest writing unit tests for functions that contain non-trivial logic. But I always feel sad when testing methods that mostly just introduce side effects. It seems like when I'm running into more of the latter, it is often worthwhile to find ways to refactor toward having more of the former, but sometimes not.
- wlievens 13y agoTrue. I find unit tests the most useful and economical when I'm testing algorithms, rather than data bookkeeping or user interfaces.
- reginaldjcooper 13y ago> When I started with Java, it seemed appropriate to put hundreds of getter / setter methods. Is there much advantage to that over allowing the variable to be accessed directly? Oh my yes. As soon as you need more than one processor messing with an object they are invaluable. The only thing better is immutable objects. It's also nice to have the object interface separate from object data if you want to change the object data representation without breaking everything (I don't know in general when you would do this, I just know I have done it before and getter/setters let me work faster to refactor).
- pan69 13y agoBest practices is something you learn over time, as you gain experience. I don't think there is a lack of best practices, it's just that there are always developers learning and gaining experience and before a best practice to make sense to them they have to do it wrong first. I.e. knowing the rules of chess doesn't make you a chess master. As I mature as a developer I notice that it takes more and more time for me to finish something. When I was younger I simply wasn't aware of half the stuff that could go wrong. Now I'm older and I am aware I find myself taking more and more time to implement something and spend a lot more time on e.g. clean interfaces and error handling. Something I simply didn't do many many years ago.