Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
    
english.stackexchange.com/questions/20455/… –  user11408 Jul 12 '12 at 10:48

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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