~teddy $ sudol writes/

home

My Introduction to Programming

27 Sep 2012

Someone on my Formspring asked: “How did you get into programming, and what advice would you give to the person who wants to develop skills in that area?” I started a reply, but it turned into a 1500-word monstronsity. I decided to write a blog post about this topic instead.

I feel that I should start off with a disclaimer: Programming is one of those things where either you can do it, and do it well, and enjoy it, or you can’t do it at all. Give it a few tries, see if it clicks. If it doesn’t….well, keep trying, really. It might just click. But it might not. Check out this article for a small discussion on the topic.

I entered the world of programming with a motivation that, in retrospect (and at the time, really) seemed rather asinine: I wasn’t nerdy enough. I didn’t play D&D, I didn’t have a pocket protector, I wasn’t a major math wiz… so I needed to do SOMETHING to get my nerd cred up. This particular train of thought arose near the end of the 8th grade. Scheduling for my freshman year of high school was coming up, and one of the courses offered was Introduction to Visual Basic (or something like that), which was the first part of a 4-class, 3-year Computer Programming track. I decided it would be pretty interesting to check it out, and hey, nerd cred!

Of course, that wasn’t my only motivation. Intellectual curiosity was also a factor. I will admit that computers had been little more than gaming consoles or big toys for me. I knew, vaguely, that there were people who created the games that I played, and that part of that creation was programming. Hell, I don’t think I even made the connection that my GameBoy was also a computer! Talking about video games, the Visual Basic (henceforth “VB”) course came with a warning from my guidance counselor: “This isn’t a course about playing video games,” she admonished, “but I don’t think I need to worry about that with you.”

Forward to my freshman year of high school, or more specifically, the Intro to VB class. The teacher was Ms. Bamford, a wonderful lady who communicated a passion for programming. It’s all her fault, really, that I’m hooked. I’m not sure if I’d still be doing this if I had a bad teacher. I definitely wouldn’t be any good at it. So there’s Tip #1: Find a good teacher. We spent the semester learning not VB specifically but the basics of programming itself. There are certain structures and ideas that permeate all programming languages: Conditional statements, Loops, Functions… these, once you master them, become not so much parts of your programming toolbox but fundamental units for breaking down a problem. Perhaps that’s Tip #2: Learn not just a programming language, but the underlying concepts that lead to that language, which tie programming together. (Later you will learn that some of the things that seem essential and basic aren’t. But that’s not for years afterward.)

The first VB course was followed in the spring semester by Advanced VB, or something along those lines. It was just a continuation of the previous semester’s work but with larger, more complex programs in mind. It became more about the language itself. To be honest, I don’t recall much of this class, or much of Visual Basic itself! It’s not what I’d call a good language, though it’s not a bad one. It’s just…there are better languages out there. More fun ones, certainly. It might last just because of its niche in education. Visual Basic, as the name suggests, centers around using forms and graphics to render the output of a program. To a beginning programmer this can be much, much easier to see and understand than the normal command line output used in almost every other language.

