Code Can Reflect Shallow Understanding

Oct. 30, 2026

Previously (here and here), I’ve argued that everyone should learn to code (even truck drivers in 2026).

The core concept is that code allows for creating digital representations of our internal mental models, which allows us to test and confirm whether our understanding is actually correct.

But the fact that you can represent your understanding with code does not necessarily mean that you possess deep understanding.

It’s entirely possible to write code that reflects shallow understanding.

I’ll explore an example below, using a basic Stat 101 concept, the arithmetic mean (what is often meant by the term average).

A shallow understanding of the mean might be demonstrated by describing it as, “The result of adding up the parts and dividing by the number of parts.”

The definition is true, but it’s very basic, and one could utter these exact words in this sequence without really knowing what it means.

We can represent this level of understanding using R code in a fairly straightforward way…

> # Sample Data
> (x=1:6)
[1] 1 2 3 4 5 6
> # Mean Formula from Scratch
> seth_mean=function(data) {sum(data)/length(data)}
> # Let's see if it works...
> seth_mean(x)
[1] 3.5
> # It matches the result of the Base R mean function
> mean(x)
[1] 3.5

We can try to break the new code, such as by messing with the inputs. For example, my custom function has a failure mode relating to NA values…

> # Sample Data with a missing value
> (y=c(x,NA))
[1] 1 2 3 4 5 6 NA
> seth_mean(y)
[1] NA
> # The Base R function can handle this...
> # ...if we simply add an argument
> mean(y,na.rm=T)
[1] 3.5

Note that the above approach “handles” the missing data by omitting those cases, which is not necessarily the best approach.

Reagrdless, I can modify my custom function to accommodate missing values (say, by omitting them), maybe like this…

> # Modified function that omits NA values
> seth_mean2=function(data) {
+ data=na.omit(data)
+ sum(data)/length(data)
+ }
> # Testing it out...
> seth_mean2(y)
[1] 3.5

But what extent of understanding does this code actually convey?

It could represent something deep… or it could merely reflect understanding equivalent to, “Uhh…it’s a statistic that you get when you add things up and divide by the number of them.”

Next time, I’ll explore using code to represent a deeper level of understanding…