How much math do I need to know to program?
I just got this question in a DM on Discord:
How important is the math section in your book? I’ve always been bad at math, so I’m wondering if I could maybe skip it.
Or I’ve seen this question asked a few times in Discord as well:
I’m not good at math. How much do I really need to know to be a programmer?
I’ll start with a short answer and then elaborate.
TL;DR: You don’t need to know a ton of math. The two things you’ll do a lot of is basic arithmetic (add, subtract, multiply, divide) and updating variables over time. If you can handle those two things, you’ll be okay.
Finding uses for math
Math is one of those things where if you know how to do it, you’ll find places to use it. In that sense, it is much like knowing how to play a musical instrument, draw, or speak a foreign language. (I’m reminded of the XKCD comic with the caption “It’s weird how proud people are of not learning math when the same arguments apply to learning to play music, cook, or speak a foreign language,” and in the hover text, it adds, “All the fun parts in life are optional.”)
I’ll add that programmers, as a group, tend to have more affinity for math than the general population, because it is so analytical. But I’ve also known some very good programmers that just didn’t like math. You need to know a little, but you can still be a good programmer if you don’t love math.
Not knowing much math or not enjoying math will take away at least some options, though a similar thing could be said about many things. For example, the place I work now uses quite a bit of geometry. Given two otherwise equal candidates, but where one knows math and the other doesn’t, we’d have a clear reason to pick the one who knows and likes doing math.
Similarly, game programming often hits on math in some surprising ways. (Though this depends on the type of game you are making, as well as how well your chosen game engine hides the lower-level math details from you.)
There are lots and lots of programming or software engineering jobs out there where math plays a very minimal role. So if you aren’t friends with math, there are plenty of other options for you out there.
Seeing math through a programming lens
I was a math tutor for many years in college. I worked with a lot of people who just didn’t like or really struggled with math.
One reason I’ve repeatedly seen that pushes people away from math is that they often just don’t see how to apply it. Math is often presented as this almost sterile thing that you do on paper, detached from the real world. Which is why you hear the refrain, “When are we ever going to have to use this stuff?”
But in contrast, in the programming world, when you bump into something that needs math, it is usually very hands-on. The purpose is self-evident, which, for many, makes it far easier to spend time working on it and push through some hurdles. Knowing that the math will solve a specific problem right in front of you makes your patience and tolerance higher, so encountering math in a programming context may actually help you like math more and find a bit more joy (or a bit less terror) in it.
Story time: I remember when I first realized the power of my new programmable graphing calculator. I realized, “Hm… if I make a program that can do the quadratic equation, I won’t ever have to compute that by hand ever again! And even if I have to show my work on the test, I’ll be able to check it and be certain I got the right answer!” That provided a mountain of motivation to work on it.
In fairness, I’ve always really liked math, so the example may not work quite as well if you’re one of those struggling.
Still, the amount of math you need to know to survive in programming is relatively small. It isn’t zero, but it isn’t huge either. The programmers that I’ve known that don’t love math will simply find somebody to pair program with them when they’re doing math that they are uncertain about, which is a good practice anytime you feel out of your depth, regardless of if that is math or something else.
What is the least amount of math you can get away with in the book?
Let’s get back to the book.
Can you skip the Math chapter and be okay?
I hesitate to say “yes” to that.
But let’s get more specific about the parts you need to know well enough to use, the parts you need to merely be aware of, and the handful of parts you can consider skipping.
I’ll go through it section-by-section in 5th Edition, but 4th Edition should be nearly identical. 3rd Edition and earlier split this into two chapters, but the two chapters cover the same general material.
This is for the people that just really don’t get along with math. If you like math, then I think you’ll want to fully engage with the math chapter as much as you can, because you’ll find it useful. This is about how much you can get away with if math isn’t your thing.
- You do need to understand the fundamental concepts of what an operator is, as well as how they can be used in expressions.
This shouldn’t be too complicated.
It is really just the idea that you can write something like
3 + 10
or10 - 5
or referencing variables and doing something like3 * x + 5
to compute a new value. - You do need to know the four most fundamental operators:
+
,-
,*
, and/
to do addition, subtraction, multiplication, and division. - The material that covers compound expressions and order of operations is something that you could go light on if you don’t love math. If you don’t do too much math, you won’t end up with too many uber complex equations, and even if you do, you can chop them up across multiple lines. You should read this section, but you don’t need to master it.
- I highly recommend doing the Triangle Farmer challenge. This is the level of math that is commonplace in programming. If you look at it closely, there is really only maybe one or two lines of math code–just enough to compute the area of the triangle–and the rest is simple inputs and outputs. If you’re able to complete this, you should be in decent shape. That makes it a good measure of your skills, so definitely take the time to work through this. There are still important things after this challenge, but you’ve covered about 80% of the most essential stuff if you can make it through this one.
- Special Number Values. This section I think is worth reading, but not one you need to master.
- Integer Division vs. Floating Point Division. This discusses some important differences in the way division works for integers vs. floating-point types. It’s important to know, but if you just stick with floating-point types like
float
anddouble
, you probably won’t have too many surprises, and could skim this. - Division by Zero. I’d suggest reading this, but you’re probably already at least familiar with the trope about how dividing by zero does bad things, which is the key takeaway from this section.
- More Operators. This section covers two main things: that you can use
-
to negate a value (make a negative number positive or a positive number negative) and%
, which computes remainders.%
is often used to determine if something is a multiple of something else, which has a lot of uses. In particular, you’ll want to pay attention to how it is used to see if a number is even or odd (x % 2 == 0
) because that type of thing is surprisingly common in programming. - The Four Sisters and the Duckbear challenge is worth the attempt. It will use
%
. If math really isn’t your thing and you struggle with this one, it will probably be okay. The Triangle Farmer is a more typical example. But I’d still suggest giving the Duckbear challenge a shot, even if you set a timer and give yourself the chance to stop working on it after 30 minutes or something. (And maybe you can share what you did or what roadblock you got stuck on in #ask-a-question or #challenge-help on Discord.) If you don’t solve this one on your own, it will be fine. - Updating Variables. This section is worth understanding. You don’t have to do too much math, but you’ll need to update a lot of variables (memory locations). In particular, pay attention to
++
and--
, which add one and subtract one from a variable location. That is used a ton in programming. - I also recommend doing the Dominion of Kings challenge. It shows an example of a program that uses some basic math to solve a real-world problem. (This is actually a score calculator for the card game Dominion, if you’ve ever played that. There’s a reason the challenge is named what it is.) Again, the amount of math is not crazy. It is some basic arithmetic and working with some variables.
- You can skip the “Prefix and Postfix Increment and Decrement Operators” section. It’s a side quest and doesn’t get a ton of use. It is safe to skip.
- Working with Different Types and Casting. This section, I recommend reading or skimming. You don’t need to master it. The main point is that types can’t just be intermixed. If you want to change some value from one type to another, you’ll need to convert it somehow. Some conversions are applied by the compiler automatically, others must be called out by the programmer with a cast. Yet others need to be done by calling a method, like the
Convert
methods in the subsequent chapter. But you definitely don’t need to memorize it all. - Overflow and Roundoff Error. If math isn’t your thing, it might be okay to just skim this section.
- The
Math
andMathF
Classes. The main thing here is that you just need to be aware that there’s a class that does a lot of the common math things for you. You don’t need to memorize or understand things like absolute value, square roots, or the trig functions.
That makes for a very long list, so let me try to condense it:
- Even if math isn’t your thing, you will still need to be able to do some basic arithmetic and work with variables. (Note that variables in C# are named places to store data, which is a bit different from math, where they are used to represent an unknown quantity or to define relationships between things in equations.)
- I recommend reading through most of the chapter, even if you struggle with math. You don’t need to master it all, but being aware of what’s out there will help you down the line.
- You should still attempt the three challenges. If you only succeed at one or two of them, you should still be fine. But set a timer and give it a serious try for a little bit, even if you don’t end up completing the whole thing. The attempt will still help you grow a ton.
Lastly, you can program without being great at or loving math, and you will never _need_ to be a math wizard to be a great programmer, but also give math another chance, now that you’re approaching it from the programming side.