Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read source code learn how to use large system? [closed]

Tags:

open-source

Let's say you want to start contributing to an open source project with thousands LOC. I am interesting in ways/suggestions on how you would start learning/hacking the new system.

like image 573
Chrys Avatar asked Dec 02 '08 14:12

Chrys


People also ask

What is used to make source code easier to read and understand?

Documentation, running the code itself, other developers, and tests are all useful tools for gaining that level of understanding. They also come in handy for learning more details as needed.


4 Answers

Learn with a purpose. I think you'll learn best if you have in mind some goal -- fix this or add that functionality. Start looking for the likely places where you will need to make your changes. Follow threads of control backwards to find out how to get to that point in the code. Also, take a "bird's eye" view of the code -- look at the layout and structure. Good code will have descriptive names that tells you want each class and method is for. See if you can recognize implementation patterns and see where/how they are used. Don't put too much stock in the documentation -- documents can be excellent, but they are often out of sync with what the code really does. Let the code itself be the best documentation.

like image 107
tvanfosson Avatar answered Dec 21 '22 18:12

tvanfosson


If you want books that I found useful for learning how to learn from the code, I would check out Diomidis Spinellis's books Code Reading: The Open Source Perspective and Code Quality: The Open Source Perspective.

For your specific question, I would start with Code Reading. But both are good books.

like image 24
Thomas Owens Avatar answered Dec 21 '22 16:12

Thomas Owens


Skim through the code, looking for places where you think you know what is occuring. Read through those sections to see if your initial thought holds up, and then try modifying it to see if you can change it to do something else.

I'd suggest that this be guided slightly by the project roadmap so you can then move on to spotting where new features and bug fixes are so you can contribute in a meaningful manner.

Also, read the documentation and any spin-up documents that may exist (functional specs, requirement specs, etc). This can further help you learn the code ropes quicker :)

like image 40
workmad3 Avatar answered Dec 21 '22 17:12

workmad3


  • Do not spend too much time on small details.
  • Do not to try to understand the overall system at beginning.
  • The point is try to understand one module or component which is relatively "independent", which was added as one entity (feature) in the past. This is usually within the size limit your brain power can cope with because it was done by someone else at one time as one module.
  • Your understanding of the overall system will be improved after more components or "pieces" digested and assembled together.
  • Tools are very helpful: Doxygen + GraphViz, or a software such as "Understand", call and caller graph in Visual studio, "Find all" and "find all references", etc.
like image 23
Sijiang Du Avatar answered Dec 21 '22 18:12

Sijiang Du