Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Program Understanding

News Recommended Links Recommended Papers Comprehension Slicing Outlining Literate programming Beautifiers
Code metrics Code Browsers Call graph analyzers Diff tools Xref tools Code review and inspections Humor Etc

Please note that one of the best editor that can help in comprehension and has built-in slicing facilities is probably XEDIT family (Kedit, THE, etc.). Some members of this family (THE) are free.

The second very useful and underused feature is outlining. The classical implementation of outlining can be found in MS Word, although without special macros MS Word does not support slicing.  It's important to note that Ms Word is probably the simplest way to implement "literate programming" in MS windows environment. I recommend to use HTML-mode. In many cases conversion of the source to HTML and working with HTML instead of ASCII text can lead to better software quality. In this case Source tree becomes a WEB page and can contain useful links from comments to other parts of the tree.

Dr. Nikolai Bezroukov


Notes:
  • This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Some amount of grammar and spelling errors should be expected.
  • The site contain some broken links as it develops like a living tree... Please try to use Google, Open directory, etc. to find a replacement link (see HOWTO search the WEB for details). We would appreciate if you can mail us a correct link.
Google Search
Open directory

Research Index

Old News ;-)

[Feb 4, 2008] Sunifdef 3.1.3 (Stable) by Mike Kinghan

About: Sunifdef is a command line tool for eliminating superfluous preprocessor clutter from C and C++ source files. It is a more powerful successor to the FreeBSD 'unifdef' tool. Sunifdef is most useful to developers of constantly evolving products with large code bases, where preprocessor conditionals are used to configure the feature sets, APIs or implementations of different releases. In these environments, the code base steadily accumulates #ifdef-pollution as transient configuration options become obsolete. Sunifdef can largely automate the recurrent task of purging redundant #if logic from the code.

Changes: Six bugs are fixed in this release. Five of these fixes tackle longstanding defects of sunifdef's parsing and evaluation of integer constants, a niche that has received little scrutiny since the tool branched from unifdef. This version provides robust parsing of hex, decimal, and octal numerals and arithmetic on them. However, sunifdef still evaluates all integer constants as ints and performs signed integer arithmetic upon them. This falls short of emulating the C preprocessor's arithmetic in limit cases, which is an unfixed defect.

