Defensive Programming - DevCon 2023

Links and resources from my talk tomorrow at Access DevCon Vienna 2023, Some Bugs are Better than Others: Defensive Programming Tips and Tricks.

Defensive Programming - DevCon 2023

Slide Deck

DefensiveProgramming-DevCon2023.pdf

Further Reading

High Level Overview

Some Bugs are Better than Others
Not all bugs are created equal. Avoid the expensive ones by making more of the ones that are easy to find and fix.
Syntax Errors
Every programming language has its own syntactical quirks. The C family loves braces. Python loves indentation. BASIC loves words. And Perl loves #%@!{}]&.
Compile Errors
Compile errors are easy to keep out of deployed code (just remember to Debug > Compile). Which is good because they hard crash Access in Runtime mode.
Misunderstood Requirements in the Project Design Phase
Your client knows what’s wrong. They *think* they know how to fix it. But treating symptoms is never as effective as treating the disease.
Automated Test Errors (aka, Failing Tests)
You can have a bug in your code and/or in your test. You’re unlikely to have the *same* bug in your code and your test.
Runtime Errors
It’s impossible to predict every possible scenario that could befall our applications in the wild. But we need to at least try.
Misunderstood Requirements (After You’ve Written the Code)
As you install the final piece of crown molding in the dog’s second bedroom, you can’t help but smile at the absurdity of it all.
Logic Errors
The logic error is the most dangerous and insidious of all software errors.

Turning Expensive Errors into Cheaper Errors

Five Ways to Turn Runtime Errors into Compile Errors in VBA
Compile errors are cheaper and easier to fix than runtime errors. Here are five ways to turn potential runtime errors into compile errors.
Five Ways to Turn Logic Errors into Runtime Errors in VBA
Runtime errors are cheaper and easier to fix than logic errors. Here are five ways to make that happen.
5 Ways to Reduce Logic Errors Using Automated Double-Checks
Identify the critical functions in your application. Then, apply one or more of these techniques to ensure that if they break, someone will notice.

Additional Reading

Why You Should Learn to Love Syntax Errors
The immediate negative feedback loop that syntax errors provide is a powerful learning tool.
Data Validity Checks
Increase the quality of your existing data by running it through a series of validity checks and showing your users the results.
Frictionless Validity Checks
Let’s apply the concept of frictionless development to the defensive programming technique of data validity checks.
Reduce Logic Errors in Critical Code
Software Developers Can Almost Eliminate Logic Errors With This Powerful Technique
The “Unset” Enum Item
This simple technique is a foolproof way to avoid the sort of logic bug that can live undetected in your codebase for years.
Defensive Programming
Don’t build digital Maginot Lines. Program your defenses in depth.
Spinning Plates: What this Parlor Trick Has in Common with Software Development
The fewer items you need to mentally track the less likely you are to make mistakes or generate bugs.
Python-inspired Doc Tests in VBA
Doc tests are not a replacement for unit or integration testing. But they do provide the best return on investment (ROI) of any type of test, mostly because the effort to write them is near zero.

UPDATE [2023-05-02]: Added link to download slide deck.

All original code samples by Mike Wolfe are licensed under CC BY 4.0