Re:Going Beyond Code to Become a Better Programmer
by koevet on Wednesday June 10, 2015 @03:47AM
(#9690568)
How do you test the code that needs to send an email, if your "SendEmail" function is not in a separate class that can be mocked?
(ok, you can use a fake smtp server, but it makes tests more complex, imo)
Re:Going Beyond Code to Become a Better Programmer
by spinningarrow on Wednesday June 10, 2015 @04:15AM
(#9690629)
Why can't you mock the function? Mocks aren't specific to classes.
Re:Going Beyond Code to Become a Better Programmer
by MichaelGG on Wednesday June 10, 2015 @05:50AM
(#9690889)
If you're passing an object in, you can just as easily pass in a function.
Though I was explicitly referring to the case where the code is literally rewriting static functions into objects without using any actual OO features - just adding extra noise.
As I've gotten more experienced, I do less "ceremony" and more "write code that does stuff". It hasn't seem to hurt, and I end up with less code to maintain.
Explicit is not always better than implicit. If you're being explicit about obvious facts, that's pointless verbosity. Type inference is a good thing; take advantage of it. Implicit's only an issue when there's complicated or hidden rules at play. For instance with automatic conversion operators that do "magic".