(Sometimes I wonder if the aspect of control is what hooked me in programming. I was entering the throes of Teenage Angst, compounded by my questions about my sexuality. I recall trying to figure out why I wasn’t attracted to girls the way it seemed in books: Head-over-heels, foolishly, slavishly lusting after them. (Ok, it’s never that extreme, but you get my point, yes?) I think that repression, even if it wasn’t as major as some people suffer through, adversely affected me. It doesn’t help that sometimes I really do feel like I’m half-robot… Tip #0: Of all the people in the world, never, EVER lie to yourself.)

Sophomore year brought a new, year-long programming course and a new language: C++. Visual Basic is to C++ what water pistols are to howitzers. Visual Basic felt like a toy, but C++ was a tool, and a powerful one at that. The class also introduced the prime programming methodology of today: Object Oriented Programming. OOP, as it is known, is the result of computer programming transforming from a purely mathematical activity to a general-purpose industry with real-world applications. Programmers looked at the world and said, “How do I represent these things in a computer program?” The answer was objects. Objects are…nouns, really. Take a car, for instance. If you were to define a Car object, you’d say it’s a thing with 4 wheels, an engine, and a steering apparatus. There’s a really simple, basic object that can be used in a program to, say, calculate the wear on tires. Programmers use OOP to model the real world inside their programs. OOP is a “programming paradigm”, or a method for designing a program. It’s not the first one, nor the last, but it is the most well known. Before OOP, most programs were “imperative” or “procedural”. That is, the programmer wrote a list of instructions that the computer would follow to produce a desired output. With OOP, defining the objects and how they interact with each other becomes a large chunk of the program. There are many programming paradigms, but the big 3 are Imperative/Procedural, OOP, and Functional. I shan’t talk about them too much more, as it is a complex, deep and constantly changing topic. By the way, VB is essentially an OOP language, but that wasn’t really talked about in class.

This class was where the real programming began. We were given freer rein to play and experiment with our programs. Discovering cool ways to break the program was a fun activity. For example, one of our exercises was to create a program that would print out a diamond using “” characters. Experimenting with that simple program went in 2 directions. One was “practical”, such as allowing the user to choose a different character that “” to use in the diamonds. The other was “experimental”. The experiments resulted in programs that would print abstract designs instead of diamonds, or would loop infinitely and would make a kind of “snow” on the output window. (These were all diamonds, just ones spread out beyond all recognition.) Tip #3: Programming is and should be fun. Experiment. Explore. Examine. Go above and beyond the basic assignment or goal, even if it’s just for your own satisfaction.

C++ is a rather fascinating and occasionally disturbingly messy language. It is a strict and occasionally cruel mistress, but boy do you learn how to program. VB will hold your hand, or at least be a little helpful. With C++, you learn to catch your own errors before you try running the program. It’s actually a great experience. You learn how to program efficiently and well, or you just get very frustrated. You learn more of those intrinsic, basic rules of programming. Later, when you move to more fun languages, you figure out how to break those rules without it coming back to hurt you. Not only that, but C++ (and its big brother, C) teaches you about the low-level facts of computer science. In some languages, you may have numbers and strings. In C++, you have ints, shorts and longs; doubles and floats; unsigned and signed numbers; strings and character arrays… a whole pantheon of variable types, each with its limitations and special uses. All of these types map down to how the computer handles data. The different between a long and a short, for example, is the number of bytes the computer allocates for that particular variable. It’s rather interesting, really. (Tip #4: Learn how computers work. You’ll be using them so much that you need to know this.)

Junior year was a bit of a disappointment. The final programming course, with prepared you for the AP Computer Science test, did not fit in my schedule. This was somewhat of a hidden blessing: Ms. Bamford left my high school and the new teacher, I later found out, wasn’t as good. (To be fair, not many people could be.) However, that doesn’t mean I sat idle for a year and let my nascent programming skills get rusty. Some explorations on the internet revealed to me a whole set of new languages, and I set about learning one: Python. Python is something of a “scripting language” as opposed to a programming language like C++. (See my post on Lua for more about scripting vs. programming.) The key thing here was that I had moved beyond the bare-metal nature of C++ into a more abstract landscape. Python still uses OOP, sure, but you don’t have to worry about different data types or how your programming is using memory. Instead, you can just focus on how to solve the problem at hand. Python is less strict than C++, and certainly more helpful when you’ve messed up. Personally, it’s my suggestion for the first language that someone should learn if they want to program.

Senior year brought a new programming teacher and yet another new language: Java, the tool of choice for the AP Computer Science test. Java commits itself fully and without reservation to the principles of Object-Oriented Programming. C and C++ let you do some things as just plain imperative programming, while Python can be adapted to several paradigms. Java looks out into the worls and sees a glorious universe of Objects. Frankly, I find it limiting. However, many people find it a great language for teaching and general development, and I have to admit that it’s much easier to deploy a Java program than any other language. (That doesn’t mean I have to like it, dammit.)

So there you have it. That’s how I got into programming. Here’s Tip #5: Program early, program often. It’s a skill, or an art. You have to use it and develop it if you want to be any good at it. That’s probably stupidly obvious, so here are some suggestions on how to actually do that:

  1. Take a course. It’ll give you some structured learning and teach you what you need to know to be successful. It’ll also give you exercises that you can do to improve your skill and learn new techniques.

  2. Open source development. There are thousands of open source projects out there, and they all need developers. This may seem a bit daunting at first—I certainly didn’t feel enough confidence in my code to put it out in public for years!—but even a novice can learn something. You could even just check out the code and see what they’re doing and how they’re doing that. (Bill Gates, I believe, is a proponent of studying other people’s code to become a better programmer yourself.)

  3. Programming challenges. There are a number of sites out there that hold competitions for every skill level. For example, there’s /r/dailyprogrammer on Reddit.

  4. Recreating other software. Ever wonder how a particular piece of software works? Why not try creating it yourself? Challenging, but fun!

  5. Algorithms study. Algorithms form the core of programming; they’re the recipes on which programs are built. Studying them can really improve your programming and give you more tools to use.

  6. Read. There are tons of blogs and books that can really help you out. I suggest Code Complete by Steve McConnell. You can also look for books about a particular language or environment that you’re interested in.

  7. Explore. Discover new programming languages and paradigms. Once you’ve learned C++, Java and Python, check out languages like Haskell or Racket. They’re completely different experiences.

You get the idea, you think. Programming, right now, is one of the few fields where being self-taught may not hold you back. I do suggest formal education, of course, as that exposes you to all sorts of good influences and interesting ideas. But hey, that’s up to you!

Here’s the tips again, all in one dandy list:

  1. Find a good teacher. Alternatively, find a good learning resource.

  2. Learn not just a programming language, but about programming itself.

  3. Programming is and should be fun. Experiment. Explore. Examine.

  4. Learn how computers work.

  5. Program early, program often. Develop your skills!

So there you have it. I hope this helps you and that you enjoy programming.