Don’t write “smart,” “fast,” or “safe” code

This is really about naming. Never name anything “smartXXX,” “fastYYY,” or “safeZZZ.” I see it happen all the time.

The crux of the biscuit is that once you’ve called a function, method, class, or what-have-you “smartXXX,” “fastYYY,” or “safeZZZ,” why the hell would I ever use ordinary XXX, YYY, or ZZZ. Am I supposed to prefer “dumb,” “slow,” or “dangerous” code? If the version you’ve produced is purely superior and functionally equivalent to the existing code otherwise, get rid of the existing stuff. If it differs in some meaningful way, it can’t ONLY be that it differs in being smarter, faster, or safer. Otherwise, you’d purge the other one. Tell us something useful in its name about why the old one continues to exist. If your new one is “safe” because it catches exceptions and deals with them somehow where the old one allowed them to pass upward, don’t call it “safeFoo,” call it “FooNoThrow.”
Continue reading