Programming Is All About Logic

Why it can be used to develop and assess a person’s logical ability

Curt Corginia
6 min readSep 16, 2022
Photo by Sigmund on Unsplash. I was not legally permitted to use a screenshot of the famous “is she a witch?” scene, so I had to use a picture of glasses on a chart I can’t read.

That “programming is all about logic” is not a controversial claim — its use of “AND statements” and “OR statements” can be traced to propositional logic, and the concept of for loops is best explained to new students with logical flowcharts. What I want to argue in this post, instead, is that programming has great educational value and that even if programming did not have the same practical applications, it would still be useful for teaching, assessing, and developing a person’s logical abilities.

A middle school math teacher might argue that algebra is important, even to those who have no intention of using anything beyond simple arithmetic in their careers, because math at this level helps a student with logical and problem-solving abilities. Programming is like this, but with an addition: You have the ability to run your programs and validate whether or not your logic works as intended.

Before turning this into something that tries to be too academic, I thought I’d share a summary of my argument with Smack on the topic:

  • He agreed that programming is heavily reliant on logic, but we disagreed on the implications
  • He argued that logic varies quite a bit between disciplines. Smack is not great at math but quite good at programming, for example. Though I agree, I believe that programming is at least as relevant as math. To get a high school diploma, we require students to learn algebra, precalculus, and either statistics or calculus. At the very least, I think programming could be a good substitute for some of these classes
  • He argued that programming is not “pure logic.” I agree — to be a good programmer you also have to memorize some things, formulate good search queries in Google, and explain to a LinkedIn recruiter that Java and JavaScript are not the same thing. Programming is about more than just logic, but that does not invalidate the point

A Surface-Level Look At Logic

I want to focus on propositional logic in this article — we first learned it in 9th grade, and it uses familiar concepts like modus ponens and modus tollens…terms I admittedly just had to look up to make sure I hadn’t misspelled them. That was a great math class because, among other things, it was the first time we really learned how to PROVE things.

My 9th grade math teacher made this website, which we used to get extra credit by writing geometric proofs. It was a great resource back then, but I recently tried replaying it and…in the age of modern frontend web development, I just don’t think it holds up. Easy and even some medium problems can be solved with simple process of elimination. I spent a solid six hours on Water Hazard before consulting a YouTube walkthrough. The health pack placement is kind of random, Ravenholm isn’t nearly as good with its old graphics, and where is ProveIt 3.0? All we got was ProveIt Alyx instead, which gets roughly 30 seconds further into the story.

What were we talking about, again? Oh yeah, propositional logic. As a winter break extra credit assignment, we were asked to formally prove the witch scene in Monty Python And The Holy Grail. To the uninitiated, they reason that a woman is a witch because she weighs the same as a duck, therefore she must float…and would also floats, and wood burns, therefore she is a witch because witches burn.

I probably botched that explanation. Here’s a formal proof sponsored by the University of Waterloo, including an application of Modus Ponens. You don’t have to look too hard to poke holes in this line of reasoning, or you could just accept the proof 100% and counter that obviously the scale was not properly built…but someone at the French Institute of Mines actually bothered to make a formal counter-proof.

Reviewing propositional logic has been interesting, and there’s quite a bit of free content available online on the subject. This, for example, is 52 textbook pages published under Harvey Mudd College.

From early on, computers have been known as “logic machines”. Indeed, “logic” plays a central role in the design, programming, and use of computers. Generally, “logic” suggests a system for reasoning. But in computer science, reasoning is only one use of logic. We also use logic in a fairly mechanistic way in the basic construction of computers. This form of logic is called “proposition logic”, “switching logic”, or sometimes (not quite correctly) “Boolean algebra”. There are also several other, much more powerful, types of logic that are used in other aspects of computer science
Source

“Who Cares?”

Logic, then, is like the very DNA of programming. Computers themselves are logic machines, and software engineers can utilize unit tests to objectively evaluate features.

Coding is useful, as a skill set, to children. It allows them to formalize goals, break down problems, and test their solutions. To be a good programmer, there is some degree of continued learning required — maybe a programmer has to stay up-to-date with new libraries, or new framework updates. But the ability to think logically about a problem, research effectively, and implement a working solution is something that goes beyond rote memorization. Furthermore, this is a useful skill to take outside of the computers.

More than a few people on Quora have asked why we like programming. The responses tend to relate to power and application — they say that they like building things, or maybe “being the god of a machine.” Though this is certainly a part of what makes programming enjoyable for some people, I think it only tells half of the story.

Why not be a writer, or a painter, or someone who engineers houses? Programmers have a desire to build, sure, but while carpenters can use wood and artists can use paint, programmers use logic as the building blocks of their creations. They create functions with intended inputs and outputs. They define statements that do one thing in one situation, and specify what to do when said criteria is not met. Should anything go wrong, programmers are responsible for the consequences. They can make alternative solutions, they can re-design and even delay, but they are still bound by the rules of their languages and associated implementations.

All of this to say: Logic matters, and it’s useful, and coding can help with all that.

Closing Thoughts

The last thing I talked to Smack about was comparing coding to a puzzle. I disagree with the analogy; he thinks it’s a great one. When you solve a puzzle, it’s something someone has made to be solved. When you’re solving a coding problem, sometimes things just can’t feasibly be done in the time expected because there was an unexpected complication. Tools are created with intended use cases. You, whether you’re building some small personal project or a large project for a corporation, are probably deviating somewhat from the intended use cases. You start to mix things in ways that have never really been done before. Maybe you’re just customizing size, or tweaking color scheme, or maybe you’re doing something very elaborate like combining two things that have a very different concept of what constitutes an event, or how lifecycle should work. Things get increasingly complicated, and you have to kind of swim atop the complexity.

Now we’re facing coding interviews all over again, and that’s its own thing.

Are coding interviews a good assessment of logical/problem-solving ability? They certainly can be. The question, in the days of LeetCode and CTCI and a million Grokking classes, is whether coding interviews are really fair assessments of how we think, or just a matter of who has memorized the most things.

I thought it would be way more fun by closing out with a discussion of Chess. I like Chess a lot. Logic is a huge factor, but at least at my level (ie not extremely high) I think emotion is a huge factor. You’re actively competing with another person, and you set traps, take risks, and make threats knowing that you’re competing with another person. I can’t put it into words, and I don’t know if I imagine it, but I think I can really tell when it’s a human on the other side. When I play against a computer, even a low-level one, the way they react is just different. Instead of following the same line of reasoning a 1400 player would make, with slight hiccups, or sometimes a certain lack of vision, a 1400 computer will play perfectly, then hang some piece, then play perfectly again.

Logic is really, really important to programming, and logic is already really, really important to chess, but it’s not like logic is the single factor.

--

--

Curt Corginia

Founder, CEO, CTO, COO, and janitor at a company I made up called CORGICorporation