How I taught myself to program (and which languages in what order)

Interested in learning to program and write code? Wondering what programming language you should teach yourself? Curious how other people got started? In this article I'll explain how I started from ground zero, knowing nothing about programming or software development, struggled to grasp new languages and concepts, and later knew enough to get a job making custom website back-ends, writing scripts for my colleagues, and developing mobile apps. Along the way I'll point out some helpful resources that I have found, as well as common pitfalls that I hope you'll avoid. Let's begin!

Which language should I learn?

A lot of people new to programming often ask this question. Depending on who you'll ask (or where you ask it) you'll often get a lot of different answers. When I was just starting out I asked people this question and did a lot of research. Java was something that people kept suggesting. Looking at all the features it had (like object-oriented, reusable, automatic memory management, or portable) made it sound very appealing, even if I didn't exactly know what those words meant for a language. What ultimately convinced me was the adoption rate and the number of companies and organizations who used Java. I was thinking that if everyone else was using it, then it must be a good choice, right?

Wrong. Java was very hard to dive into. Your first, supposedly simple "Hello World" application was full of weird keywords that would take an experienced programmer a few days to fully explain. What the hell does public static void main(String[] args) even mean? Why is it necessary? What's arguably worse about Java for beginners is that it introduces the advanced concept of objects and classes way too early in the game. Add strong typing, inheritance, and polymorphism to the mix and you'll have beginners scratching their heads and getting discouraged. Sure those features are awesome (and almost necessary for large projects), but they are advanced topics that someone new to programming shouldn't be too concerned about. But Java almost forces you to use them, or at least think about them. That's why to get anything to run you have to use static void main(String[] args).

So after getting all sorts of excited to finally learn programming, I purchased Head First Java and spent a couple weeks writing my first programs. For the reasons summarized above, I was quickly discouraged and each day teaching myself programming was getting more tiresome. I took a very long break of about 6 months because I thought programming was difficult and it didn't feel very rewarding.

What was the first language that was exciting?

I later thought it'd be a fun project to get a website up and running. After figuring out how to make a simple website (full of static HTML pages) I wanted to make a dynamic, user-interactive website which I realized would be easiest with PHP. After researching a good book, I ordered the highly-acclaimed PHP 6 and MySQL 5 for Dynamic Websites  and within a week was writing simple, powerful, useful, and fun PHP code. The book is one that I have recommended to friends and though it assumes some programming knowledge, I found the book to be an excellent source in learning PHP from the ground up.

If you're not familiar with PHP, it is a "web language". What does that mean? It means that it is useful for writing web pages. To put it simply, PHP exists to spit out a bunch of HTML, process forms, interact with a database, and spit out some more HTML. Some great questions to ask are: where does PHP live? Do you compile it? Do you install it somewhere? What makes PHP such a good first language was that if your web server supports it, PHP is as easy as writing a couple lines of code in a simple text editor, sticking it on your web server, and then visiting that page with a web browser. Here's an example page. Note that most of this is simple HTML, with just a couple lines of PHP code:

<title>PHP Test</title>
echo '<p>Hello World</p>';  
$count = 10;
$animal = "monkeys";
echo '<p>There are ' . $count . ' ' . $animal . '!</p>';  

You'll notice that the PHP lives in between the HTML. How easy is that? (pretty easy!). To get output from PHP code you typically echo or print it out in the form of some HTML, maybe in between some paragraph <p>. You can also use PHP to create any sort of other HTML tags like dynamic <div> and layout tags, or maybe headers, or buttons, or CSS, or JavaScript. PHP stands for the hypertext preprocessor meaning it is executed and ran before the HTML is displayed to the end user.

PHP also is a great language to learn in conjunction with a database, typically MySQL (because they play so well together). Databases are a big deal, and any aspiring programmer needs to know the basics of how to interact with one. What's great is that PHP and MySQL are really easy and approachable. You don't need to dive into crazy advanced topics to do some neat and very useful stuff. The week or two that I spent learning about databases when I was learning PHP has been super useful with other languages and future projects.

So why was PHP such an "exciting" language?

  • It was easy to get started (no installation)
  • I didn't need to understand advanced topics to do simple things (dynamic weak typing, objects are optional)
  • I created cool stuff quickly (a dynamic website that my friends and I used)

