Slashdot Mirror


Source Code Browsing Tools?

Marco Sanvido asks: "I often look at source code (especially C, but this question is valid for other languages as well) and I have a really hard time in understanding how it works. Documentation is often missing or quite outdated, and the only way to see how the program works is to try to understand the source code. Which tools do you prefer to use for browsing and studying source code? So far I have used LXR for Linux, Eclipse for java, and CScope, but I'm not sure that these tools are the best solution." It's tempting to flood this question with answers for your IDE, but the key thing here is _browsing_, not _development_. What decent, lightweight programs would work well as source code viewers?

12 of 165 comments (clear)

  1. Re:A couple of options by diverscuba023 · · Score: 2, Interesting

    The only problem with doxygen is the amount of time it takes to generate the documentation for an entire project. I had one project it would take almost 48 hours to produce the documentation for and it could not generate the graphs for two of the hiearchies since they were too big. The source code was only about 500K lines.

  2. JEdit by ChaseTec · · Score: 2, Interesting

    I needed an easy to use C source code browser because I'm porting an old bbs game to Java. JEdit fit the bill perfectly. Out of the box it's not much more then a text editor with syntax highlighting(130+ languages). It has a feature call HyperSearch that can be used for search through single files or multiple files and have a little box of hyperlinked results. It has lots of plugins to extend it's funtionality but nothing extra to get in the way when you first install it. Check it out at jedit.org. The only thing some people might take issue with is that it requires Java.

    --
    My Hello World is 512 bytes. But it's also a valid Fat12 boot sector, Fat12 file reader, and Pmode routine.
  3. gdb by Bastian · · Score: 4, Interesting

    I'm actually a fan of using a debugger to step through code I'm trying to understand. I can let it keep track of the call stack for me and it saves me from having to manually surf around multiple source files to figure out where the next function I need to look at is.

    It's not a good way to figure out how every nook and cranny of the code works, but it's great for an initial scan-through to see the overall structure of a module. And if you are at liberty to throw in an embeddable scripting language (I use F-Script) you can poke and prod at anything you want with ease.

    1. Re:gdb by marcosdumay · · Score: 2, Interesting

      Use GDB inside of Emacs (M-x gdb) That way, you have an entire buffer to navigate through the code, while the debugger output is displayed on another buffer. And, yes, the code buffer is always actualized to the running instruction when the debugger beaks.

  4. Source Insight by Anonymous Coward · · Score: 2, Interesting
  5. Re:OpenGrok by Anonymous Coward · · Score: 2, Interesting

    That looks very interesting but the requirement page lists a servlet container, such as Glassfish or Tomcat, just to use it. Is there a way to use it without installing Tomcat or Glassfish or is it primarily a web app? I have no interest in any of the online functionality it offers and requiring a servlet container seems to be overkill for my needs. Running Tomcat or Glassfish in the background simply for this application definitely removes it from being a "lightweight" option.

  6. FishEye by pajama · · Score: 2, Interesting

    If you develop in Java you could try FishEye:
    http://www.cenqua.com/fisheye/

  7. A query language for browsing by mmacdona86 · · Score: 2, Interesting

    To plug a personal project of mine--
    Browse-by-Query is a database for code with a query language specifically designed for finding things in code.
    I was dissatisfied with fixed-function browsers, so I developed this.
    Use expressions more powerful than regular expressions to search through and understand your codebase.
    Works only with Java now (there's a standalone version and Eclipse plugin) but I hope I (or someone else) will extend it to others.

  8. Understand for C++ by barries · · Score: 2, Interesting

    We use Understand for C++ (link is to the index of all "Understand for..." family members) when reviewing and designing formal unit tests for our clients' code. It's extremely useful for manual static analysis: understanding structure and inter-relatedness, so to speak.

    However, to understand dynamic behavior you should look at various tracing options, even the lowly printf(), or try stepping through in a debugger. The larger, more complex and the more object-oriented the code, the more important understanding the dynamics are.

    Anyway, Understand for C++ is much more interactive than any of the free comment extraction or cross reference tools and the database has a Perl API, though we've not had a chance to use it. It's worth the price if your doing this as part of your job.

    - Barrie
  9. Emacs by sdfad1 · · Score: 2, Interesting

    I know you said no IDE's, but if you merge well with Emacs, it can do the work too. Emacs is not exactly a heavy weight, depending on how you install it (it's often built into your distro anyway). It uses this thing (I don't really know it that well to be honest) called tags - ctags or etags.

    Basically you run etags (check your man pages) from the command line that will parse through your source files and create a lookup table in a file (name TAGS by default I think). While browsing the source file, you just have to position the cursor at the right symbol, and press M-. (that's usually Alt-DOT) and it'll take you to the function definition. (vim has a similar thing)

    I haven't used it too much, since I'm a Lisper, and the Slime development environment (Emacs addon mode) for Lisp has a similar thing (and it doesn't need to create any tables beforehand) that also provides a "stack-like" functionality. That means you can jump to the function definition, then pop back to where you were. This can be handy for quick detours just to lookup small functions for example.

    The advantage here is that you have the all the files locally, so it's faster than browsing through a web interface (html-ized source files, like the Sourceforge CVS frontend - I still use that a lot, and it is SLOW), and you can also edit the source (just a bonus).

  10. Re:Nothing Can Beat a Good Editor by Anonymous Coward · · Score: 1, Interesting

    Vim is not much lighter then Emacs, strictly speaking it actually is an emacs (not by keyboard layout, but by programability). They both are light compared to the IDEs of today.

  11. Not *browsing* but *understanding* by PurplePhase · · Score: 3, Interesting

    Unfortunately the story poster was a bit vague. They could mean that they or the person assigned don't read code, yet they need to know how a program works, or what it does. There are many times when you don't want to or cannot run/debug a program to analyze it.

    There have been many links posted which I'm going to have to explore - not the editor links (jEdit and Emacs rulz!) but the conceptualization links. Unfortunately most if not all IDEs are still code-file based. The most prominent other tool for project conceptualization is UML which has been gaining IDE integration. Yet there are still a couple problems with that:

    1. The UML usually generates accurate structures for classes, but doesn't or cannot generate execution diagrams (what, 4 types in UML?) or state diagrams.

    2. These static diagrams represent only the level of the code instead of being an interactive object with drill-downs or abstract-up commands!

    To understand a new set of code or codebase, I need something that analyzes the code and reports back to me on its tactics and strategies - what patterns are used, what weaknesses are in the code, ... Current tools give you unuseful amounts like cyclomatic complexity, or other ratings like test coverage or Fowler's class interdepence/brittleness/(whatever) measure. However those things are useful to me only: if you know nothing about code, have any resources to plug testing holes, or are actively managing a codebase, respectively. None of them say what the code *does* or how it does it. So we need something that covers concerns orthogonal to what already exists.

    Which makes me more curious about the comment asking if anyone uses the tools researchers are working on for visualizing a project. I haven't kept up on academics - where do I start looking? And is there anything there with demos, products available, or in post-beta releases?

    8-PP