Reddit プログラミング初心者からの脱却

授業を聞いたり、ビデオを見ただけではプログラミングは上達しない。

コードを書き続けることをしないと上達しない。

Hi /r/learnprogramming,

A few weeks ago I asked programming beginners to tell me about the difficulties they faced, and a common problem was moving beyond the basics, especially after doing online courses. I’ve written an article about it here:

http://www.programmingforbeginnersbook.com/blog/when_you_know_the_basics_but_you_still_cant_code/

Below is a short summary.


People express this problem in a few different ways, such as:

  • “I’ve learnt Python through an online course, but I don’t know how to use it to make programs.”
  • “I know the theory, but I can’t put it into code.”
  • “I know about while loops, but I don’t know how or when to use them.”
  • “I know about loops and arrays and variables, but I don’t know how to combine them.” Usually the student completes some kind of online programming course, but feels lost once the course is over.

[…]

In summary, 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!

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:

  • “I’ve learnt Python through an online course, but I don’t know how to use it to make programs.”
  • “I know the theory, but I can’t put it into code.”
  • “I know about while loops, but I don’t know how or when to use them.”
  • “I know about loops and arrays and variables, but I don’t know how to combine them.”

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
  1. Not like this:
  2. def foobar
    puts 1 + 2 / 3
    end
  3. Mention what you have already tried. This tells people that you’ve already put in some effort.
  4. 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!

A List of Basic Programming Terms

Here are the definitions for some basic programming terms, with usage examples. These terms are applicable to most programming languages.

I’ve tried to keep the definitions as simple as I can. This means that some definitions will be missing details and nuances, but they are correct in a general sense. For the practical purposes of a beginner programmer, the minor technicalities aren’t that important.

Where a term from this list is used in a definition, it will link to the term and look like this. Where a term can be used as both a noun and a verb (e.g. assignment/assign), I’ve only included a single definition — both usages should be deducible from the one definition.

algorithm(noun) a step-by-step procedure to achieve a specific goal. Can be implemented with code.
Example: I used the quicksort algorithm to sort the array alphabetically.argument(noun) a value that is passed into a function when it is called. Arguments are said to be “passed” into a function, and functions are said to “take” arguments. Also known as a “parameter.”
Example: That function takes two arguments.array(noun) a type of value that contains a sequence of other values.
Example: I put all our names into an array of strings.assignment(noun) the act of putting a value into a variable.
Example: I assigned the number 22 to the agevariable.brackets(noun) characters often used to surround text. The different types of brackets are:

  • Parenthesis/parens/round brackets: ( )
  • Curly brackets/braces: { }
  • Angle brackets: < >
  • Square brackets: [ ]

The bracket at the beginning is called the “opening” or the “left” bracket. The bracket at the end is called the “closing” or “right” bracket.
Example: Your code won’t compile because you forgot a closing bracket.