The last point is pretty key. If you are a beginner learning how to program, you'll want to operate in a way that gives instant feedback and satisfaction. The other components help (no installation, no worrying about data types) but if you don't feel like you're accomplishing something, you'll probably give up faster.

What was the second language that was exciting?

During my senior year of college I took my "first" formal programming course (technically third, since the first was using MatLAB to create ray-tracing programs for an optics course, and the second was Mathematica for applied boundary value problems and Fourier analysis). This class was taught by the computer science department and those wishing to learn computer science typically took it during their first year in the program. The language that was chosen for introductory students was Python.

Why Python? That was the very first lecture, and I'll share with you the bullet points taken straight off the PowerPoint presentation:

  • —Named after Monty Python’s Flying Circus

Which probably just means the course instructor was a bit weird. But let's look at what sort of programming assignments we had. Here's the classic Hello World (with my addition) program in the Python IDE that comes bundled with the software installer (17 MB that unpacks to ~50 MB).

And let's see what it looks like when it is executed (by pressing either F5 or going into Run -> Run Module)

Neat, huh? What's also neat is that it takes all of 5 minutes to download, install, write, and run your first Python program. The software and packages are light-weight and comes with its own text-highlighting editor (IDLE) and console shell. Now let's look at some of the other programs that our first-year class made:

  1. A text scanner to analyze large text documents (entire books) to determine word counts per sentences, word frequencies, etc.
  2. Animations and simple 2-dimensional movies by procedurally drawing and moving shapes.
  3. Sound synthesizers and audio transformation tools.
  4. A simple web crawler.

They sound pretty neat, useful, and engaging. Yet these were created by first year students, many of which never programmed before in their life. You might be thinking, "Wow, a web crawler... something that is a fundamental part of Google, Bing, and Yahoo... how the hell does a first year student make something like that?" Check out the code here-- it's under 50 lines of Python.

Python has a great community and comes with some awesome documentation. It doesn't have a difficult installation or a write, compile, run workflow. The debugging information is usually helpful. It doesn't force you to use objects and classes (unless you want to) or think about which data type your variables should be. At the same time, it's powerful enough to do just about anything you wanted to. Unless you're developing enterprise level software or extremely computationally intensive tasks (and most beginners aren't!) you don't need to write in Java or C/C++. In fact, Google is well known to use Python for all sorts of projects (such as this DNS benchmark utility). In fact many software engineers and research scientists are turning to Python for their projects or for rapid prototyping. You may also notice that at many of the universities and colleges in the U.S. computer science departments are frequently moving away from using Java for the first couple courses. (Two of the schools in my area use Python for the first two CS courses in a four course sequence, Java for the last two, and C/C++ or Java for the remaining advanced courses).

Let's summarize why I found Python to be so exciting:

  • It was easy to get started (the installation was quick and comes with its own IDE, called IDLE)
  • I didn't need to understand advanced topics to do simple things (duck typing, objects are optional)
  • I created cool stuff quickly (a web crawler among others)
Look familiar?

So what language should I learn?

Many enthusiastic and aspiring programmers still get stuck on this question. Here's the answer: Learn whatever language works for you, keeps you excited, and is flexible enough to do whatever you want. With that in mind, I personally believe Python really worked for me. PHP got me very excited and is the language that I really learned how to program with, but it also has a pretty specific purpose (web development). Sure you can create websites with Python, but PHP was incredibly easy to get started with. And this reflects another very important point: Use whichever language is most suitable for the work that you are doing. You can use C/C++ to create a DNS benchmark software for individuals to check their speeds at home, but it'd probably be a lot faster to use Python. At the same time, you can use Python to create an algorithm to find large prime numbers, but you'd be much better off using C or even assembly language.

As a beginner don't stress out too much about this question. The best thing you can do is pick a language, run through some tutorials, and see how you like it. The things that you'll discover while learning your first language will all translate over to the next one. After I had learned PHP and Python I took another stab at Java, this time with the goal of creating an Android app. Within a few weeks I was pumping out code and starting to appreciate (and understand!) all the advanced topics such as objects, classes, inheritance, and polymorphism. But I wouldn't ever have gotten it if I had just forced my way into it. Learning how to code, all the features of certain languages, and computer science in general is a process that will never end.

So what are you waiting for? Get started!


Read more posts by this author.

View or post Comments