Tag: coding

  • Not Everyone Agrees That We All Should Learn to Code

    Nov. 5, 2026

    Previously, I argued that everyone should learn to code. (Well, everyone who wants to learn how to think better, anyway.)

    I should point out that many, many people disagree strongly…

    I Googled this, and I found loads of top hits where the vast majority of individuals argued that No, coding is NOT essential.

    • In the past, many people said things like, “No, because there’s lots of work that doesn’t involve coding.”
    • More recently, people say things like, “No, because AI can do that for us now.”
    • I saw one comment along the lines of, “If we do all need to code, then computers have failed as a concept.”
    • When asked about the benefits of coding, one person even said there were “absolutely none.”
    • Someone said, “%$#! no.”

    That’s fine, but I think they’re all wrong.

    The crux of their confusion (in my view) is in thinking that the value of coding is limited to employment skills.

    In fairness, it makes sense that people would assume that’s all there is to it, because in the past it was very useful for that specific purpose. (Arguably it still is, though I don’t know enough to say.)

    One particularly common response to the claim, “Everyone should learn to code,” is to list any number of other activities (e.g., building cars, forging metal, painting, writing novels…), which obviously not everyone “ought” to learn to do.

    To be clear, if we’re talking about computer programming more generally, as in being able to design entire software applications…then I totally agree that not everyone needs to learn that.

    But if by coding we simply mean being able to express ideas in some programming language…then I completely disagree.

    Consider it like this…

    I grant that you don’t need to know how to write a novel, but you really do need to know how to read and write, at least at a basic level, in order to function optimally in society.

    In the same way, you don’t need to know how to program an entire software application, but I’d argue that you do need to know how to express concepts in digital form in order to think optimally.

    As I’ve said before, it’s like eating your vegetables: It’s not a moral imperative, but it’s good for you.

    Among those who do (or, prior to the increased popularity of LLMs, did) believe coding was universally beneficial, the reasoning usually relates to either getting a job or improving logic and problem-solving skills. Additionally, coding is often promoted as a way to understand computers better.

    I don’t disagree with these points, but I still think they miss something more fundamental…

    In my view, the reason we should all learn to code is so that we can better clarify our understanding of the world.

    It’s not enough to be able to express our ideas verbally. Our verbal explanations often gloss over conceptual gaps without our even realizing it.

    After saying “LLMs are predictive text on steroids” for the millionth time, we start to forget what a dramatic oversimplification that statement is.

    And we slide into the trap of thinking that, because the words in our explanations come so easily, therefore we must understand deeply.

    “But how does predictive text work in the first place?”

    “And what is the mechanism that steroids represent in this metaphor?”

    Either of the above questions would be crushing for most people who liken LLMs to predictive text.

    Our underlying mental models are not as shored up as we like to think they are. This is one of the primary reasons that coding is so beneficial.

    Natural human language allows us to mask gaps in our understanding, because words are simply labels for concepts. You can utter a word regardless of whether you actually grasp its meaning with any depth. And entire statements pass our lips effortlessly, with no inherent check for either logical consistency or even the speaker’s own comprehension.

    Nor is there any guarantee that a listener will point out logical inconsistencies. Often, if it “sounds right,” we assume it is right—and that goes for speaker and listener alike.

    In contrast, when we force ourselves to articulate our thoughts in a language consisting of nothing but explicit unambiguous instructions, the conceptual gaps leap out.


    In a world where surface-level understanding is increasingly the domain of AI, we’re called upon to understand more deeply, not less.

    Coding offers a highly flexible medium for putting that to the test.

  • Using Calculus to Find the Area of a Triangle

    Nov. 1, 2026

    The area of a triangle can be found with (1/2) base ⋅ height, which makes sense because a right triangle is half of a rectangle with area base ⋅ height.

    Hopefully, that formula already seems intuitively clear.

    But we can also find the area of a triangle using calculus…

    I like to think of calculus as geometry for weird shapes, but it can also be used to find the area of commonplace shapes like squares, triangles, and circles.

    One way to think of integration is as a method of slicing up a shape into many thin strips, where the width of each strip approaches 0. In other words, you’re slicing the shape as thinly as possible.

    The area of each slice can then be approximated by a rectangle with a width approaching zero and a height determined from the dimensions of the original shape.

    The area of the shape can therefore be found by summing the areas of all these thin slices.

    For example, consider a triangle with base = 5 and height = 10. We know from the basic geometric formula that the area is (1/2) 5 ⋅ 10 = 25.

    If we “sliced” this into vertical strips, the leftmost strip would have a height of 0, and the rightmost strip would have a height of 10. If we summed the areas of all the vertical slices from height 0 to height 10 (i.e., from x = 0 to x = 5), the total would be 25.

    We can check whether our understanding of integration is correct using R code.

    There are multiple ways to do this, but I’m going to approximate the correct answer by literally slicing the triangle into many very thin strips.

    Specifically, I’m going to cut it into 50 million slices. (That’s a lot, but R does it in a split-second on my device.)

    > # Triangle Dimensions
    > base=5
    > height=10
    > # Standard Area Check
    > (area=base*height/2)
    [1] 25
    > # Specifying 50 million slices
    > slices=seq(0,5,1e-7)

    Now, how do we approximate the area of each slice? Each width has been defined as 1e-7 = .0000001.

    If we examine the triangle, we’ll notice that the height of each vertical strip is twice its position along the x-axis (i.e., the distance from the left end of the triangle). For example…

    1. When x = 0, the height is 0
    2. When x = 2.5, the height is 5
    3. When x = 5, the height is 10

    Another way of saying this is that the top edge of the triangle is a line described by y = 2x (the slope is 2).

    So, now let’s identify the height of each slice….

    > # Heights of slices
    > slice_heights=slices*2

    And then combine the heights and widths into areas of each slice…

    > # Areas = Heights * Widths
    > slice_areas=slice_heights * 1e-7

    And the last step is to sum the areas of these slices…

    > sum(slice_areas)
    [1] 25

    Note that we only get precisely 25 because R displays just 7 significant digits by default. If we instruct R to be more precise, we’ll see that the calculation is not quite 25…

    > # This is less precise than it seems...
    > print(sum(slice_areas),digits=15)
    [1] 25.0000005

    But the narrower the slices we use, the more the result will dial in on precisely 25.

    Okay. I think the concept has been demonstrated well enough.

    Clearly, there are much more rigorous ways to approach this kind of thing. And I’m sure that any actual mathematician reading this would fly into a rage at the imprecision in my explanations and demonstrations.

    But the point is we’ve written code to represent our understanding of the concept (integration), and this code accurately produced expected results to an acceptable degree of approximation.

    Next time, I’ll apply the same concept to show how we calculate these magical p-values that stats folks are always talking about…

  • Using Code to Represent Deeper Understanding

    Oct. 31, 2026

    I believe everyone should learn to code, because it allows for creating digital representations of the concepts that exist in our minds, and this allows for testing them for accuracy.

    In the previous post, however, I showed that a coded representation of an idea can still be incredibly shallow. In that example, I showed that creating custom R code for the arithmetic mean could simply reflect a basic formulaic understanding: “Add up the parts, divide by the number of parts.”

    A deeper level of understanding might involve realizing that the arithmetic mean is only one specific case of a set of general functions (e.g., geometric mean, harmonic mean, exponential mean)…

    For all these functions, there is some operation (e.g., addition, multiplication, etc.) conducted on each value in the distribution, and then they are aggregated in a way that shows what an “equal contribution” of each would be.

    For example, with the arithmetic mean, we are adding all the parts up. And the mean represents the single value that could replace every datapoint in the distribution while still summing to the same total as the original dataset. In this way, it’s a sort of “typical” score in an additive sense.

    Suppose we had 3 scores: (1, 2, 3)…

    • The arithmetic mean is (1 + 2 + 3)/3 = 2.
    • The sum of the original dataset is 1 + 2 + 3 = 6
    • If we replaced each value with the mean (2), we would get precisely the same sum: 2 + 2 + 2 = 6

    So this family of means (which is infinitely large) says: If you perform some operation on all the scores, then the mean will be the value that could replace each without changing the result of the operation. In other words, it shows what an “equal contribution” to the operation would be.

    If this understanding is correct, then we should be able to write a function in R (or whatever programming language you prefer) that takes as its inputs (1) a set of scores and (2) the operation being performed, and then produces the resulting mean.

    Let’s take 4 examples from this family of means…

    1. Arithmetic Mean = Σx/n (Operation: Addition)
    2. Geometric Mean = ⁿ√(Πx) (Operation: Multiplication)
    3. Harmonic Mean = n / Σ(1/x) (Operation: Addition of reciprocals)
    4. Quadratic Mean = √(Σx²/n) (Operation: Addition of squares)

    Pulling this off successfully will require understanding a more general algorithm that binds all these (and all others in this family) together…

    Geometric Mean

    When each value in a set is multiplied, the arithmetic mean produces misleading results.

    Example: Suppose you invest $100. If your return in the first year is +30% (i.e., 130% of original) and then your return in the second year is -30% (i.e., 70% of Year 1), then what is the average growth?

    The arithmetic mean would seem to suggest 0% growth…

    • Σx/n = (1.30 + (.70)) / 2 = 1
      • (In this case, 1 means 100% of the original, so zero return overall)

    But this is obviously incorrect if we check step-by-step…

    1. Year 1: $100 ⋅ 1.30 = $130
    2. Year 2: $130 ⋅ .70 = $91

    We’ve lost $9…so clearly it’s not 0% growth.

    The better solution is the geometric mean, which gives the typical multiplicative value…

    • ⁿ√(Πx) = ²√(1.30 ⋅ .70) ≈ .9539

    We could replace each year’s return with this value and then get the correct ending value…

    1. Year 1: $100 ⋅ .9539 = $95.39
    2. Year 2: $95.39 ⋅ .9539 ≈ $91

    So what’s the link between the arithmetic mean and the geometric mean?

    Well, the real question is, “What’s the link between addition and multiplication?” And the answer is logarithms.

    Specifically, log(a·b) = log(a) + log(b).

    This means that if we first take the log of each value, we can proceed to use the ordinary arithmetic mean…

    • [ln(1.3) + ln(.7)] / 2 ≈ -0.0472

    …then exponentiate (i.e., return to original units) to get the correct answer!

    • e^-0.0472 ≈ .9539

    This is the same result we got when using the geometric mean formula.

    Harmonic Mean

    When working with reciprocals, the ordinary arithmetic mean again fails…

    Example: If you drive at 50 mph on the way to your destination, then you drive back at 40 mph, then what was your average speed?

    It may seem intuitively clear that the answer is 45 mph (the midpoint between 40 and 50). That value is the arithmetic mean… and it is WRONG.

    That calculation would only work if you traveled for the same time units each time (e.g., 50 mph for 1 hour and then 40 mph for 1 hour).

    But you were traveling 10 mph faster on the way to the destination, so it did NOT take you the same amount of time each way.

    The real solution is the harmonic mean, which expresses the calculation in terms of the thing that is constant (i.e., distance to and from the destination). It’s as simple as flipping the miles / hour fraction…

    • (1/50 + 1/40) / 2 = .0225 hours per mile (hpm?)

    …then taking the reciprocal to put it back in the original units…

    • 1 / .0225 ≈ 44.44 mph

    Quadratic Mean

    When working with square units (e.g., tiles on a bathroom floor), the naive arithmetic mean again fails…

    Example: Suppose you’ve got 100 tiles to cover the floor of a room. Half are 6 inches across, and half are 8 across. What’s the average coverage of a given tile? And how much area will this cover?

    It might be tempting to just think, “Well the average tile is 7 inches across (i.e., the arithmetic mean of 6 and 8), so that’s 7² = 49 sq in. Multiply times 100 tiles to get 4,900 sq in.”

    Wrong, wrong, wrong…

    The 6″ tiles have area 6² = 36 sq in, and the 8″ tiles have area 8² = 64 sq in. The arithmetic mean is (36 + 64) / 2 = 50 sq in. And that multiplied times 100 tiles is 5,000 sq in.

    The quadratic mean, √(Σx²/n), handles this correctly. First, calculate the mean of the squares…

    • Σx²/n = [50⋅6² + 50⋅8²] / 100 = 50 sq in

    …And then we can take the square root to convert back to original units (inches rather than square inches)…

    • √50 ≈ 7.07107 in

    The average tile’s side length is 7″… but that does not accurately reflect the total tile area!

    (By the way, I’ve never laid tile before, so I don’t know if being off by this factor would be a serious problem or not. But I personally would want the correct calculation.)

    Quasi-Arithmetic Mean

    In case you haven’t noticed it yet, the general process is…

    1. Transform the scores
    2. Calculate the arithmetic mean: Σx/n
    3. Transform the scores back into original units (inverse transformation)

    The general form of this process is called the quasi-arithmetic mean…

    • Mean = f ⁻¹ [Σf(x) / n]

    (This formula is nothing new. It’s just expressing that 3-step process above using mathematical notation.)

    The transformation (f) could be taking the logarithm (for the geometric mean), taking the reciprocal (for the harmonic mean), taking the square (for the quadratic mean), and so on.

    Transform, calculate the arithmetic mean, then transform back to original units.


    Finally, we’re ready to write R code that takes any set of scores as input, along with a specification regarding the type of operation conducted, and that then spits out the resulting mean (whether arithmetic, geometric, harmonic, or whatever).

    Here’s a version where each step is explicitly laid out…

    > # Custom Mean Function
    > generalized_mean=function(data,transformation,inverse) {
    + t_data=transformation(data) # Transformation
    + m_t_data=sum(t_data)/length(t_data) # Arithmetic mean calculation
    + result=inverse(m_t_data) # Inverse transformation
    + return(result)
    + }
    > # Example 1: Arithmetic Mean
    > x1=1:3
    > generalized_mean(x1,identity,identity)
    [1] 2
    > # Example 2: Geometric Mean
    > x2=c(1.3,.7)
    > generalized_mean(x2,log,exp)
    [1] 0.9539392
    > # Example 3: Harmonic Mean
    > x3=c(50,40)
    > generalized_mean(x3,function(x) 1/x, function(x) 1/x)
    [1] 44.44444
    > # Example 4: Quadratic Mean
    > x4=c(rep(6,50),rep(8,50))
    > generalized_mean(x4,function(x) x^2, sqrt)
    [1] 7.071068

    All the results match our above calculations.

    But we can make it WAY cleaner by collapsing the function into a single line representing f ⁻¹ [Σf(x) / n]…

    > # Cleaner Generalized Mean Code
    > gen_mean_clean=function(x,f,inv_f) {inv_f(mean(f(x)))}
    > # Arithmetic
    > gen_mean_clean(x1,identity,identity)
    [1] 2
    > # Geometric
    > gen_mean_clean(x2,log,exp)
    [1] 0.9539392
    > # Harmonic
    > gen_mean_clean(x3,function(x) 1/x, function(x) 1/x)
    [1] 44.44444
    > # Quadratic
    > gen_mean_clean(x4,function(x) x^2, sqrt)
    [1] 7.071068

    If we check our work using the standard formulas, we get the exact same answers…

    > # Checking our work...
    > mean(x1)
    [1] 2
    > prod(x2)^(1/length(x2))
    [1] 0.9539392
    > length(x3)/sum(1/x3)
    [1] 44.44444
    > sqrt(sum(x4^2)/length(x4))
    [1] 7.071068

    In each of the 4 cases, the mean finds the value that would constitute an “equal contribution” to some result, namely…

    1. The sum of scores for the arithmetic mean
    2. The product of scores (i.e., sum of log-scores) for the geometric mean
    3. The sum of reciprocals (e.g., total time) for the harmonic mean
    4. The sum of squares (e.g., total area) for the quadratic mean

    If we can follow all of that, then I think it’s safe to say we have fairly deep understanding of the concept of the mean.

  • 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…

  • Everyone Should Learn to Code (Even in the AI Era)

    Oct. 28, 2026

    I believe that every person should learn to code, at least at a basic level.

    Even if one’s job does not involve computers.

    Even now, in the mid-2020s, when LLMs are about 200 million times better at coding than humans (at least, in terms of speed and accuracy of basic coding tasks).

    In fact, it might be more important now than ever.

    Obviously, it’s not a moral imperative or a necessity to survive or anything like that.

    But I do think everyone ought to learn to code in the same way that everyone ought to eat vegetables.

    In the past, a lot of people made similar arguments on the basis of employability, although I don’t know anyone currently doing that.

    Incidentally, I do think coding could help you get a job in the modern era, but only in the same sense that learning to do math, to write, to speak multiple natural languages, etc., could help in a sort of diffuse way.

    It’s not necessarily about employing the skill as part of your work tasks; it’s about understanding more of how the world works.

    More generally, it’s about learning to think better.

    That’s something we all need, and not just in our work lives.

    I’m aware that many others have previously argued for this same conclusion. Often, their arguments relate to how learning to code makes you more well-rounded, improves your logic and problem-solving abilities, etc.

    To be clear, I agree with all of that.

    For example, learning to code is analogous to learning a new language. (In one sense, that’s LITERALLY what it is.)

    I know I would be a more effective person in general if I could speak multiple human languages fluently. I would be able to do more in the world, and I would understand more of what I experienced.

    It’s not a moral imperative on those grounds, but it would definitely be good for me.

    But my core argument for why everyone should learn to code is different…

    I believe everyone should learn to code because coding offers a highly flexible way to create digital representations of concepts, which allows us to test or demonstrate that we have established deep understanding.

    I previously argued that much of human learning is shallow.

    This isn’t because we’re lazy, though; it’s because our brains are ruthlessly efficient…

    And the most efficient way to learn is to seek minimum viable understanding—that is, just deep enough that (1) the concepts hold together in our minds, and (2) we can apply the knowledge successfully most of the time (or enough of the time).

    Although I’ve given multiple examples of what I mean by shallow vs. deep understanding (e.g., here, here, and here), I haven’t clearly articulated a definition of deep understanding, at least not beyond suggesting it’s something more than shallow understanding.

    I know others have used this term before, but here’s what I mean…

    Deep understanding involves developing a sophisticated mental model of a concept or subject, including…

    • Intuitive, even visual, representations of concepts in one’s mind.
    • Multidimensionality—concepts can be described in multiple, complementary ways.
    • Coherence of related concepts in a semantic web, including causal chains.
    • Independence from textbook definitions or other external sources or explanations.

    I think the last bullet is the linchpin in all this.

    Having a mental representation of a concept that exists separately from the sequence of keywords in the textbook definition is what enables behaviors like:

    • Writing your own definition of a term
    • Explaining a concept in your own words
    • Solving novel problems without relying on flowcharts or decision rules
    • Making judgments without relying on heuristics or checklists
    • Running mental simulations
    • Making predictions

    I think the main limitation of my explanation is the “mental model” or “mental representation” part. Terms like these are popular and useful in psychology, but they’re difficult to explain or define.

    It’s also hard to know exactly how solid a mental model is without creating some substantial version of it.

    That’s why we need to instantiate our ideas with physical models, verbal explanations, digital representations, etc. If the material version functions correctly, that’s a good sign that the mental representation is on target as well!

    And that’s why I think everyone should learn to code: We can use code to create digital representations of our mental models, and those can be directly tested.

    Critically, this only works if the code is built “from scratch,” directly based on one’s own mental model.

    As I’ll demonstrate in subsequent posts, computer programs are ideal ways to check whether things work or not (e.g., code either runs or breaks; output is either correct or incorrect). I also find them more flexible and convenient than other types of instantiations, but maybe that’s personal preference.

    Anyway, this post is getting too long, so I’m stopping here. I’ll start exploring examples tomorrow.

  • Choosing an Data Analysis Software

    Sept. 20, 2026

    Question: How should I choose a statistical analysis software?

    The answer depends on various factors like…

    • What you’re using it for
    • In what context
    • How technical you want to get (e.g., coding?)
    • Whether you want a free or paid platform

    I have a YouTube video breaking down similarities and differences among MS Excel, IBM SPSS, and R/RStudio in terms of these factors.

  • Vibe-Coding in R and RStudio

    Sept. 19, 2026 | VIBE-CODING PT. 3

    Question: What is vibe coding, and how do you do it?

    Check out this YouTube video where I demonstrate 3 ways to vibe-code in R and RStudio:

    1. Going back-and-forth between RStudio and a chatbot (old school at this point)
    2. Inline autocomplete using Posit AI
    3. Posit Assistance chat interface inside RStudio

    Have fun with it!

    Remember that if you don’t actually understand coding or statistics, then the results might be nonsensical =)