Use small and isolated experiments to resolve uncertainties
When facing uncertainties, create focused experiments to get definitive answers rather than making assumptions or proceeding with incomplete knowledge.
Small and isolated experiments offer:
- Fast feedback - get answers in seconds or minutes, not hours
- Low risk - test ideas without affecting production code
- Clear insights - isolate variables to understand exactly what’s happening
- Reduced friction - avoid long build times and complex setup
Without feedback, there is no opportunity to learn. We can only guess, rather than make decisions based on reality. - Dave Farley in Modern Software Engineering
Useful tools for experimentation
Section titled “Useful tools for experimentation”Online interactive tools
Section titled “Online interactive tools”- Compiler Explorer (godbolt.org) - Assembly output, multi-compiler testing, optimization analysis
- Quick Bench - Performance comparisons and microbenchmarking
- C++ Insights - Template instantiation, compiler transformations
- Regex101 - Interactive regex testing with explanations
- Wandbox - Online compiler with execution support
Local approaches
Section titled “Local approaches”- Minimal test programs - Single-file
.cppprograms for isolated testing - Unit test sandboxes - Small test cases in your test framework
- Interactive debugger - Step through code to understand behavior
- REPL environments - For languages/scenarios that support them
Common uncertainties and experimental approaches
Section titled “Common uncertainties and experimental approaches”Performance questions
Section titled “Performance questions”“Will this optimization actually help?”
- Test on Quickbench
Compilation and language questions
Section titled “Compilation and language questions”“Will this template work across compilers?”
- Test on Compiler Explorer with multiple compilers
- Verify template instantiation with C++ Insights
- Check assembly output for optimization assumptions
Regex and pattern matching
Section titled “Regex and pattern matching”“Does this regex match what I expect?”
- Validate patterns interactively on Regex101
- Test edge cases before integrating into code
API behavior and edge cases
Section titled “API behavior and edge cases”“How does this function behave with empty input?”
#include <gtest/gtest.h>#include <vector>
TEST(SuspiciousFunctionExperiment, CheckWhatHappensWhenInputIsEmpty) { std::vector<int> empty; auto result = suspicious_function(empty); EXPECT_EQ(result, ""); // If the result is not "", the output log will show the actual result.}Unit tests for experimentation
Section titled “Unit tests for experimentation”Unit tests are particularly valuable when:
- Working with proprietary or sensitive code that cannot be shared online
- Needing to preserve experimental insights in your test suite
AI for experimentation
Section titled “AI for experimentation”Using LLM/AI for experimentation can also be very effective:
- Show some code to the AI and ask it: how would this code look…
- … if functional oriented?
- … using modern C++ idioms?
- … with RAII principles?
- Show me 3 different ways to …, and then review which one is cleaner
When this applies
Section titled “When this applies”This approach works best when you:
- Have specific technical questions that can be tested
- Want to validate assumptions before committing to an approach
- Need to understand behavior in isolation from your larger codebase
- Face long build times that make iteration expensive in your main project
For complex architectural decisions or broader design questions, other approaches like prototyping or design reviews may be more appropriate.
Experiment design principles
Section titled “Experiment design principles”- Isolate one variable - test only the specific uncertainty
- Use minimal setup - avoid unnecessary complexity
- Document findings - capture insights for future reference
- Iterate quickly - prefer fast feedback loops over comprehensive tests
Related
Section titled “Related”- Make intentional design decisions - The underlying principle driving experimentation
- Use Static Analysis to guard correctness and consistency - Automated validation techniques