public void myMethod(String name) {Why bother to override a method (without changing it's visibility) and do nothing? I find it just clutters up the code and adds exactly nothing. This goes for constructors as well, which is where I see this type of code more often, especially when people write JUnit tests!
super.myMethod(name);
}
Does this make sense to anyone? Is there some secret that other people know that I'm missing by writing code that does nothing? This rant brought to you by reading someone else's code.
O mighty Jim, greatest programmer in the world. I am not worthy :)
ReplyDeleteFirst: read the code properly. Or try and compile and run it yourself. Hint: look at the constructor.newInstance() call.
If you really do have a better approach, as the last line in my blog post urges, I would be interested in some constructive feedback.
- Peter
"O mighty Jim, greatest programmer in the world. I am not worthy" - you must be new here. ;-)
ReplyDeleteFirst off, I meant no offense. I have just seen a lot of places where people override methods / constructors that do nothing and I was frustrated by this. I figured that I was missing something that everyone else knew: that's why I made this post in the first place. You've got to ask the question to learn, even if you risk looking like a total idiot (like today!).
Unfortunately I lumped overriding constructors and methods into the same category. They are not the same. I understand now *why* you have to explicitly have the non-default constructors that you want to call.
However, I still don't understand why people override methods (like in my example). :-( Is it bad coding? Is it "clearer" to them? Is it just adding line count to their app? I don't know.
As for functional testing, I can't really give any constructive feedback on using something like watij. I have found that unit testing frameworks like StrutsTestCase / Cactus etc. have been good enough for me right now.
Peace. Sorry for sounding off there for a moment. I completely agree with your observations on generally overriding methods without any value-add.
ReplyDeleteIt's just that I thought I had solved one of the greatest gripes I had against JUnit and you were picking holes in my coding standards :) while pointing visitors to my blog!
Regarding Watij - Watij is for *functional* testing, hence the need to hack a framework designed for unit testing such as JUnit. If you need to repeatedly test a whole slew of web-pages, you'll love it.
Again, sorry for pointing to your site in a way that made it seem like it was a bad example.
ReplyDeleteHowever, on a totally different note, I don't think that you solved your problem. It may work, but it's not (from what I read) guaranteed by the docs.
See my comment on your post.
http://ptrthomas.wordpress.com/2006/08/23/watij-and-running-junit-test-methods-in-the-order-that-you-want/#comment-397
Maybe the overriding method is just a stub for a future implementation? Maybe it's just there as a reminder for later development? That's my only guess. But, then, you'd sort of expect some comments in there to explain the stub. Meh.
ReplyDeleteIt's because their employers use lines of code as a metric of how much work they are doing, and overriding methods with simple calls to the parent methods is a way of increasing the number of lines without too much effort.
ReplyDeleteOn the other hand, it's probably just left over code from when they originally made the class, thought they were going to have to override the function, and later decided that nothing needed to be done. Maybe it's just a better idea to write out the function, so it shows that they thought about overwriting it, and decided to do nothing, instead of forgetting to overwrite it when they really should have.
Overwrite?
ReplyDeleteLike a lot of code, it's a personal preference.
ReplyDeleteUnit tests will dictate whether a method really needs to be overridden ... and that's all I worry about. :)