tags:

views:

446

answers:

13

Possible Duplicate:
How do I begin reading source code?

I've been studying C++ and Lisp for a while now..

Bur, everytime I try getting others code to read. WOW, it seems like I am very very lost.

Anything has some tips?

thank you, Mario

+5  A: 

Be persistent.

That's the only way to really achieve everything hard.

Klaim
+1  A: 

There's a pretty good book on the subject that might help you out.

Robert Greiner
+2  A: 

If you can reformat a bit, it helps. For example, rework the indentation.

Everybody's code looks different and weird. Including yours only 6 months after you've last seen it. That's why it's important to document it very well, and to write clearly.

MPelletier
+1 for indentation! It can turn unreadable code into readable in minutes!
AndrejaKo
Faster depending on your IDE if it has automatic refactoring.
MPelletier
+3  A: 

I find that stepping through code within a debugger is a great way to see what it is doing. If you are unable to run the code, Klaim is right, be persistent.

linuxuser27
+11  A: 
  1. Try to practice reading on well documented and well structured code.

  2. Make sure to read the code alongside with running it in a debugger.

  3. Use a good IDE that lets you for example trace all places where function X calls (or find function Y's definition)

  4. Make sure to WRITE a lot of code. Reading pieces of code which resemble something you're written helps in understanding.

  5. To understand the structure and flow of the code, make data/call/process flow charts. Preferably by hand - it helps with memorization and understanding.

DVK
+1  A: 

Lisp (i assume CL) and C++ are to Language that are hard to read because they are both old and really, really big! CL and C++ have the to biggest language standards.

There is no trick have docs available, if you read lisp always have a repl to test things out or a debugger in C++. There is no silver bullet, its hard but it pays off because you gain knowledge on the language and the tricks people use.

Look for project that are know for sticking to common standard first. In some cases it is almost impossible because with templates and multiple inheritance (or macros in lisp) you can mess up really really bad. Avoid stuff like that if you don't have to read it (its not worth it).

nickik
+1  A: 

Using an editor that does syntax coloring can improve readability a lot.

neoneye
A: 

I find that thinking of a nice use-case and then dry-running the code and seeing where all the bits fit together is more useful that just reading the code from start to finish.

doron
A: 

Try going through the code one by one understanding each line of code clearly. Take your time to study the program. If you are trying to rectify someone's code then also check for upper-case and lower-case , also check whether statements are closed, opening and closing of brackets etc . Another idea would be to load the code in a editor that displays code, values etc in different color which would make it easy to understand and find errors in the code. Have patience and try to keep a calm mind. As Klaim said above u must be persistent and try to give indentation as needed. Practicing helps you understand more about the language also helps in learning some common and unusual coding techniques . Also asking the developer of the program for help in understanding could solve your problems very easily. And also pray to God before peeping into others code :P

subanki
+1  A: 

Well its a bit like learning to read, it takes a lot of practice, sometimes you think you got it right but often not. It just takes a lot of practice. You will notice an improvement the more you read other peoples code, but above all, write your own code. No programmers has ever become a programmer by just reading other people's code.

Anders K.
+1  A: 

One trick I find useful is to try to modify the code in some way. Say by adding a trivial feature or changing how some part behaves. This gives you some feedback if your understanding is actually right since you can test your understanding by running the new code.

Paul Rubel
A: 

You never learn better than reading other's code about how to write a code readable and understandable by others..

Just make a note of what makes difficult to understand other's code and don't do those when you start coding your own..

liaK
A: 

what helps me to understand how a fragment of code behaves under certain circumstances is to try to add some debug statements to monitor the state during runtime.

also try to get a big picture first and step into critical parts, which are still not clear.

jalbert