Ok, so you’ve decided what programming language you want to learn and now you are all set to learn it.
All you need to do is crack open a book and start reading, right?
Well, not exactly. I mean, you can do it that way—if you like frustration.
Remember how we talked about how you learn best by doing?
That’s the plan for this chapter.
I’m going to give you the layout for the ideal way to learn your first programming language, and not just to learn it, but to become extremely comfortable and proficient in it, if not master it.
Learning your first programming language can be the most difficult thing about learning to program, but it doesn’t have to be.
Most programmers—myself included—learned by reading a book, trying a few things out, scratching our heads, and then rereading a book and continuing to try things out until it finally “clicked.”
What I’m about to share with you comes from coaching and teaching many software developers through not only learning their first programming language but also improving their skills in that language. I also bring my own experience mastering languages like C++, C#, and Java.
Basically, in this chapter, I’m showing you what I would do—knowing what I know now—if I were in your shoes and were learning my first programming language today.
Start by Looking at a Working Application
Most starting programmers, when they want to learn to program, pick up a book and start reading.
While there are some excellent books out there which attempt to teach you programming in a very hands-on approach, I think the best place to start is by looking at the source code of an actual working application and trying to figure out as much of what is happening as possible.
This is difficult.
It’s going to feel uncomfortable, but that’s ok. Get used to feeling uncomfortable. That is the only real way to grow in life.
What I want you to do is to pick an open source application—preferably a popular one that is likely to be well-designed—and start looking through the source code.
You can find plenty of projects on GitHub, so I’d recommend checking there.
It’s beyond the scope of this book, but it’s even better if you can download the code and build and run the application yourself.
If you have a friend that can help you with this, that’s great. If you don’t, it’s ok.
What is important is that you explore the code to get a feel for what the programming language syntax looks like and that you try and read the code and see if you can understand or make sense of anything.
Use the application itself, if possible, so you can get a feel for the relationship between the code and what the code does.
Like I said, this is going to feel very uncomfortable.
You might feel like you're not understanding anything.
I repeat, that is ok. Just do your best and see if you can figure out how one or two things work or what you might change in the code to change the functionality in some way.
Moreover, get a feel for how things are named and how they are organized.
Pretend like you are an archaeologist trying to understand the writing of some ancient civilization.
By starting out this way, you are going to have a serious head start over most programmers who have no idea what the programming language they are trying to learn even looks like.
It’s always a good idea to get a lay of the land before embarking on any journey.
Programming is no different.
Find a Few Good Resources or Books and Scan Through Them
Further continuing with the theme of getting the lay of the land before setting sail, the next step is not to read a programming book cover-to-cover, but instead to pick out a few books or other resources—such as videos, articles, or tutorials—and scan through them.
Again, this is going to be at least somewhat uncomfortable because much of what you are looking at isn’t going to make much sense.
But… the idea here is to scope out the territory. You just want to get an idea of how big this thing is that you are about to learn and what the general concepts are.
This extra work upfront will pay off later when you have an idea of what types of things you are going to be learning and how the concepts are going to build on each other.
If you have taken my “10 Steps to Learn Anything Quickly” course, you might recognize that what you are essentially doing here is getting the big picture and determining scope.
Learn How to Create Hello World
Ok, at this point you are still not “reading a book” or taking a training program.
You’ll be doing that soon enough—if you want to. (You can actually learn a programming language without doing that, if you follow these steps. I learned Go and Dart in about two weeks utilizing only online documentation and a similar process to what we’re discussing here.)
What you want to do at this point is to create the most basic kind of program you possibly can in whatever programming language you are learning.
Remember how we talked about learning just enough to get started in the chapter on “How to Develop Technical Skills?”
That is the goal here.
You want to get started as soon as possible so that you can develop the confidence and knowledge to apply what you will be learning and put it immediately into practice.
What you are going to start with is a very basic program called “Hello World.”
Most programming books begin by having you create a “Hello World” program, which usually just prints “Hello World” to the screen.
The idea here isn’t really to learn all that much about the language, but rather to become familiar with and test out the basic tool chain required to build and run a program in your programming language of choice.
If you have a book you are reading about your programming language, it should contain an example of a “Hello World” program you can create.
If not, just do a Google search for “Hello World + your programming language.” You should have no trouble finding an example.
By creating a “Hello World” program, you’ll also learn the basic structure of a program in your programming language.
Learn Basic Constructs and Test Them out with Real Problems
Now comes the point where, if you have a book on your programming language or tutorial of some sort, you could start reading or working through it.
At this point, what you are reading or consuming shouldn’t be quite as mysterious as it would have been if you just dove in.
What you want to do now is familiarize yourself with each of the basic constructs of the programming language you are learning, and then write some code that uses these constructs.
You’ll want to try and think of problems or applications associated with what you are learning that are as realistic as possible because, when you apply a skill to an actual problem, you understand and remember it better.
Here is a list of some of the basic constructs most programming languages should contain:
- Ability to write output to the screen
- Basic math capability
- Storage of information as a variable
- Organization of code into functions, methods, or modules
- Invoke a function or method
- Performance of boolean logic evaluations
- Branch conditional statements (if / else)
- Looping statements
Here is some good news.
Once you know these basic constructs and how to use them, you’ll have the basics of programming in any language. Yes, the syntax might be different, but this is the core of programming.
You will probably spend a good amount of time in this phase.
Just work your way through, learning each of the constructs of your programming language one at a time, and apply each construct by actually writing some code.
If you are working on your own, you’ll need to identify what all the constructs are and in what order it makes sense to learn them.
If you are going through a book or tutorial (or preferably multiple books and tutorials), the path should be laid out for you and should even have some examples and challenge assignments for you to do.
Try to make sure you always understand what you are learning and how it is applied.
Now is a great time to go back to that original source code you looked at in the first step and see how much more of it you understand.
Know the Difference Between Language Features and Libraries
One thing that often trips up beginning programmers—especially with the programming languages of today—is knowing what is part of the language and what is part of the standard libraries that come with the language.
Often the distinction is not very clear because, idiomatically, you are going to write code that uses the standard libraries very often.
That’s ok. You are going to need to know the conventions for programming in the programming language you are learning, but you should take special care to try and figure out what is part of the actual language and what is part of the libraries that are often used with the language.
This might seem like nitpicking, but I think it’s important because it will take that scrambled mess of syntax that you probably have floating in your head at this point and help you categorize and organize it to make more sense.
What you’ll realize is that, for most programming languages, the actual language part itself is not that large and is relatively easy to learn, but the standard libraries are large and knowing your way around them is going to be the more difficult endeavor.
Programming today is more about knowing how to use libraries and frameworks than being an absolute expert in the language.
That is one of the reasons why this distinction is important.
By realizing what is not part of the language but is rather part of the library and learning how to look up libraries for common tasks you want to accomplish in the language, you’ll become a much better programmer.
Review Existing Code and Work Through Understanding Each Line
At this point you should be familiar with all of the major concepts of the programming language you are learning, and you should have used most of the programming language features in real examples.
You also should have a decent understanding of the difference between the language itself and the libraries that are used in conjunction with the language.
You still might not exactly feel comfortable with the language or that you actually know it.
This is the stage where you may sort of feel like you can understand how everything works, but you have no idea how you would put it together to write a real application.
Many beginning programmers tend to get a bit stuck at this stage and feel frustrated, thinking they’ll never be a real programmer.
One of the best ways to push forward from here and make sure you don’t have gaps in your knowledge is to start looking at existing code, line by line, making sure you understand exactly what each line and statement in the code is doing. (Even if you don’t always understand the why, being able to know the what is still progress.)
You can take the existing source code for a project you looked at in the first step and start randomly going through files in the project.
Open a file and go through each line of code in the file, making sure you understand exactly what it is doing.
If you don’t understand—and there will be plenty of things you won’t—take some time to think about it, and look up anything you don’t understand.
This is tedious. It might even be boring, but it’s totally worth it.
When you get to the point where you feel like you can read any line of code and understand what it is doing—again, the why is not as important at this stage—you are ready to move on.
Build Something… Lots of Somethings
Now it’s time to really start using the programming language.
At this point, you should already have written a few small programs and utilized most of the features of the language, but you’ll get a greater feel for the language once you start actually building real applications.
Pick a few small project ideas—nothing huge—and start building applications.
Don’t pick anything too ambitious and don’t try to do anything platform specific or UI intensive at this point. Preferably, your applications will just print text to the screen and take input from the keyboard for now.
The idea is to build some simple applications that focus on utilizing the programming language you are learning and the standard libraries, not additional frameworks for platform features—we’ll get to that next.
By doing so, you will build confidence in the programming language and your ability to use it, and you’ll learn what language constructs to use to reach the goal you are trying to accomplish.
Here are some simple project ideas to get you started:
- Create a program that solves a mathematical problem by getting inputs from the user.
- Create a Choose Your Own Adventure type of program where the input from the user determines what happens next.
- Create a very simple text-based adventure game where the user can issue commands to pick up objects, move through rooms, etc.
- Create a program that is able to read input from a text file and write output to a different text file.
- Create a chatbot that talks to the user and pretends to be human or gives humorous responses.
Apply the Programming Language to a Specific Technology or Platform
Up until this point, you should have mainly been learning about and using the programming language you’ve chosen in isolation.
This is intentional because you need to understand and be comfortable with the programming language itself and its standard libraries before adding the extra complexity of the environment and other frameworks you might use to build a real-world application.
In order to create something useful with a programming language, you are going to need to apply it to a specific technology or platform.
At this point, you should decide on a few small projects you can complete which will require you to utilize the programming language on a specific platform.
For example, let’s suppose you are learning Java.
Up until now, you would be writing Java code that would work on any platform that Java could run on, since you’d be mostly using the standard libraries and just working with input and output to the screen or a file.
At this point, you might decide to use Java to build an Android application.
You will have to learn how to build Android applications and about the Android framework. (This is a good place to utilize the “10 Steps to Learn Anything Quickly” program.) However, you’ll already be familiar with Java, so you won’t be trying to learn a huge amount of things at once without knowing what Java is or what Android is.
You can, of course, learn Android and Java together—in fact, I did a Pluralsight course teaching exactly how to do that—but to get a real mastery of the language and avoid confusion, isolating the language from the platform or technology and then combining them is probably going to be much easier.
Now you will be developing specific, specialized skills with the programming language you are learning that will be useful for getting a job.
Pick whatever platform or technology you think you are most likely to want to work with in the future and start creating a few small applications using it.
I’d also recommend that you specialize in just one technology or platform at this point. You can always learn more later.
By specializing, you will not only limit what you have to learn at this point, but you will allow yourself to gain a deeper knowledge and competency in a particular technology, which will make you much more confident and greatly increase the marketability of your skills.
Solve Difficult Algorithm Problems with the Language to Master It
By now you should be pretty comfortable with the programming language you are learning.
You should know it pretty well and have used it in a variety of different applications.
You should have a specific technology or platform you’ve applied your skills to and feel comfortable creating basic applications using that technology.
Nevertheless, you still might not feel like you have a mastery of the programming language.
Don’t worry; this is also normal.
When I was first learning C++, I remember how even after I understood everything about the language, had actually used it to create several applications, and was even working as a developer writing C++ code, I still didn’t feel like I had a real mastery of the language.
I felt like I was a good C++ programmer, but not a great one.
I really wanted to get my C++ skills up, but I didn’t know how.
Every week, there was a new set of programming challenges where you could compete against other programmers to solve some fairly difficult algorithm problems.
At first I was horrible. I couldn’t even solve the easiest problem.
I would look at other people’s solutions, and I would have no idea how they came up with that solution or even how their code worked.
They were using C++ in a way that I never imagined.
But then, over time, as I kept trying to solve problems and I looked at how other people had solved the problems, I started to get better… much better.
I started to see patterns in how certain types of problems were solved.
I started to really understand how to utilize features of C++ that I had previously ignored.
I learned how to effectively use the standard libraries and language features along with data structures to solve complex problems.
I became not just proficient at C++ but excellent at it. I finally felt as though I had mastered the language.
That’s what I want you to do.
You don’t have to go on Topcoder to compete, but there are plenty of places where you can practice solving algorithm-type programming problems.
I’ve already mentioned one good resource for these kinds of problems, but here are some more:
- Cracking the Coding Interview by Gayle Laakmann McDowell
- Programming Pearls by Jon Bentley
- Project Euler
- Interview Cake
- Topcoder (check out the practice rooms for the algorithm contests)
These problems will be extremely difficult at first, and that is ok. They are supposed to be.
What you’ll find is that, over time, you’ll start to recognize that there are only a handful of types of problems, and you’ll start to be able to identify how to solve them immediately.
At first, you’ll have no clue what to do, and like I said, that’s ok—just keep trying.
Also, don’t forget to look at how other people have solved the problems you are struggling with. Try to understand why they solved particular problems the way they did.
This was one of the best ways I was able to learn how to solve these kinds of problems.
I would look at the solutions of the top coders on Topcoder, and I would learn a great deal.
Once you can solve these types of programming problems with the programming language you are learning, you will not only be pretty close to mastery of the language, but also coding interviews will be a piece of cake for you while other candidates are sweating through their shirts.
During this phase, you'll be absorbing lots of information. There are good and bad ways to do this — check out my course 10 Steps to Learn Anything Quickly for some tips.