Wednesday, November 12, 2008

How to browse source-code?

99% of your life is wasted is studying code written by someone else. And studying this code can be an awfully irritating task. (Although, studying codes written by TE/BE students can be a really pleasing experience. You can just lambaste them on every possible line! It is fun. Trust me. Simply log-on to the lab-server, access someone else's code. Don't worry about the permissions. Seems that PICT's lab assistants believe in open source. So, get someone else's code and vent your anger through comments. Don't forget to save the file :D)

Anyway, getting back to the point. There are few tools available which can make the task a bit simpler.
1) Etags
2) Cscope
3) Doxygen

My good friend Vedang has written enough about them. Here are the links to Etags and Cscope posts.

Personally, I think Cscope is just amazing. You can find functions which call this particular function and there is a regular expression search too. Etags is quick but primitive. I generally use Etags for simple browsing and Cscope only when Etags cannot help!

Tools aside, you also need to have a strategy for browsing source code. You cannot simply dig into the source code to understand how linux works. (Although, it may work if you are sufficiently genius.)
So, first try to get a doc explaining what the piece of code does. Having an insight into the working certainly makes browsing the code a lot simpler and faster. Then, use whatever-piece-of-software you have so that you know the inputs and outputs. Start with the source code only when you think you have a good understanding of the product.

Don't worry if you cannot seem to understand or remember anything the first time. Be persistent and you'll get the knack of it.

Browsing the source, btw, is a very good way to understand how people think. So, if you have a crush, go get her source code! :P

5 comments:

CDK said...

are we going to get info on doxygen or do we have to dig it up?? i mean u just mentioned it...are there more articles coming ?

Jitesh Shah said...

I havn't really used Doxygen. So, I guess you'll have to dig it up. and then write a blog post ... I'll link to it :D

Vedang said...

@cdk
we tried using doxygen once, but we were sold on cscope by then.. and didn't really check into the merits of it. Maybe you can do that and teach us something new :)

Anonymous said...

You can just lambaste them on every possible line!
Ahh! Fun times! :) You remember the awesome stuff we did? :D:D

Jitesh Shah said...

yeahhh!!!...
ha ha ... I just hope the girl didn't cry :P