views:

229

answers:

9

I am a student of computer engineering. I have never done any programming before, and as you can understand, I don't know how to study it or how to make my own programs. My English is weak [edited for clarity - ed], and so if you don't like the choices I list, please feel free to provide others.

How should I study? How should I learn programming languages?

  1. Study completely from a book.
  2. Don't study from a book, just try writing code.
  3. A mix of the two; study from a book, then try writing code.
  4. Study half the book, then write the code by hand on paper.
  5. Listed to the teacher, then try to solve general problems (those not from any specific chapter).
+1  A: 

I would use a combination of reading on-line tutorials, a book or two, and definitely practice coding it. Practice will make what you read become real for you. It's easy to forget what you've read unless you use it to do something useful. I guess I'd lean toward your answer choice 'c', since reading half the book before you start coding might be too much info to swallow all at once and might make you lose interest.

Dylan West
+1  A: 

Your option (c) sounds best.

You'll want to read a book, tutorial, or other source in order to understand the basic concepts of the language you're learning. At the same time, you'll never get very good if you only read and do book exercises, so it's a great idea to apply what you're learning to a real project as you read.

JSBangs
+1 for answering the question like a layperson rather than a computer programmer. This is what the question requires.
John Berryman
Since gcc's English isn't that good I think you should change that to "Your option (3) sounds best.
nategoose
+1  A: 

Reading books, articles and blog posts about programming languages and the data structures and algorithms that we implement with them is a required starting point, but you will want to reinforce that learning by writing practical code. Read, then code what you read.

Adam Crossland
+1  A: 

Joel wrote a great post about it. You might want to scroll down and take a look at the section for non-programmers. (It's right at the very end)

http://www.joelonsoftware.com/navLinks/fog0000000262.html

Apart from that, if you have an idea and a platform to implement it on, then I think reading sample code, a few tutorials online to get you started and forums like SO help a lot. If you like structured learning without jumping around all over the place, I'd say get a book, read while working on your code.

Tejaswi Yerukalapudi
MarkJ
A: 

Why not a combination of all of those?

There probably isn't one correct way to learn though. If you learn the best by reading out of a book, that is probably for you. You should aim for what works best with your learning style.

Jim
A: 

Learning programming solely from a book vs programming is a bit like learning a foreign language solely by reading. You only get half of the picture. It isn't until you try to construct sentences and interact with actual people that you really become competent in a foreign language. The same is true of programming languages. If you want to understand the language, yes, you need a book to get you started. But it isn't until you apply those ideas in practice that you gain a strong understanding.

Joel
A: 

Everyone is different. For me personally I spent my first two years on tutorials and figured out some information. I didn't get the bigger picture or details of things until I purchased my first thick reference book. I referred to books ever since.

Phil
+1  A: 

The method is not really all that relevant. What is relevant is the 'content' that needs to be learned.

  • Syntax: this should be the easiest, but for some reason stumps a lot of people. You should have a book handy that has a short overview of the syntax.
  • Semantics: this is what programs mean. Again, a reference is useful.
  • Idioms: otherwise known as 'good style'. This is where it gets harder, and where you need examples of good code to base yourself on.
  • Modularization: how to structure larger pieces of code.

It takes a while to get through all of that, but it's worth it.

If you are learning your 2nd, 3rd or 4th language, especially if they are of a similar paradigm than what you know, it gets easier and easier. If you are learning a new paradigm, then you really need to be ready to get your brain rewired. You're not getting it until you feel that that rewiring has happened. Each new paradigm is hard to get, but really worth it.

If you have a few languages under your belt, then I highly recommend the following method:

  1. Fix yourself a specific task,
  2. Write a program in a language from all paradigms that you know,
  3. Make sure your code is completely idiomatic,
  4. Stand back and see how the result is both 'the same' and 'completely different' at the same time.

Sample nice projects to get started on are a) a fully polymorphic quicksort implementation parametrized by both a comparison function and a partition function, b) an interpreter for a toy language (like the lambda calculus with integers and booleans), c) a type-checker for b). In languages that I like, each of these tasks is around 40 lines of code; in verbose languages, up to 200. [For b) and c), skip the parser, assume the input is an in-language data-structure].

Jacques Carette
A: 

Since you mentioned things like writing code on paper and similar, I'm going to share some of my experience with you:

First thing you may want to consider is to separate concepts of passing an exam and learning the programming language professors are teaching you. I think that this point is VERY important and here's why: In my faculty we do exams on paper. Usually there will be a couple of "theoretical questions" like Can in Java methods wait(), notify() and notifyAll() of class Object be redefined in sub-classes? or figure out what this C program prints :

#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
int i, a, b, c = 0, d;
      for(i=1;i<argc;i++) {
         d=atoi(argv[i]);
         if(i==1) a = b = d;
         else { if( a<d ) a=d;
                if( b>d ) d=d;
          c += d; }
printf("%d%d%d", a, b,c);
}

if arguments are 4 6 7 10

or something similar and a program which student has to write on a piece of paper.

I've also analyzed how several students I know studied and how they passed the exam.
We had some people who only studied from text-books, lecture notes and past exams. They usually scored relatively well on the exam because they focused on passing exam. They looked for patterns in exam problems which would often repeat and looked for most efficient ways to solve them from solutions of older exams and lecture notes. They also focused on memorizing as much code as possible and mixed and matched pieces in order to get solutions, basically practicing copy-paste programming. Such people often don't get comfortable using the programing language they learned! So instead of typing a simple C program to solve some repetitive problem, they'd often do it by hand. Also such people are often unfamiliar with ways of gaining information outside university. They haven't found good websites explaining problems they would need to solve in future. Another problem I've noticed is that they are often uncomfortable using some more "advanced" features of integrated development environments like debugging.

On the other hand there are people like me who learned the language by writing code and running it and analyzing it. Problems I've had are basically over-relying on computer. Modern IDEs have good code completion and easy to use debuggers. While I learned how to make programs which work well on a computer, I didn't learn so well how to analyze code without a computer. Simply I had no need to analyze what some über-1337 code does using pen and paper. My fist reaction is to fire up debugger and watch variables as the program executes. OF course if the exam is done on paper, I don't have debugger available. So while I understand in general what piece of code does, I can't quickly figure out what some function does which has several levels of recursion or something similar. That ability needs to be practiced! Another thing I've noticed is that on "practical" part of the exam, I'd often make an original solution which doesn't use pre-made elements from previous exams. They wouldn't be as simple as canonical answers, but they are product of my own work. Also I'm comfortable solving problems programatically and I have managed to pick up good sources of information on Internet and know how to use documentation in popular IDEs.

In the end there are also what I'd call "nerds". Those people would do their best to brute-force their way through exams. The would solve by themselves every past exam, memorize whole book and everything ever said during lectures and they would make tons of simple programs. Of course, they get great score and do learn the stuff, but in order to do that large sacrifices must be made!

So in the end after this wall of text, here's my answer: If you want to pass your exams, you should do your homework and problems in the book and on past exams. If you want to actually learn the language, you should write the code and then analyze it until you have good understanding what it does lastly and find bugs in it. You should find tools which will analyze the code and pint out problems in it, like for example Splint for C programs.

AndrejaKo