When You Know the Basics, but You Still Can't Code

In a recent reddit thread about difficulties faced by beginner programmers, the most common difficulty was getting beyond the basics. People express this problem in a few different ways, such as:

Usually the student completes some kind of online programming course, but feels lost once the course is over.

Cause: Artificial Programming Environments

One contributing factor to this problem is the artificial environment that online courses provide to students. Students are usually typing code into a web page that contains instructions and hints. This is not how real programming gets done. So when the course is over and it’s time to use a real programming environment, students feel lost without the environment that they are accustomed to.

There is a good reason why online courses provide this artificial environment – it’s because setting up a real programming environment is often complicated and frustrating for beginners.

I’m not trying to say that artificial programming environments are a bad! They allow you to gain programming experience without the pain of setting up your own environment. Unfortunately, that pain has not been avoided, it has just been delayed until the course is over.

Cause: Excessive Guidance

When you’re completing an online course, or following a book, or even being instructed in real life, you’re being provided lots of hints and prompts that allow you to progress. You might even just be given the answers from the start, or told exactly what to type in. When you try to make a program by yourself, however, you’re just looking at a blank text file – no instructions, no hints, nobody telling you what to type. It’s natural to feel lost when you suddenly jump from one environment to the other.

One consequence of excessive guidance is that students learn syntax without learning programming concepts. Syntax is just the text that you type in for a particular programming language, like if and while. Syntax is different for every language. What you really want to learn are the concepts, like branching and iteration. Concepts allow you understand what the code will actually do, and they can be written in lots of different languages. When someone says that they know about while loops but they don’t know when to use them, that indicates to me that they have learnt the syntax but they don’t really understand the concept of iteration.

Again, I’m not saying that guidance is bad! When you’re just starting to learn, you definitely need someone to guide you. You will need people to guide you at every stage of your programming career. However, receiving too much guidance as a beginner can give you the false impression that programming is easy, leading you to feel disappointed when you can’t write a program on your own.

Real Talk

This is the part of the article where I give you a bit of tough love. Prepare yourself. If you feel that you know the basics but you can’t write a program without guidance, then I’m afraid that you probably don’t understand the basics yet.

You’re standing on what the Viking Code School refers to as The Cliff of Confusion:

The Cliff of Confusion is the painful realization that it’s a lot harder when the hand-holding ends and it feels like you can’t actually do anything on your own yet. Your primary challenges are constant debugging and not quite knowing how to ask the right questions as you fight your way towards any kind of momentum.

If your studies have been challenging up to this point, then this won’t come as a shock to you. If, however, you’ve been breezing through a programming course and got the impression that programming isn’t that hard, then this might feel like a punch in the gut.

It sucks, but you’re not alone. Everyone has to go through this stage if they want to become a programmer.

It’s going to be frustrating at times, but let’s look at some strategies to push through this phase.

Tip: Create a Real Programming Environment

Now is the time to go through the pain of installing and configuring a real programming environment. Each programming language requires a different environment.

First, you need a text editor or an IDE (integrated development environment). Find out what the most popular editor is for the language you are learning, and install it. You should be able to find one that is free.

Secondly, you need to work out how to run a file that contains code.

If you’re using an IDE as your text editor – like Visual Studio, Xcode, or Eclipse – then this functionality will be built into the IDE. Discover how to make a new project, and what buttons to click to run the code.

If you are not using an IDE, you will probably need to learn how to run your code from the command line. The command line will take a while to get comfortable with. Look for “getting started” instructions for your programming language, and also check YouTube for instructional videos that you can follow.

Once you can write code, save it to a file, and run the file, then you are ready to rock. This is how professional programmers write code every day.

Tip: Make Programs From Scratch

You have to start writing your own code, without instruction. Start with an empty file, and type every line of code yourself.

This is going to be really difficult at first. You will spend a lot of time debugging, and trying to understand error messages, but that is the point. Every time you investigate and fix an error, you are gaining real programming experience. This is how you learn and grow.

You can look at other peoples’ code, but don’t copy and paste it. If you paste in the code and it works, you haven’t learnt anything. If you paste in the code and it’s broken, you won’t be able to fix it. Analyse other people’s code, learn a little bit about how it works, then write it yourself.

Tip: Start Small

It’s fairly common to try to make something well beyond your skill level. This isn’t necessarily a bad thing. If you find it interesting and motivating then it will force you to learn a lot, including the fact that your MMORPG project is going to take many years to finish. It doesn’t matter whether you finish, as long as you’re learning along the way.

On the other hand, if you’re demotivated, confused, and making no progress, then you need to start with a much smaller project. At the beginning, you will usually be writing text-based programs because they are easier than everything else. All you need to know to make a text-based program is how to display a string on the screen, and how get a string that the user types in.

I know, I know, text-based programs are not as cool as 3D graphics. You know how everyone says that you don’t need to know math to program? Well that’s not true for 3D graphics programming. You will need a decent understanding of geometry, linear algebra, and a bit of differential calculus.

Even a normal GUI with buttons and text boxes can be difficult, depending on what programming language you’re learning. It doesn’t really require any math, but it will likely require a solid understanding of object-oriented programming and complicated object graphs.

