This is another of Steve McConnell’s (author of Code Complete) gems.
Do we do this?
If not, why not?
Anytime you find yourself looking at a class’s implementation to figure out how to use the class, you’re not programming to the interface; you’re programming through the interface to the implementation. If you’re programming through the interface, encapsulation is broken, and once encapsulation starts to break down, abstraction won’t be far behind.
If you can’t figure out how to use a class based solely on its interface documentation, the right response is not to pull up the source code and look at the implementation. That’s good initiative but bad judgment. The right response is to contact the author of the class and say “I can’t figure out how to use this class.” The right response on the class-author’s part is not to answer your question face to face. the right response for the class author is to check out the class-interface file, modify the class-interface documentation, check the file back in, and then say “See if you can understand how it works now. “You want this dialog to occur in the interface code itself so that it will be preserved for future programmers. You don’t want the dialog to occur solely in your own mind, which will bake subtle semantic dependencies into the client code that uses the class. and you don’t want the dialog to occur interpersonally so that it benefits only your code but no one else’s.
May 11, 2013 at 13:01 |
[…] What is the most expensive part of the SDLC? (hint: reading others code) […]
July 6, 2013 at 13:05 |
[…] language. Use its dynamic nature cautiously if you want performant code. Most importantly, favour read time convenience over write time. Your code is going to be read many more times than it’s […]
July 29, 2013 at 15:47 |
Hey there! This is my first comment here so I just wanted to give a quick
shout out and say I truly enjoy reading your articles.
Can you recommend any other blogs/websites/forums that deal
with the same subjects? Thanks for your time!
January 31, 2014 at 11:17 |
Keep oon writing, great job!
January 31, 2014 at 19:29 |
Thanks for the encouragement 🙂
August 16, 2014 at 08:13 |
Epic. Informative