Engineering Essentials
I see a lot of stupid stuff while developing software. I see it professionally, I see it in the open source world. I see some things over and over again. So here we go, a bunch of key concepts, anti-patterns, and miscellaneous crap that drives me batty.
Source control is actually easy to use, and is useful. git is free, play with it.
Source control keeps old revisions of code, you don’t need to keep them in the file as commented out blocks. Or worse, enclose them in
if (0) { ... }
or#if 0 ... #endif
blocks. Delete the damn code already.A global or static hash/dict/HashTable does not a cache make. Caches have size bounding, expiration schemes, and locking semantics. What you’re creating is a memory leak and potential headache.
The solution in Java (or any OO language) is usually not another singleton or class method.
Deprecation is a nice thing to do.
“Fixed bug” is not a valid check-in comment. Neither is “changed code”.
You should do a source control update before you test/check-in, because I don’t give a flying fuck how well your new code works against the copy of the source code you updated 2 weeks ago.
That thing you don’t understand and are misusing? There’s a book on it. I’m sure of it.
That thing you couldn’t find a book about? Google knows where an article is on it. Giants exist and have amazing shoulders.
If you ever think, “Man, I can’t believe nobody has written a standard library to handle this problem! I’m going solve it!” you should stop coding. Someone probably already has solved it, and you just haven’t looked hard enough.
Not all your code is “library worthy”. Write it first as a local function. Then learn from your local version as you write another local version. If it turns out that other people can use it, then and only then should you move it to a common library area.
A library should never be named after your business model. If you’re writing a finacial system,
libfinance
is the worst thing you can start with because everyone will justify that their new function is a part of dealing with finances, and belongs inlibfinance
. Within a very short time, it will become an unweildy, unmaintainable mess.Stop being so damn timid. You’re a developer, rewrite it already!
Global variables are still a bad idea. Seriously. This is something that hasn’t changed since you took your first programming class.
Use a logging framework and provide meaningful log messages. Otherwise the operations guys will kill you in your sleep. It’s not a big deal for them. They’re already awake and angry because your shit broke and printed the phrase, “Something bad happened” to
STDERR
.A cron job that prints out “Completed successfully” every time it runs is against the rules. Cron emails he operations guys; they don’t like deleting messages all day that confirm that they don’t need to fix anything. How would you like it if the guy you work with stopped by every ten minutes to tell you all is well? Be silent on success, and noisy (and helpful) on failure. Also, again, use logging!
Write code and comments for the next person who will be in the code. If you’ve ever indignantly wondered “who wrote this code” and found it to be yourself, think how someone else would feel.