As I pointed out in my previous post, making your intentions clear is crucial in defensive programming. You never want anyone to guess what your code does. Instead, without ambiguity, you want to make sure everyone understands what your code doing. Here is another example of a coding practice that I see everywhere. Most seasoned programmers probably know immediately what… Continue reading "Zen of Defensive Programming: Clear Intentions"
Tag: code safety
Now that we’ve covered the preliminaries, it is time to dive into specific examples to illustrate what defensive programming habits you can build to improve your code. More importantly, I’ll also explain, why they are a good choice. Perhaps the single most important thing to remember is that source code is cheap! This takes us straight back to the readability… Continue reading "Zen of Defensive Programming: Source Code is Cheap"
We are now reaching the part that people usually associate with Defensive Programming: Code Safety. As I mentioned previously, often considered to be the only subject in defensive programming, as you have seen, it represents only a small subset of the subject as a whole. Code safety generally consists of two steps, typically: Assertions and Guard Clauses. Assertions Assertions are… Continue reading "Zen of Defensive Programming: Code Safety"