bug(noun) a mistake in a program.
Example: There must be a bug because the output is wrong.call(verb) to run the code in a function. Also referred to as “running,” “executing,” or “invoking” a function. For the noun, see function call.
Example: I called the rand function and it returned 42.class(noun) a type that can be defined by the programmer. Classes are defined in order to create objects of that class. See object.
Example: I made a Person class that holds a person’s name and age.comment(noun) arbitrary text written around code, but which is never run, and is generally ignored by the computer. Used to leave notes and documentation for people who read the code later. Also used to stop code from running (see comment out).
Example: I wrote comments in my code so I could understand it later.comment out(verb) to turn code into a comment so that it does not get run.
Example: I commented out this line of code, and it doesn’t crash any more.compiler(noun) a program that converts code into an executable, and checks that the syntax is correct. Sometimes compilers convert code into other code.
Example: The compiler is giving me an error, so I must have incorrect syntax somewhere.constant(noun) a variable that never changes its value.
Example: The PI constant has the value 3.14.crash(verb) to cause a running program to stop due to an error.
Example: I tried to divide a number by zero, which made the program crash.data structure(noun) a value that contains other values.
Example: Arrays are one kind of data structure.debug(verb) to investigate and fix bugs.
Example: I spent all day debugging a complicated error.declaration(noun) code that declares that something exists – usually a variable, function or a class. A declaration might not fully define the thing it is declaring. E.g. a constant may be declared to exist, without actually defining what it’s value is. Not all programming languages allow for declarations.
Example: My code won’t compile because I wrote a function declaration, but I forgot to write the actual function.definition(noun) code that fully implements something – usually a variable, function or a class. The code that implements a class is called the “class definition.” The code that implements a function is called the “function definition.”
Example: The function wasn’t doing what I expected, so I had a look at its definition.double(noun) a float that can represent a wider range of numbers than a normal float. Short for “double-precision floating-point number.” See float.
Example: The number was so tiny I had to use a double instead of a floatexecute(verb) Synonym for run.
Example: I can’t execute my program because it won’t compile.executable(noun) a program, usually a single file, ready to be run.
Example: Give me the executable so I can try out your program.float(noun) a type of value that represents numbers with fractional parts. Short for “floating-point number”.
Example: The value 3.14 is a float.function(noun) a piece of code that is not run until it is called. Functions take zero or more arguments. When a function finishes running, it returns a return value back to the code that called it.
Example: I wrote a function that takes an array of numbers as an argument, and returns the average.function call(noun) code for calling a function. Function calls specify which function to call, and all of the arguments that the function requires. The result of a function call is a return value. Not all functions have a return value.
Example: The function call add(1,2,3) returns the value 6.implement(verb) to write all the code to complete something – usually a function or a class.
Example: I finished implementing those functions.instance(noun) Synonym for object.
Example: I created an instance of the Personclass.instance variable(noun) a variable that is attached to an object. Also known as a “member variable” or just a “member.”
Example: On the tom object, I assigned the value "Tom Dalling" to the name instance variable.instantiate(verb) to create an object from a class.
Example: I instantiated an object of the Personclass.integer(noun) a type of value that represents whole numbers. For fractional numbers, see float.
Example: 42 is an integer value.interpreter(noun) a program that runs code. For languages that are not compiled, the source code is run directly by an interpreter. Compiled programming languages do not usually have an interpreter.
Example: I installed the Ruby interpreter so I can run my Ruby code.invoke(verb) Synonym for call.
Example: I invoked the function with the wrong arguments, and it crashed.iterate(verb) Synonym for loop.
Example: I iterated over all the values in the array.loop(noun) a piece of code that runs itself repeatedly. Commonly used to run a piece code for every valuein an array. Also known as “iteration”.
Example: The code loops until the user types in “quit.”member function(noun) Synonym for method.
Example: This class has three member functions.member variable(noun) Synonym for instance variable.
Example: This class has two member variables.method(noun) a function that is attached to an object. Methods belong to, and are defined in, a class. Also known as a “member function.”
Example: The length method returns the number of characters in a string object.nested(adjective) contained within something like itself. E.g. a nested array is an array that is inside another array, and a nested class is a class defined inside the definition of another class.
Example: I used a nested loop to loop over a grid – the outer loop for the x coordinate, and the inner loop for the y coordinate.object(noun) a value created from a class. E.g. If you want to represent your family in code then you might make a class called FamilyMember, and create several objects from that class – one object for each person in your family. Objects usually contain other values inside instance variables, and have methods attached to them. E.g. each FamilyMember object might have a nameinstance variable. Objects combine the concept of variables and functions into a single value. Also known as an “instance.”
Example: I make the enemy move by changing the position instance variable of the enemy object.object-oriented(adjective) designed using objects.
Example: Ruby is an object-oriented programming language because all values are objects in Ruby.parameter(noun) Synonym for argument.
Example: That function takes two parameters.parenthesis(noun) A type of bracket.
Example: Lisp-like programming languages use a lot of parenthesis in their syntax.procedure(noun) Synonym for function.
Example: That procedure takes two arguments.program(noun) a full piece of software that is ready to be run. Usually an executable.
Example: I wrote a program that keeps track of my todo list.read(verb) to retrieve input data values from an external source – usually from a file. Can refer to retrieving data over a network, such as the internet. The opposite of writing.
Example: I read the contents of file into a string.return(verb) to immediately stop a called function from running, possibly providing a return value. A function automatically returns once all of its code has been run. However, the code in the function definition can force the function to return at any point.
Example: If the array is empty, the function returns early without running the rest of its code.return value(noun) the value that results from a completed function call.
Example: The return value of the rand function is a random float between 0.0 and 1.0.run(verb) to perform the instructions written in code or an executable. Code is a set of instructions, and “running” code is when the computer actually performs those instructions. To “run” a function means to call that function (see call).
Example: I wrote a new feature, and ran the code to check that it works.string(noun) a type of value that represents text. The word “string” derives from the phrase “string of characters.” E.g. The string "cat" is a string (a.k.a. sequence) of the characters ‘c’, ‘a’, and ‘t’.
Example: I represented my name as a string in the code.syntax(noun) the grammatical rules of a programming language. Every programming language has different syntax. Syntax determines whether code is written correctly or incorrectly, and is enforced by the compiler or interpreter. Code will not compileor run unless the syntax is correct.
Example: I forgot to write the brackets, so the compiler gave me a syntax error.type(noun) the kind or category of a value. Every value has a type.

  • The value 5 is of the integer type.
  • The value 5.2 is of the float type.
  • The value "cat" is of the string type.

Simple types, like integers, are usually provided by the programming language. The programmer can define more complicated types using classes. The type of an object determines what methods and instance variables are attached to that object.
Example: I got a crash because the variable contained the wrong type of value — I thought it would be an integer, but it was actually a string.

value(noun) a piece of data that can be contained inside a variable. Every value has a type. Values represent information, in a way that code can work upon. Code can:

  • send and receive values over the internet
  • save values into files
  • convert values into different values
  • etc.

Example: My program asks a user for the year they were born, then uses that value to calculate their age.

variable(noun) a named container for a single value. Variables are not values themselves, they are merely containers for values. Putting a value into a variable is referred to as assignment. Variables are named after the fact that their value can vary — a different value can be assigned to a variable at any time.
Example: I assigned the string value "Tom" to the name variable.write(verb) to send output data values to an external destination – usually to a file. Can refer to sending data over a network, such as the internet. The opposite of reading.
Example: The program writes all its data to a file before it quits, so it can read the data back again next time it is run.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.