r/ExperiencedDevs • u/habitue CTO @ Pylon • Jun 22 '24
Stories of "Intellectual Control" of code vs. "Statistical Control"?
I recently ran across this blog post:
The author defines intellectual control as having a model of the code in your head that's simpler than the code itself.
Statistical Control, on the other hand, is where you believe the code to be correct because the tests on the code are passing, but you don't actually understand the code itself.
Personally, I can remember numerous times where I refactored large swaths of code, maintaining confidence I hadn't broken existing behavior because the tests and types were passing, but I didn't actually have a compact mental model of the system as a whole. If someone had asked me to redesign the system I was refactoring, I wouldn't be able to do it since I didn't really understand it.
Also, this kind of underlies bus factors etc, where a person leaves the company and you have software systems that you now only have statistical control over, but not intellectual control any more. Often having to painfully regain intellectual control.
I'm curious to hear stories of teams that ran heavy on statistical control (maybe a catchall team that inherited orphan systems). Or maybe stories where you saw intellectual control slipping away and how it went.
39
u/ashultz Staff Eng / 25 YOE Jun 22 '24
Complicated frameworks as are currently popular generally push you to statistical control rather than intellectual control. I've worked with a very low framework codebase where we understood all of it and could change it with confidence (we also wrote tests of course).
And I've come in to big spring/node/etc codebases where the existing devs basically treated it as witchcraft. In the spring case to the point of not understanding basic operations of the system. The framework let them create without actually knowing anything.
15
u/annoying_cyclist principal SWE, >15YoE Jun 22 '24
I agree with the author that both of these are important and on a well-functioning project the team has both. They're complementary concepts, addressing related but different concerns.
To me, intellectual control is table stakes for working effectively as an engineer or an engineering team, at least if you're above mid level. Much of what I think of as engineering is difficult or impossible if you don't have a good mental model of the system. Statistical control techniques are a force multiplier for intellectual control: automatically checking nitpicky implications of the mental model, speeding up QA processes, reducing defect rates, and lowering the bar somewhat for new teammates (you don't need to index as heavily on skill, judgement, and knowledge if you're not totally relying on engineers for the things statistical control gives you). I've seen successful teams that rely almost exclusively on intellectual control for the things statistical control can provide (I probably wouldn't voluntarily work on one at this point, they can be really stressful). I've never seen a successful team that relied almost exclusively on statistical control and didn't have at least a couple people with a decent mental model of the system they're working on.
10
u/oxleyca Principal Software Engineer Jun 22 '24
I don’t think these things are correlated. I’ve seen teams have poor mental model for systems they own (typically built by others who left) and terrible tests, and tests with good mental models.
Having a solid mental model doesn’t eliminate edge cases. You can have the best idea for programs flow and still find valuable bugs with a fuzzer or input enumeration.
That being said, it’s still a good exercise to think on what systems your team shares a good mental of and which ones lack.
3
u/ravixp Jun 23 '24
This is a great framework for thinking about this, and something that I plan to share with my team. One thing that I wish it addressed more is how intellectual and statistical control evolve with a team.
Intellectual control is necessary if you want to make changes to a system. A good test suite will help confirm that you didn’t change anything that you didn’t mean to change, but it won’t tell you whether a new feature works correctly, you have to write new tests for that.
Statistical control is a lot easier to scale, and a lot easier to measure, compared to intellectual control. You can tell everybody to run tests with every change, and you can measure your code coverage objectively, but it’s much harder to measure whether new engineers understand the design philosophy of the system.
Statistical control is also a lot easier to keep, because your test suite is a technical artifact, while your intellectual control of a system lives in people’s heads. Lose the wrong engineer and you can lose intellectual control over part of your system, and worse, you may not realize it until you actually need to update that part.
7
u/AncientPlatypus Jun 22 '24
It seems to me the author is conflating 2 very different things. There is absolutely no relationship between more tests and worse code.
In my experience teams without enough diligence to keep a good test suite are the same teams that write complex and brittle code.
If a team is having issues with bad code that’s a process problem in the code review, and having less testing would just let people be confidently wrong
6
u/[deleted] Jun 22 '24
An experienced developer should have a mental model of the system.
2
u/jakeStacktrace Jun 22 '24
For me, I have to know if the tests are actually ensuring my change is safe, because of their quality and they test the kinds of things that might break. At that level, I have a mental model of what the code is doing, or I wouldn't know enough about the tests to trust them. There is different levels too like performance and UAT, not just unit functionality to consider.
1
u/idontliketosay Jun 23 '24
If I understand, intellectual control is like Unix, or windows. I have a simplistic understanding of how that code works and I am able to run my code on the OS. As for statical control, tests, I find this works well for checking code is still compatible with the data, less so when I am adding a new feature.
0
u/wwww4all Jun 22 '24
It's called black box testing.
It's been a thing for decades.