Tuesday, January 31, 2012

Learning a programming language

No matter what craft you're practicing, two things are very essential for making progress with that craft and getting better at it, wiz. Theory and Practice.


Theory:


1. Read (fundamentals of language)
    Reading about the language you're about to learn is the best way of starting off. Grab a book for fundamentals of that programming language. If you're a beginner, its better if you don't skip and keep reading it from the beginning. If you have prior experience of programming another language, it'll be easy for you.
  
2. Read the example code
    Reading the example code and trying to figure out what its doing is best practice for learning any programming language. Once you get to know about the language while reading, you can skip to reading example code whenever you get bored of reading theory.


Practice:
 
3. Type that example code yourself and run it.
    As you type the code yourself into the editor, you'll start getting a hint of whats going on in the program. And also you'll get familiar with the syntax of that programming language. The best practice is to add your own comments while rewriting code and try to explain WHY something is done.
    For example:
int calSquareArea(int side)
{
 return side*side; // returning square of 'side'   <-- Isn't it obvious? Duh! Not so  helpful, is it?
}

int calSquareArea(int side)
{
 return side*side; // formula to calculate area of square is side*side    <-- Ooh, now I get it!
}

4. Change it.
    Now that you know what the nuts and bolts of example code are, you can tweak it a bit and run again. As the program works differently each time you tweak and run it, you can make it to whatever you want. Its quite an useful skill to modify already existing code and make it do whatever it is that you want to do. You'll learn a lot by this trial & error method of learning a little bit everytime you change something in the program and re-run it.

5. Write your own code.
    Writing your own code is like making your own world with your own terms. You're the God of that world, you get to decide what happens in it. Sounds awesome, doesn't it? So start writing small piece of codes to do some tasks or solve problems. Personally, I would recommend to go after small games like tic-tac-toe. Write a huge number of such small programs. And then move on to taking big projects.

No comments:

Post a Comment