In the time it takes to read this message you could have voted twice. Login and vote now.
By Thierry.Lefort
via itscommonsensestupid.blogspot.com
Published: Oct 13 2008 / 17:36
Static method is much more easier to learn, and use compare to OOP and polymorphism,. But somehow it acquires a bad name in the TDD circles. Some people don't like static methods . The reason? Can't mock the static methods.



Comments
soulcutter replied ago:
I somewhat agree with his point, but his post does not present a very strong argument.
zynasis replied ago:
what kindof blindsighted nitwit would see static methods as bad?
are java coders really becoming that naive?!
Bryan Young replied ago:
naive? maybe. I prefer to think that people are just being lazy. Rather than trying to understand all the pros and cons of an argument and reapply the arguments to each problem, most people would rather have a dogmatic law that might apply 80-90% of the time and pretend that it's an absolute truth.
Dogma is much easier than Heuristics.. especially for people who start with a background in Math, Science or Engineering where absolute truths are much more common than other fields.
Miloskov replied ago:
No code samples or comparing code? bah.....
zynasis replied ago:
surely an even mildly experienced person can think of numerous real life examples of swinging both ways on this
Miloskov replied ago:
Haha I know your kind they think they know everything, The elite that knows everything in their damn head, BS. That is why Im reading the article to see the author perspective but no code samples no nothing what kind of blogging or writing is this leaven the reader with own thoughts, if cant put code samples better don't blog on methodologies or programming, period.
zynasis replied ago:
go back to ur java for dummie's book, nublet
kunnar replied ago:
Maybe i am not experienced person then, but i would like to see in code how he exactly mocks static methods. I agree that because of missing code samples such articles about programming suck a little. But otherwise than that it was interesting post.
Rob Signorelli replied ago:
There are times when static methods are definitely good and you don't have to sacrifice testability to get it. I'm sure just about anyone who has worked on a large project has used/written a Utils and/or StringUtils class. Nothing but static methods because frankly there's no state to maintain, so instantiation is a waste of time in those cases. And if anything, those methods are far easier to test because you *don't* have to worry about mocking your utility class. Just mock up your inputs and test.
Generally speaking if you're using statics far beyond that in an OO language, there's a good chance you're not using them correctly anyway. There's room for both without losing anything, so I don't really agree with the author's argument here.
Voters For This Link (11)
Voters Against This Link (2)