[Jan 18, 2008] Slashdot Tools For Understanding Code

  • by MikeWB (1222682) on Friday January 18, @02:20PM (#22098390)
    The way I would handle this issue is by doing the following. 1) Learn what the system is supposed to do. Talk to the domain expert(s) and have them give you a walkthrough of the system. You have to understand what the software is supposed to do and how it works first. 2) Learn the entire UI. 90% of the functional requirements of a system will manifest themselves through the UI. 3) Define 2-3 Exemplary Use Cases With your knowledge of 1 & 2, define some typical system use cases. Now you are armed with enough information to begin learning the code. You can make assertions about the system. This means you know what to look for, you just are not certain what form it will be in. e.g. A widget processor will have some sort of workflow code to do so. 4) Trace Through The Code Now execute your use cases using the debugger to trace through the code. This will allow you to hit most all of the major subsystems in the application. 5) Comment the Code as You go Along As you read and learn the code, comment it! The next poor bastard who comes after you will be eternally grateful.

 

  • Stepping Through (Score:5, Insightful)

    by blaster151 (874280) * on Friday January 18, @11:38AM (#22094862)
    I've always found that stepping through the debugger at runtime is a decent way to start making sense of a large code base. Easier, anyway, than trying to read static code printouts. Just set a breakpoint at a point of interest, fire up the application, and use it as a starting point. You get a sense for program flow and it's a great way to generate questions--lots of them. (What does class SuchAndSuch do? It looks like the application is handling remoting in such-and-such a fashion; is that right?) You can also choose one aspect of the architecture and selectively ignore or step over other aspects, building up your understanding one aspect at a time. In my case, with Visual Studio as a development environment, I can hover the mouse cursor over variable names to see their current values. In the case of variables of a certain type, like datasets or XML structures, I can use realtime visualizers to browse the contents and get a much better feel for what's going on.

    If there's no one at your company that can help answer your questions and bring you up to speed, I feel for you - your employers ought to know enough to give you some extra margin. It can be very hard to take over a large code base without some human-to-human handover time.

    Also, is it an object-oriented system? I assume that it's not, based on your post, but you don't say either way. If it is, the important aspects of program flow often live in the interactions between classes and objects and the business logic is decentralized. OO is great, but it can be harder to reverse-engineer business logic because it's distributed among various classes. A debugger that lets you step through running code is almost essential in this case.
    •  

      Re:Stepping Through (Score:5, Insightful)

      by daVinci1980 (73174) on Friday January 18, @11:47AM (#22095068) Homepage
      This post is dead on.

      Place a breakpoint somewhere you think will get hit (e.g. main), and then start stepping over and into functions. I usually attack this problem as follows:

      Place breakpoint. Use step-in functionality to drop down a ways into the program, looking at things as I go. What are they doing, how do they work, etc.

      Once I feel like I understand how a section of code works, I step over that code on subsequent visits. If I feel like this isn't taking me fast enough, I let the program run for a bit, then randomly break the program and see where I am.

      Lather, rinse, repeat.

      Also, this should go without saying, but you should ask someone who works with you for a high-level overview of what the code is doing. The two of these combined should get you up to speed as quickly as possible.
    • Mod parent up (Score:5, Insightful)

      by mccrew (62494) on Friday January 18, @12:28PM (#22095944) Homepage
      Sorry, no points today to mod you up myself.

       

      I would suggest a slight variation on the theme. Fire up the application, start it on one of its typical tasks, and then interrupt it in the debugger to catch it. While the process is stopped mid-flight, take note of the call stack to see which classes and methods are being used. Maybe step through a few calls, then let the program run some more.

      By doing this repeatedly, you will quickly get a sense for which parts of the code see the most action, and would provide the most obvious places to start studying the code base, and provide the best bang-for-buck return on your time.

    • Not for a "large" codebase... (Score:4, Insightful)

      by smitth1276 (832902) on Friday January 18, @12:39PM (#22096182)
      That doesn't always work for a code base with millions of lines of atrociously written code. I've worked with code where it is absolutely not feasible to step through everything.

      It seems like in those cases I end up working from effects... I note some program behavior and then try to find exactly what causes that behavior, which can be surprisingly difficult if you are dealing with the "right" kind of code. After a while, though, the patterns begin to emerge in the system as a whole.
      • Re:Not for a "large" codebase... (Score:4, Insightful)

        by ChrisA90278 (905188) on Friday January 18, @02:45PM (#22098808)
        "That doesn't always work for a code base with millions of lines of atrociously written code. I've worked with code where it is absolutely not feasible to step through everything"

        You are correct. All these people talking about using a debugger and so on... That does NOT work on larger projects any on fairly simple ones. "Large" projects might have 250 source code files and thousands of functions or classes and likely a dozen or so interacting executable programs. I've seen print outs of source code that fill five bookcase shelves. No one could ever read that.

        I've had to come up to speed on million+ lines of code projects many times. The tool i use is pencil and paper

        The first step is to become an expert user of the software. Just run the thing, a lot and learn what it does. Looking at code is pointless untill yu know it well as a user.
    •  

      Re:Stepping Through (Score:4, Insightful)

      by JesterXXV (680142) <{jtradke} {at} {gmail.com}> on Friday January 18, @12:50PM (#22096430)
      I don't think there's any replacement for talking to the real-live developers who wrote it. Failing that, any design documentation they left behind. Failing that, just get a task to do, and try to get it to work. Nothing like learning by doing.
    • Re:Stepping Through by smitty_one_each (Score:2) Friday January 18, @12:50PM
      •  

        Tests (Score:4, Interesting)

        by gerddie (173963) on Friday January 18, @02:04PM (#22098084)
        Tests are indeed very good to understand a code base- Nearly all the last year I was working on a code base that nobody understood completely, although I had someone to ask about the general code structure. Writing tests helped me to understand what some parts of the code actually do. And where I needed to change things I could make myself sure that I didn't break anything.

        Another great tool is valgrind+KCachegrind - it gives you really nice call trees. Vtune can do something similar as well, but IMHO the output is not as good as in KCachegrind. The only problem, of course, is that valgrind makes your program very slow and, it is, AFAIK, not available on MS Windows.Vtune, OTOH, runs the program at normal speed, but it's calltree output is ugly, at least on Linux.

        If these two options are not for you than you might add a trace output to each function. IMO this is better than using a debugger - especially in C++ with BOOST and STL, where a lot of stepping goes through inline functions.With proper logging levels you can get a very useful output to see what's going on. It helps to understand the code, and it also helps, if you hit a bug.
    • Re:Stepping Through by Assmasher (Score:3) Friday January 18, @12:51PM
    • Re:Stepping Through by dannannan (Score:2) Friday January 18, @01:55PM
      • 1 reply beneath your current threshold.
    • Re:Stepping Through by superwiz (Score:3) Friday January 18, @01:57PM
    • Re:Stepping Through by psykocrime (Score:2) Friday January 18, @02:04PM
    • better: don't grok the codebase by jhoger (Score:2) Friday January 18, @03:32PM
    • 1 reply beneath your current threshold.
  •  

    Doxygen (Score:5, Informative)

    by Raedwald (567500) on Friday January 18, @11:39AM (#22094886)
    For C++ code, Doxygen [stack.nl] can be useful, as it shows the class inheritance. As requested, it uses a (rudimentary) parser. It works with several other languages too, although I can't vouch for its utility for them.
    • Re:Doxygen by PetriBORG (Score:2) Friday January 18, @11:49AM
      • Re:Doxygen by zeekec (Score:3) Friday January 18, @11:59AM
        • 1 reply beneath your current threshold.
      •  

        Re:Doxygen (Score:5, Informative)

        by Bill_the_Engineer (772575) on Friday January 18, @01:10PM (#22096854)
         
        Doxygen I thought did java-doc like parsing for C++? I was thinking he should look for something able to build a UML diagram based on the code... I hate UML, but if there isn't any documentation telling you the structures of the code it might be a place to look.

        Doxygen is more than a javadoc replacement.

        I like Doxygen + Graphviz. Just set Doxygen to document all (instead of just the code with tags) and set it to generate class diagrams, call trees, and dependency graphs and allow it to generate a cross reference document that you can read using your web browser. Set the html generator to frame based, and your browsing of code will be easier. I would also set Doxygen to inline the code within the documentation.

        I've use Doxygen to reverse engineer very large programs and had good luck with it. I will say Doxygen is not going to do all your work for you, but it will make your job easier. Especially if you add comments to the code as you figure each section out.

        Now if you like to see the logical flow of each method then try JGrasp (jgrasp.org). It has a neat feature called CSD that allow you to follow the logic of the code a little better. It's a java based IDE so that may be a turn off for you. I do whole heartedly recommend the Doxygen (w/ Graphviz).

        Good luck.

        • I agree by joggle (Score:2) Friday January 18, @03:10PM
        • Re:Doxygen by SpinyNorman (Score:1) Friday January 18, @04:15PM
    •  
      by Mr.Bananas (851193) on Friday January 18, @11:50AM (#22095130)
      I use Doxygen for C code, and it is really helpful. One of its most useful features is that it generates caller and callee graphs for all functions. You can also browse the code itself in the generated HTML pages, and the function calls are turned into links to the implementation. Data structures and file includes are also pictorially graphed for easy browsing.

      If the system you need to understand has a really big undocumented architecture, then this presentation [uwaterloo.ca] might be useful to you (there is a research paper, but it's not free yet). In it, the authors present a systematic method of extracting the underlying architecture of the Linux kernel.
    • Re:Doxygen by JamesP (Score:1) Friday January 18, @11:58AM
      •  

        Re:Doxygen (Score:4, Informative)

        by mhall119 (1035984) on Friday January 18, @01:28PM (#22097296) Homepage Journal
         
        Only problem is, it is a pain to configure. Also, windows versions don't look very stable.
        Windows version has been very stable for me, I've not had any problems with either Doxygen or Graphviz. It also includes a configuration wizard that is both easy to understand and powerful. There is also an Eclipse plugin that lets you configure and run Doxygen.
    • Re:Doxygen by mhall119 (Score:2) Friday January 18, @01:25PM
    • Re:Doxygen by QRDeNameland (Score:2) Friday January 18, @01:34PM
    • 1 reply beneath your current threshold.
  • When I was your age... by russotto (Score:1) Friday January 18, @11:40AM
  • Paper by raddan (Score:2) Friday January 18, @11:41AM
    • Re:Paper by plopez (Score:2) Friday January 18, @12:08PM
    • Re:Paper by bunratty (Score:3) Friday January 18, @12:15PM
      • Re:Paper by sdpuppy (Score:3) Friday January 18, @12:48PM
    • Re:Paper by jklappenbach (Score:1) Friday January 18, @12:24PM
      • 1 reply beneath your current threshold.
    • Re:Paper by cjonslashdot (Score:3) Friday January 18, @12:30PM
      • Re:Paper by raddan (Score:2) Friday January 18, @01:50PM
    •  

      Absolute tosh ! (Score:5, Insightful)

      by golodh (893453) on Friday January 18, @12:43PM (#22096258)
      An interesting post, even if it's absolute tosh. No-one in his right mind tackles a new code-base of any size or complexity with nothing but a printout. Not if he's expected to understand how it works and/or maintain it in a responsible way.

       

      In fact, it nicely highlights the difference between "software engineers" and "code monkeys". Code monkeys just dive in; they never pause to think. In fact ... they tend to avoid thinking. It's not their strong point. After all ... they're paid to code, right? Not to think. Software engineers on the other hand, look before they leap and spot the places where they need to pay attention first. And they're systematic about it.

      In fact, a software engineer will happily spend a day or two putting the right tools in place, *including* a full backup and a proper version management system for when he's going to have to touch anything.

      The first thing you want to know about a new code base (after you find out what it's supposed to be doing) is its structure. Tools like Doxygen (see previous posts) show you that structure *far* quicker and *far* more reliably than any amount of dumb code-browsing can. And besides ... once you do it, you've got that documentation stashed away securely instead of milling around incoherently in your head (you'll have completely forgotten most of what you read by next month) or on disorganised pieces of note paper.

      The second thing is to figure out if it calls any "large" functionalities like subroutine libraries or even stand-alone programs like databases, let alone if it makes operating system calls. The call-tree will give you an excellent view, and the linker files can complete the picture. You wouldn't be the first maintenance programmer who found out after months that his application critically depends on some other application he wasn't told about.

      The third thing is to see where your code does dirty things. Let the compiler help you. Just compile your application with warnings on and have a look at what the compiler comes up with. You might be surprised (and horrified). Then compile with the settings used by your predecessor and check that your executable is bit-for-bit identical to what's running (you wouldn't be the first sucker who's given a slightly-off code base).

      If performance is at all important, then running the whole thing for a night on a standard case under a good profiler will also tells you lots of important things. Starting with where your code spends its time, where it allocated memory and how much, and where the heavily-used bits of code are. All neatly written down in the profiler logs.

      Finally, run your application with a tool to detect memory management errors the first chance you get. Useful tools are Valgrind (in a Linux environment), Purify (expensive, but probably worth it) under Windows, and sundry proprietary utilities under Unix. Just about 90% of the errors made in C programs come from memory management problems, and half of them don't show up except through memory leakage and overwritten variables (or stacks .. or buffers .. or whatever). You'll need all the help you can get here, and as far as these errors are concerned, dumb code browsing is useless. Just keep your head when looking at reports from such tools ... they can throw up false positives. Ask around on a forum with specific questions if you're allowed, or ask your supervisor. After all ... you showed due dilligence.

      When you know all that (if you have the tools in place, all of this can be done within 1 day + 1 overnight run + 1 hour reading the profiler output), go ahead and trace through the code in a debugger. You'll be in a *far* better position to judge what you should be reading.

    • 1 reply beneath your current threshold.
  •  

    doxygen (Score:3, Informative)

    by greywar (640908) on Friday January 18, @11:41AM (#22094922) Journal
    If its in a language that doxygen can understand, thats the tool I would HIGHLY recommend.
     
  •  

    Ctags (Score:3, Insightful)

    by pahoran (893196) * on Friday January 18, @11:42AM (#22094948)
    google exuberant ctags and learn how to use the resulting tags file(s) with vim or your editor of choice
    • 1 reply beneath your current threshold.
  •  

    Old School (Score:5, Funny)

    Printouts and colored markers.
     
  •  

    Understand C++ (Score:5, Informative)

    by SparkleMotion88 (1013083) on Friday January 18, @11:43AM (#22094978)
    Sorry I don't have an open source tool for you, but I've used Understand for C++ [scitools.com] in the past and it was pretty helpful. To me, the most useful piece of information for understanding a large codebase is a browseable call graph. I'm sure there are simpler tools out there that generate a call graph, but this is the only one I've used with C++.
  •  

    RR & EA (Score:3, Informative)

    by Anonymous Coward on Friday January 18, @11:44AM (#22094988)
    Sometimes tools like Rational Rose [ibm.com] or Enterprise Architect [sparxsystems.com.au] are successful at reading in the code an building a UML model that you can then attempt to parse through. I'm not familiar with the use of either, but I know it can be done, with mixed results depending on the size and complexity of the code being analyzed. Both tools are fairly expensive though, I believe.
    • Re:RR & EA by wfeick (Score:2) Friday January 18, @12:07PM
  • Eclipse works extremely well for Java... by mario_grgic (Score:1) Friday January 18, @11:45AM
  • Reverse Engineer? by dotpavan (Score:2) Friday January 18, @11:45AM
  • lxr by Anonymous Coward (Score:1) Friday January 18, @11:45AM
  •  
    by theophilosophilus (606876) on Friday January 18, @11:47AM (#22095062) Journal
    Sorry about that.
  • Delete it! by Besna (Score:1) Friday January 18, @11:48AM
  • When I am particularly frustrated by antifoidulus (Score:2) Friday January 18, @11:48AM
  •  

    What I do (Score:5, Informative)

    by laughing_badger (628416) on Friday January 18, @11:48AM (#22095078) Homepage
    SourceNavigator : A good visualisation package http://sourcenav.sourceforge.net/ [sourceforge.net]

    ETrace : Run-time tracing http://freshmeat.net/projects/etrace/ [freshmeat.net]

    This book is worth a read http://www.spinellis.gr/codereading/ [spinellis.gr]

    Draw some static graphs of functions of interest using CodeViz http://freshmeat.net/projects/codeviz/ [freshmeat.net]

    Write lots of notes, preferably on paper with a pen rather than electronically.

  • Non-sequitur time by 14erCleaner (Score:2) Friday January 18, @11:49AM
  •  

    Answer (Score:5, Funny)

    by hey! (33014) on Friday January 18, @11:49AM (#22095116) Homepage Journal
    Yes. Understanding code is one of thing things you hire tools for.
    ...

    Wait, were you talking about software?
    • Re:Answer by WK2 (Score:2) Friday January 18, @12:16PM
      • Re:Answer by hey! (Score:2) Friday January 18, @12:21PM
  •  

    doxygen - with full source option (Score:3, Interesting)

    by mhackarbie (593426) on Friday January 18, @11:50AM (#22095122) Homepage Journal
    I agree with the previous recommendations for Doxygen. A while back I wanted to become familiar with the source code for a game engine and tried various tools to help with the 'grok' factor. I found the doxygen docs, with full source code generation in html, to be the fastest and most convenient way to walk around the code. After a while, it just clicked.

     

    Creating small demo apps that use the code can also help.

    mhack

    GNU Global (Score:4, Informative)

    by Masa (74401) on Friday January 18, @11:50AM (#22095134) Journal
    GNU Global is able to generate a set of HTML pages from C/C++ source code. This tool has helped me several times. All member variables, functions, classes and class instances are hyperlinks. It provides an easy way to examine source code. It also provides tags for several text editors (for Vim and Emacs especially). http://www.gnu.org/software/global/ [gnu.org]

    Umm.. documentation? (Score:5, Insightful)

    by Anonymous Coward on Friday January 18, @11:51AM (#22095144)
    Seriously folks, having spent large chunks of my working life having to decipher the mess of those who came before me I cannot stress enough the importance of clear comments, variable/function names, and consistent and readable syntax. AND WRITE F@#$%ing HUMAN READABLE DOCUMENTS DESCRIBING FUNCTIONAL REQUIREMENTS, ALGORITHMS USED, LESSONS LEARNED, ETC.
    Calling all your variables "pook" or the like may be very cute, but does not help me figure out what the heck the function is supposed to do or why I would ever want to call it. Yes it's a pain. Yes we're all under time deadlines and want to get it working first and go back and document it later. And yes, it WILL bite you in the ass (ever heard of karma? your own memory can go and then you have to decipher your OWN code!).

    That said, if you have inherited a code base from someone who ignored the above, go through and generate the documentation yourself. Write flow charts and software diagrams showing what gets called where and why. Derive the equations and algorithms used in each piece and figure out why the constant values are what they are. Finally, start at the main function or reset vector (I do a lot of microcontroller development) and trace the execution path.
  • Documentation Documentation Documentation by DrLang21 (Score:1) Friday January 18, @11:51AM
  •  

    Osmosis (Score:3, Insightful)

    by Greyfox (87712) on Friday January 18, @11:51AM (#22095150) Homepage
    If the original developer made useful comments that will help immensely. If there's a design document showing how the program fits together that helps a lot. If there's a process document explaining the business logic the application implements, that helps a lot. On average you'll start with a marginal code base with no comments, no design documents and no explanation of what the application is attempting to accomplish.

    Get the guys who use it to explain what they're trying to do, read the code for a couple of days and then have them show you how they use the application. Then plan on six months to a year to get to the point where you can look at buggy output and know immediately where the failure is occurring. In the mean time just work in it as much as you can and don't try to redesign major parts of it until you know what it's doing.

     
  • Muhahaha by roman_mir (Score:2) Friday January 18, @11:53AM
  • Read The Fine Manual by frith01 (Score:1) Friday January 18, @11:54AM
  • Reading code is no good to start with. by pt99par (Score:1) Friday January 18, @11:57AM
  • Codesurfer by ximor_iksivich (Score:1) Friday January 18, @11:58AM
  • I have an idea by Anonymous Coward (Score:1) Friday January 18, @11:58AM
  • Source Insight or SlickEdit by dgoldman (Score:1) Friday January 18, @11:58AM
  • hmm. by apodyopsis (Score:2) Friday January 18, @11:59AM
    • Re:hmm. by SageinaRage (Score:2) Friday January 18, @02:31PM
    • 2 replies beneath your current threshold.
  • Just Do It by BAH Humbug (Score:1) Friday January 18, @12:00PM
  •  
    by Anonymous Brave Guy (457657) on Friday January 18, @12:01PM (#22095364)
    I'm afraid you've set yourself an almost impossible task. IME, there are no shortcuts here, and it it's going to take anywhere from a few months to a couple of years for a new developer to really get their head around a large, unfamiliar code base.

    That said, I recommend against just diving in to some random bit of code. You'll probably never need most of it. Heck, I've never read the majority of the code of the project I work on, and that's after several years, with approx 1M lines to consider.

    You need to get the big picture instead. Identify the entry point(s), and look for the major functions they call, and so on down until you start to get a feel for how the work is broken down. Look for the major data structures and code operating on them as well, because if you can establish the important data flows in the program you'll be well on your way. Hopefully the design is fairly modular, and if you're in OO world or you're working in a language with packages, looking at how the modules fit together can help a lot too. Any good IDE will have some basic tools to plot things like call graphs and inheritance/containment diagrams, if not there are tools like Doxygen that can do some of it independently.

    If you're working on a large code base without a decent overall design that you can grok within a few days, then I'm afraid you're doomed and no amount of tools or documentation or reading files full of code will help you. Projects in that state invariably die, usually slowly and painfully, IME.

  • Tools For Understanding Code? by mattboston (Score:1) Friday January 18, @12:04PM
  • kcachegrind by Akatosh (Score:2) Friday January 18, @12:04PM
  •  

    Look at doxygen/umbrello (Score:3, Informative)

    by Yiliar (603536) on Friday January 18, @12:04PM (#22095458)
    See:
    http://www.stack.nl/~dimitri/doxygen/ [stack.nl]
    and:
    http://uml.sourceforge.net/index.php [sourceforge.net]

    These tools allow you to 'visualize' a codebase in several very helpful ways.
    One important way is to generate connection graphs of all functions.
    These images can look like a mess, or a huge rail yard with hundreds of connections.
    The modules, libraries, or source files that are a real jumble of crossconnected lines are a clear indication of where to start clean up activities. :)

    Good luck!
  •  
    by crovira (10242) on Friday January 18, @12:08PM (#22095546) Homepage
    That should be good for a laugh or three.

    They'll be out of date, full of inconsistencies and incomplete.

    Then you'll be reading the code only to discover that people's idiosyncrasies and personalities definitely affects their coding styles. (There's even some gender bias where women tend to set a lot of flags [sometimes quite needlessly] and decided what to do later in the execution while men code as if they knew where they were going all the time, just that when they get there, they're missing some piece of information or other.)

    If you read code developed by a whole team of people, you'll get to know them, intimately.

    Good luck. You'll be at the bar in no time... I kept the stool warm for you.
  • The Classics by Dunx (Score:2) Friday January 18, @12:09PM
  • massive printfs by cathryn (Score:1) Friday January 18, @12:13PM
  •  

    The Slashdot attitude (Score:3, Insightful)

    by gaspyy (514539) on Friday January 18, @12:19PM (#22095734)
    I'm appalled by some of the comments that imply that the poster may not be fit for the job.

    A few years back I had to maintain a large module written in C#. I had about 200K lines of code, 50 classes, zero documentation, zero comments, zero error logging support, and I was expected to find and fix bugs and add functionality the day after the module was handled over.

    So if you were never in this position, just STFU. Yeah, the code is there, but is this flag for? Is this part really used, or is obsolete? What are the side-effects of using that method? And so on...

    Eventually, I learned it, especially after some intensive debugging sessions, but it was frustrating to say the least. I would have loved to have some aiding tools.
  • Where be dragons? by mm4 (Score:2) Friday January 18, @12:24PM
  • Sounds like a lack of documentation... abuse it. by Eternal Annoyance (Score:1) Friday January 18, @12:26PM
  • Reverse Engineering Tools by kaladorn (Score:2) Friday January 18, @12:26PM
  • Only 2 tools needed by spazoid12 (Score:1) Friday January 18, @12:26PM
  • Explain the code to someone else. by Organic Brain Damage (Score:2) Friday January 18, @12:28PM
  •  

    HTML based cross reference (Score:3, Interesting)

    by NullProg (70833) on Friday January 18, @12:32PM (#22096034) Homepage Journal
    Run these commands (or put them in a script):

    ctags *
    gtags
    htags -Fan

    It will create a ~\HTML folder with all the function/variables cross-referenced. Open the file index.html or mains.html in your browser. If your not running Linux, I think these utilities are included in cygwin http://www.cygwin.com/ [cygwin.com]

    Enjoy,
  • Browse-by-Query by mmacdona86 (Score:2) Friday January 18, @12:32PM
  • Headers by 12357bd (Score:2) Friday January 18, @12:34PM
  • This should be the longest thread in /. history. by mcmonkey (Score:2) Friday January 18, @12:39PM
  • You need to understand more than just the code by h2o2 (Score:1) Friday January 18, @12:45PM
  • i feel for ya by pak9rabid (Score:1) Friday January 18, @12:50PM
  • Doxygen by flyingfsck (Score:2) Friday January 18, @12:53PM
  •  
    If your project is object oriented, you may be able to get your UML modeling tool to import the code and visualize the classes. When you do this, you'll probably get a HUGE diagram that seems just as unwieldy as looking at the code. The trick is to apply a filter to the model, so you're not overwhelmed with detail. Your UML tool should be able to do that for you.

    I recommend focusing on all interface classes first. This can give you a remarkably sane picture of a system, and will help you divide up the code into more conceptually meaningful chunks.

    The tool I use is Enterprise Architect [sparxsystems.com], which does quite a lot of heavy lifting yet is still inexpensive enough for me to own a personal copy.
  •  

    Solution (Score:5, Funny)

    by Chapter80 (926879) on Friday January 18, @12:54PM (#22096530)
    I've always found that the most effective method of learning code is to inject a random line of code somewhere, and see what breaks. Two techniques: 1) print some official-looking error message, and 2) add a large value (a million or greater) to a number somewhere. Keep a nice chart of what you added, where:

     

    Error 'Format Conversion Error, converting from Y2K to Z2L' added to module x1
    Error 'Out of Memory Banks' added to module x2
    Error 'Object Expected; found adjective instead' added to module x3
    Error 'bitbucket 95% full; please empty' added to module x4
    Added 1,000,042 to some random value in module x5
    Added 5,555,555 to some random value in module x6

    Not only will you learn about the code, you'll make a great impression on your boss, when, within minutes, you are able to resolve some mysterious problem that has never happened before.

  • Is what you get by aled (Score:2) Friday January 18, @01:02PM
  • Ask somebody who has worked on it by sneakyimp (Score:1) Friday January 18, @01:02PM
  • Log Messages by mitchell_j_friedman (Score:1) Friday January 18, @01:05PM
  • No substitute... by pottymouth (Score:1) Friday January 18, @01:10PM
  • Roll your own tool? by Spinlock_1977 (Score:2) Friday January 18, @01:13PM
  • Keep a log by durin42 (Score:1) Friday January 18, @01:17PM
  • I've used QA/C and VectorCast... by Simon Brooke (Score:2) Friday January 18, @01:20PM
  • Use profiling debuggers by bacchu_anjan (Score:1) Friday January 18, @01:22PM
  • Nothing beats... by Babu 'God' Hoover (Score:1) Friday January 18, @01:23PM
  •  

    More than tools (Score:4, Interesting)

    by sohp (22984) <(moc.oi) (ta) (notwens)> on Friday January 18, @01:31PM (#22097350) Homepage
    The best tool is your brain, applied liberally. Here's some thoughts to put in it

    Feathers, Michael. Working Effectively with Legacy Code [amazon.com], Chapter 16 especially.

    Spinellis, Diomidis. Code Reading: The Open Source Perspective [amazon.com], Chapter 10 lists some tools for you.

    My own thoughts now. First, don't trust the comments, they are probably outdated. Second, if it's a big code base, forget the debugger. Write some little unit test cases that exercise the sections of code you need to understand, and assert what you think the code is supposed to do.

    Finally, unless you are cursed with a codebase which is not kept in version control (in which case, ugh, time to start the jobhunt up again maybe), then take a look at the revision history. See what changes have been made to the area you are working on. With luck, someone will have put in a revision message that points you towards greater understanding of why a change was made, which will in turn nudge you towards knowing the purpose of the section of code that was change.

     
  • Tools of the trade by EvilXenu (Score:1) Friday January 18, @01:31PM
  • Crystal REVS by lordmage (Score:1) Friday January 18, @01:38PM
  • Use a DSM to understand the architecture by scott151 (Score:1) Friday January 18, @01:40PM
  • Document A Project by rrobbins (Score:1) Friday January 18, @01:41PM
  • Read the docs. by KillerCow (Score:1) Friday January 18, @01:43PM
  • three letters by fdisk3hs (Score:1) Friday January 18, @01:46PM
  • UML for Understanding code by clintt (Score:1) Friday January 18, @01:46PM
  • Profiler by Myshkin (Score:2) Friday January 18, @01:50PM
  • Fulltext search for dynamic technologies by bandannarama (Score:1) Friday January 18, @01:52PM
  • What do I use? by JerryLove (Score:1) Friday January 18, @01:53PM
  •  
    My main tool for figuring it all out was to use exuberant ctags [sourceforge.net] to create a tags file, and Nedit [nedit.org] to navigate through the source under Solaris, with a little grep thrown in. I also used gdb with the DDD [gnu.org] front-end to do a little real-time snooping.

     

    I've since added both cscope [sourceforge.net] and freescope [sourceforge.net], as well as the old Red Hat Source Navigator [sourceforge.net] for good measure.

  • VHDL? by Alexpkeaton1010 (Score:1) Friday January 18, @02:02PM
  • Understand? by iso-cop (Score:1) Friday January 18, @02:14PM
  • Did anyone mention the Linux Cross Reference by malk315 (Score:1) Friday January 18, @02:16PM
  • Learn What the System Does First by MikeWB (Score:1) Friday January 18, @02:20PM
  • My two tools by GrEp (Score:2) Friday January 18, @02:26PM
  • Lots of Bad Advice Here... by RobDude (Score:1) Friday January 18, @02:26PM
  • Sourcepublisher by Uosdwis (Score:2) Friday January 18, @02:57PM
  • no easy way by maestroX (Score:1) Friday January 18, @03:02PM
  • Here's what I do. by Haszak (Score:1) Friday January 18, @03:21PM
  • easier yet... by kellyb9 (Score:1) Friday January 18, @03:38PM
  • 2 ideas: Class-based local Variables w/ Labels by rfc1394 (Score:2) Friday January 18, @03:42PM
  • Re: Tools For Understanding Code? by datadigger (Score:1) Friday January 18, @04:01PM
  • Not open source but very useful by malsmith (Score:1) Friday January 18, @04:28PM
  • Lazy by Quickfingers (Score:1) Friday January 18, @04:29PM
  • Source Insight, Zynamics binnavi by jdp (Score:1) Friday January 18, @05:06PM
  • Tools and Techniques by choch (Score:1) Friday January 18, @05:06PM
  •  

    Source Insight (Score:3, Informative)

    by Effugas (2378) * on Friday January 18, @05:22PM (#22101634) Homepage
    It's inexpensive, and scales astonishingly. I've spent the last two years in it, and it's just how I audit code nowadays.
     
  • Rt. Click - Find All References by boatboy (