Coding Shouldn’t Be Scary
Hello there brave reader. There are going to be a lot of questions on the coming post, but I want to start off with a simple one: have you ever written a program before? If no, then this post is for you. Don’t worry, it’s not a sales pitch, or anything close to a tutorial. There is no need to be afraid! No technical material will follow, I promise. In fact, this post, while still about programming, is just about the opposite of technical.
When people think about ‘computer programming’ a few images seem to come to mind. A screen glowing with a wall of undecipherable text. Some lanky coffee-addled guy holding his head as he stares at it. In fact, at the time of writing this, out of the first 15 images shown by a Google Image search of ‘Computer Programming’, 14 of them are stylized pictures of either source code or binary (ones and zeros). Doing the same with the term ‘Computer Programmer’ and filtering out the pictures without any people in them, of the first 36 images, 31 are of a Caucasian male sitting at a desk (I went to 36 so that I could include a picture of Tony Stark in that statistic).
I want to try a little exercise. Look at the following image, and ask yourself what you’d need to do to replicate it in your favourite text editor:
Was your answer: “A lot of memorization?”
Learning to program is not about memorizing programming languages
When we write a program, we need a formal way to tell the computer what we want it to do. The history of this is interesting, but I promised no technical things, so I will simply say that we developed programming languages to do this. Java, C, Python, you have probably heard of some. However, contrary to what Google Images, and popular opinion, would lead you to believe, the important part of being a programmer isn’t memorizing a whole lot of these.
For the sake of curiosity, the code in the picture gets a computer to tell you if one piece of text is contained within another. It is not a hard problem, but if you gathered all the programmers you knew and asked them all to write code to solve the exact same problem, chances are you’d get as many different solutions as you had programmers. Why? Because it’s like asking someone to describe a picture you show them, or to prove some theorem. It is not about finding the one, exact solution, it’s about taking the tools at your disposal and figuring out how to solve a problem with them.
Programming is a creative process
Yes, you need to know what the tools are and how they work, and in the case of coding that usually means a programming language. But once you sit down to write an honest-to-goodness program, your task isn’t to blindly repeat a bunch of lines of code you memorized earlier. It is about looking at the for-loops and if-blocks and everything you’ve learned about, and asking yourself “How do I use these little pieces to create the thing I want.”
This was a revelation for me when I first learned to code. I spent time reading books on Python and Java, and dreaded having to remember it all, word for word, when the time came that there was a problem I really needed to solve. But when that time came, it wasn’t like writing a history exam, filling in blanks on some big form I’d had to remember by rote. The feeling was exactly the same as deciding what chords to play to make a song sound like it did on a record, or what words to use so that a reader would see the exact image in their mind’s eye that I did, or even how to take the math I had learned in school and prove that Pythagoras was right (though that one doesn’t come up all that often, admittedly).
I will say it again: programming is about being creative. It is about taking a problem, and coming up with the best solution you can. I won’t say “there are no right and wrong answers”, because there are. If you wanted to calculate pi to a thousand digits, my code up there would be dead wrong. But there are many right answers. More than any one person could possibly imagine. A programmer’s job isn’t to type out the solution to a problem, it’s to be clever enough to figure out one of the many solutions, the best one they can find and make work.
Want to see another way to do exactly the same thing as the code above?
Couldn’t get more different. A lot simpler, definitely, but the important part is that both solutions are correct.
Seriously, open up whatever app store you have on your phone. All of those programs you can download: probably not ridiculously complex. They aren’t the product of someone throwing their life into learning how cell phone software works. They are usually just the result of someone saying “I wonder how I could get my phone do do something new…”
What I am trying to get at is: when you think about programming, don’t think about memorization, think about problem solving.
Still intimidated? That’s fine. While I’m at it, let me share one more secret:
Programmers have a hard time reading code too
This is a bit open to interpretation, but what I mean say is: when a programmer looks at a block of code, what it does is not immediately clear to them either, in most cases. When we say “I know the programming language Java” it is not like saying that we know English or French or Spanish. When you look at something in a spoken language you are fluent in, the message is immediately clear (assuming it is not just gibberish). That is because spoken languages are made for people to understand. Programs are made for computers to understand.
Don’t believe me? Any programmer worth their salt does something called commenting. Comments are little messages in code put there so that anyone can follow the code’s logic. Reading uncommented code is a nightmare for even the best of us.
Here is what my code from above looks like without the comments removed:
A good bit longer, but significantly more readable. Now, don’t get me wrong: this code isn’t particularly complex, and even without the comments most Java programmers could probably figure out what it did given a couple of minutes. But they would spend that whole time thinking “Man, I really hate the guy who did not comment this code of his.”
It is a standard in the field because, even for those of us who spend time doing this sort of thing, a screen full of source code can be intimidating if there is no English commenting interspersed to explain what it does.
The point? Don’t worry if having to look at a bunch of code worries you; it worries the best of us. All that blue text in the above image does nothing, literally nothing, from the computer’s perspective. Comments exist in every well written piece of software you use, because even the people who write programs know how confusing their own code can be.
What I am trying to say is this: the stereotypical view of coding, as some horribly complex, inaccessible task, is not what programming is all about. All too often, when I pull some sourcecode up on my laptop screen in public, someone looks over my shoulder and says “Oh, I could never do that.” The problem is: they can. It isn’t about knowing what every single possible line of code does. It is about ingenuity and creativity.
I could go on, and I will in a future post, but for right now, I will end off with this: if you like problem solving, if like being able to come up with your own solution to a problem, instead of just replaying one that has already been developed, if you like the idea of being able to tell your computer what to do, and understanding why it is doing it, I encourage you to try programming. The online resources to get you started are near limitless.
And, if you don’t want to have to worry about semicolons and tabs, or even lines of text, the resource I recommend to you is Waterbear. It allows you to code with blocks, instead of with words, and we, the Waterbear team, are constantly working to make it a more effective and intuitive learning tool. Go, see what you can make it do. See if you can use it to write your name, or to draw a picture, or to solve some math problem. Whatever you like. The important part, cliché as it sounds, is that you enjoy yourself. Because, unlike memorization, or staring blankly at a computer screen, programming should be fun.
—-Jarrett