Why the hell are you complaining about static methods?
Seriously, is there any difference between:
Math.Absolute(x)
x.Absolute()
No. Look at the assembly, it compiles to the exact same thing. The only difference is that in the second line the parameter happens to before the function name instead of after.
As for testability, there is zero difference. I cannot think of any reason why I would test one differently than the other.
What about maintainability? You cannot start shuffling everything around just for the sake of testing and completely ignore the complexity it adds.
Stuff like dependency injection is not free. It adds a significant amount of complexity in terms of the number of possible paths as well as the overall code size.
Focusing again on the “avoid the new operator” bit. If a class doesn’t know how to construct its own dependencies, then who does?
Every single location that needs an instance of that class? Do you really want to cut and paste that much code?
Instead of testing a complete component, with all its dependencies neatly encapsulated, you are just testing a shell. You now have to go back and test everything that uses this component to make sure it is correctly assembling the guts.
5 responses so far ↓
thank you for this great stuff!
does the slides are available somewhere by any chance ?
Thanks a lot for your talk, it was very informative and insightful.
Wonderful talk. More people should have been there!
Why the hell are you complaining about static methods?
Seriously, is there any difference between:
Math.Absolute(x)
x.Absolute()
No. Look at the assembly, it compiles to the exact same thing. The only difference is that in the second line the parameter happens to before the function name instead of after.
As for testability, there is zero difference. I cannot think of any reason why I would test one differently than the other.
What about maintainability? You cannot start shuffling everything around just for the sake of testing and completely ignore the complexity it adds.
Stuff like dependency injection is not free. It adds a significant amount of complexity in terms of the number of possible paths as well as the overall code size.
Focusing again on the “avoid the new operator” bit. If a class doesn’t know how to construct its own dependencies, then who does?
Every single location that needs an instance of that class? Do you really want to cut and paste that much code?
Instead of testing a complete component, with all its dependencies neatly encapsulated, you are just testing a shell. You now have to go back and test everything that uses this component to make sure it is correctly assembling the guts.
Leave a Comment