My advice for beginners is to make text-based games for a while. Make a few games like “guess the number,” a multi-choice quiz, and tic-tac-toe. Try to make a text adventure.

Alternatively, make something that would be useful in real life. That could be a time tracker, or something to automate calculations you need for work or school.

Use these projects to learn all of the features of your chosen programming language.

Tip: Write Lots of Code

Programming isn’t a purely theoretical exercise. You can’t read books, watch videos, and answer quizzes, then expect to be able to create complicated programs. To learn how to write code, you have to write lots of code.

It’s a bit like carpentry. You can read all you like about carpentry, but reading alone won’t give you the skill to make a table. If you really want to learn how to make a table, you need to get some wood, a saw, and some glue, and actually attempt to make a table. The first table you make will probably be terrible. So you read a bit of theory, or get some advice from a real carpenter, and try to make another one. The second table is still no masterpiece, but it’s better than your first attempt. If you keep making tables, and applying the theory that you’re reading, eventually you will have a decent table.

Programming is the same, in that you have to make software to gain skill. The first program you make will not do much, and it will probably have messy code, but that doesn’t matter. Read some theory, get some advice, and make a new program. Each program you make should be bigger and better than the last. Repeat these steps for long enough, and you will become an expert.

Tip: Ask for Help

You are going to hit errors that feel unsolvable. That’s just part of learning to program. If you’ve tried to solve your problem for over an hour, it might to be time to ask for help.

Some students immediately ask for help without attempting to solve the problem themselves. This is generally frowned upon in the programming community. People might tell you to visit WhatHaveYouTried.com. Always try to google your problem first.

Other students refuse to ask for help, ever. This is probably slowing down their learning. If you’ve tried to fix your problem but nothing has worked, it’s OK to ask for help.

Don’t copy and paste someone’s answer to your question, though! Analyse the answer and learn the cause behind your error. That way, when you encounter the same error again, you will already know how to fix it.

If you’re constantly hitting unsolvable problems, that probably means that your project is too ambitious. Scale it back, and make something smaller until your skills improve.

Tip: Ask for Help the Right Way

Beginners often don’t want to ask questions because of their experiences dealing with the intimidating or unfriendly members of the programming community. If you ask your question in the right way, you will have a better experience.

  1. Paste in your exact error message. This is the most important peice of information. People often won’t try to answer the question unless they can see the exact error message.

  2. If there is no error message, explain what you expected to happen, and what actually happened. Some something like “I expect it to output 5, but it actually outputs 7”. Often, the problem isn’t in your code, it’s in your expectations. If you don’t explain what you expected, you will get answers like “the code looks fine” and “what is the problem?”

  3. Paste in your broken code. It’s very difficult to debug a problem without seeing the code. Paste it all in, if it’s not too big, because people will run your code to investigate the problem. If there is too much code, paste it into a Github Gist or Pastebin.com, then put the link into your question.

  4. Format your code correctly. Don’t just paste in your code like normal text. Learn how to format your code nicely so it is easy to read. It should look like this:

    def foobar
      puts 1 + 2 / 3
    end
    

    Not like this:

    def foobar
    puts 1 + 2 / 3
    end

  5. Mention what you have already tried. This tells people that you’ve already put in some effort.

  6. Try to use correct terminology. This isn’t always possible, because you are still learning all the terminology, but give it your best shot. Make an effort to learn the common terms, and use them correctly.

A small, but vocal, percentage of programmers are condescending towards beginners. It is true. Professional programmers often forget how difficult it was to learn their first language. But we’re not all like that! If you write your question according to the guidelines above, it will help to attract the nice programmers, and keep the grumpy ones away.

Conclusion

Programming is hard. Really hard. And if you’ve just breezed through an online course, this might come as an unpleasant surprise.

Set up a real programming environment, with an IDE or a text editor. Write little text-based programs to learn all the features of your chosen programming language, before moving on to bigger, complicated projects. Write all the code yourself. Don’t copy and paste other people’s code without understanding it first.

Write lots of code. Read theory, but make sure to apply the theory to your code. Read, code, read, code, read, and so on, and eventually you will master it.

When you get stuck, try to fix the problem yourself, but don’t be afraid to ask for help. You will learn faster if you ask questions. For a more pleasant experience, Learn how to ask questions the right way, because the programming community has a few grumpy bums in it.

Most importantly, have fun and keep going!

How All This Relates to the Book

The Programming for Beginners book is designed with all the points of this article in mind.

Right from the start, the book puts you into a fairly real programming environment. The first chapter gets you to install a text editor, and the Ruby programming language. It comes with a “code runner” file that gets you up and running quickly, without having to learn to use a command line. You can get this part of the book, and the code runner, for free in the samples chapters.

The book is structured so that you learn a bit of theory, with lots of code examples, and then you are required to make a small text-based game. It follows the read-code-read-code pattern. At the end of the book, you will have written multiple programs from scratch. Each program is slightly more complicated than the last, and requires you to apply all the theory that you’ve read up to that point.

You will probably need to ask questions, especially for the harder projects at the end, but the book is designed to be self-contained. All the theory that you require to complete each project is explained in the book, with code examples.

Give it a try!