Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Programming books often contain a lot of code scattered within it. Usually there will be an accompanying website to download the code used in the book.

How do you use the code? Do you just run them and check the results or do you code it from scratch again?

If you are coding it from scratch, have you found any advantages( like remembering the content better etc)?

share|improve this question

closed as primarily opinion-based by durron597, GlenH7, Bart van Ingen Schenau, Dan Pichelman, Ixrec Apr 29 '15 at 20:15

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.… – user11408 Jul 12 '12 at 10:48
up vote 6 down vote accepted

The best advice on the matter I know of comes from the prologue of Zed Shaw's Learn Python The Hard Way:

This simple book is meant to get you started in programming. The title says it’s the hard way to learn to write code; but it’s actually not. It’s only the “hard” way because it’s the way people used to teach things. With the help of this book, you will do the incredibly simple things that all programmers need to do to learn a language:

  1. Go through each exercise.
  2. Type in each sample exactly.
  3. Make it run.

That’s it. This will be very difficult at first, but stick with it.

And later on he elaborates:

It seems stupidly obvious, but, if you have a problem typing, you will have a problem learning to code. Especially if you have a problem typing the fairly odd characters in source code. Without this simple skill you will be unable to learn even the most basic things about how software works.

Typing the code samples and getting them to run will help you learn the names of the symbols, get familiar with typing them, and get you reading the language.

Almost all of the prologue is dedicated to why typing code is preferred, there is no point to copy it here, there's a free pdf version of the book you can read.

So, to answer your question, I always type in the code. Every time you choose to type the code instead of just compiling / running the accompanying code you actually get some valuable practice and extra muscle memory points in the language's syntax, conventions and quirks. It's not just the code that matters, unless all you want to achieve is reading the language.

Python, where indentation is a language requirement and not a matter of style, is a perfect example of why you need to type everything when learning.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.