Slashdot Mirror


Source Code Browsers?

patonw asks: "I just started working for a company as a programmer on a project with a huge existing codebase. The person hiring me half-jokingly said that it usually takes new employees two years before they understand the system. What I am looking for is not just an editor/browser but a program that displays functions and classes as connected graphs -- preferably free. I would like to view how programs are structured by function calls and class relations. I have access to several different kinds of platforms/operating systems."

67 comments

  1. What is is with slashdot by bitsformoney · · Score: 0, Flamebait
    that everyone is asking for code analysis software these days? There was a story just a couple of days ago already.

    The truth is, that I have done a lot of research on the Internet to find suitable stuff for this problem. There is none. Period.

    --
    This comment is printed on 100% recycled electrons.
    1. Re:What is is with slashdot by Anonymous Coward · · Score: 0

      fucking morons want us to do their work for them.

      these specs are the requirements of a couple of different government grant projects. These morons haven't even done the write-up for the grant proposal yet (due date coming up soon!) and are out fishin' ("trolling" would be the right word for civilians, but that word has the wrong emotional context on /.) for freebies.

      lazy little fuckers.

  2. KDevelop can help by Zoko+Siman · · Score: 1

    If it's a c++ project KDevelop will show you a list of functions and classes and what files they're in. Things of that nature. Try it out, it's free.

  3. Source Navigator by IYagami · · Score: 5, Informative

    Sponsored by RedHat:

    http://sourcenav.sourceforge.net/

    From the FAQ:
    Source-Navigator supports C, C++, Java, Tcl, [incr Tcl], FORTRAN and COBOL, and provides and SDK so that you can write your own parsers.

    Use Source-Navigator to:

    * Analyze how a change will effect external source modules.
    * Find every place in your code where a given function is called.
    * Find each file that includes a given header file.
    * Use the grep tool to search for a given string in all your source files.

    1. Re:Source Navigator by AiY · · Score: 1

      sourcenav is pretty cool. I used it to learn a very complicated C++ codebase - really helped. Of course when I showed it to a someone who started recently, he asked why I just didn't use vi & tags. I didn't have good response.

      --
      "You need a license to buy a gun, but they'll sell anyone a stamp." - Red Green
    2. Re:Source Navigator by statusbar · · Score: 2, Interesting

      Which tags programs works with c++ effectively? Is even a subset of what sourcenav indexes available?

      If there is one, I'd love to see it.

      --jeff++

      --
      ipv6 is my vpn
    3. Re:Source Navigator by hughk · · Score: 1

      This is just a "me too", but I also found sourcenav great for getting into a big legacy C++ project. I did have stability problems but I had to run the Windows version because the AIX backend was so ancient that I couldn't build on that platform. It meant I needed frequent saves of the project but otherwise fine.

      --
      See my journal, I write things there
    4. Re:Source Navigator by Anonymous Coward · · Score: 0

      Perl is noticeably absent from the list of languages that SN supports. Any good free/cheap code browswers for Perl?

      kj

  4. Doxygen by Tersevs · · Score: 3, Informative

    I havnt heard about any free source browsing programs... But I've been using Doxygen to generate HTML documentation of the source when I need to familliarize myself to new code. Definitions in the documentation will be hypertext linkes and there are class inheritance graphs generated. What's missing is really some kind of call-tree but you cant have everything. Doxygen also extract JavaDoc comments from C++ code and insert them into the HTML-documentation.

    Doxygen can also generate LaTeX, and RTF files instead of HTML.

  5. Doxygen for C++ / C etc by ssclift · · Score: 3, Informative

    Doxygen is a good choice for C++, C, Java, Objective-C, IDL... I used it to get into a ~50K line project a few years ago and have used it regularly whenever I'm forced to use C++... Get Graphviz as well so Doxygen can draw pretty pictures for you.

  6. Doxygen by DeadMeat+(TM) · · Score: 4, Informative
    Doxygen can use Graphviz to generate class and call graphs for several different languages. It helps to have Doxygen or Javadoc annotations in the code, but it's not necessary.

    Unfortunately graph generation is pretty slow, but otherwise it's a fantastic tool.

  7. Meh by cookiepus · · Score: 3, Insightful

    If your codebase is anything like what I've been working with, there's no tools that are going to make your life easier.

    If the code had decent structure, you'd not be asking this question. But it's a mess. And if you display the mess as a tree structure, it's still a mess. The value is limited.

    The best thing I've done is set up etags accross the entire codebase. This way I can at least navigate code easier. But I doubt you will understand anything more from tree graphs.

    1. Re:Meh by _flan · · Score: 3, Interesting

      I don't think that's entirely a fair statement. I find that being able to visualize a codebase can help significantly -- even when it is a mess.

      Where I work we have some home-grown (and not terribly good) tools that help us visualise a project's architecture, from both the design and the implementation point of view. For projects that are good, these two views mesh perfectly. For projects that are crap, they diverge wildly. This gives a you a good idea where a little refactoring might to a lot of good. When working on a new code base, I start like this -- making small, incremental changes, documenting places that I find difficult to understand, and above all talking with more experienced developers.

      Also, as someone that hates to write documentation, I find it invaluable when trying to describe large systems. But my documentation always has pictures, because they are fundamentally easier to grasp quickly than ten dense pages of text. Unfortunately, it's difficult to put good diagrams in comments.

      (As an aside, back in my university days, I worked on a project where we did all of our coding in FrameMaker. This allowed us to put in pictures, colored comments -- basically anything. The build script turned the FrameMaker file into C++ source, which then got compiled. It was kind of the extreme version of self-documenting code.)

  8. Debug by rmull · · Score: 3, Insightful

    This is perhaps a tangential answer, but I do much better by going through the code with a debugger and watching things happen. Especially with some of the more compilacated OO stuff, and when the comments are unhelpful or wrong, it can be much more useful than reading the code.

    --
    See you, space cowboy...
    1. Re:Debug by Fizzl · · Score: 2, Interesting

      Amen.

      Have you ever been porting/documenting/something someone elses Symbian C++ code? It's fricking hilarious. Symbian forces certain design principles upon you, but the design is so arcane for the small pieces of software, it makes it next to impossible to decipher someone elses Symbian code.
      Especially if the previous developer has adopted the "correct" way of structuring app/ui/doc/view in different files plus followed the UI/Engine guideline too. Ofcourse you must do everything asynchronously with Active Objects (aka. poor man's threads)

      "Hello world" takes atleast 300 lines and walking through it in debugger (assuming you want too see and understand each line) takes an hour or so. ..Hmm This turned into a rant. Oh well, I already wrote it so here goes. 'Submit'

    2. Re:Debug by Bat_Masterson · · Score: 2, Informative

      Of course, that presumes that you have a decent set of functional tests that cover the code well in order to get a good idea of what is going on. Of course, the permutations involved on a moderate to large code base could be far more than you could keep in your head...

    3. Re:Debug by slapout · · Score: 1

      Assuming, of course, that they let you have a debugger, unlike my last employer...

      --
      Coder's Stone: The programming language quick ref for iPad
    4. Re:Debug by GlassHeart · · Score: 2, Insightful
      I do much better by going through the code with a debugger and watching things happen.

      That can tell you what is actually happening, but not what the original programmer wanted to happen, or why he needs it to happen.

      when the comments are unhelpful or wrong, it can be much more useful than reading the code.

      Not to be facetious, but how do you know it's the comments, not the code, that are wrong?

    5. Re:Debug by AsbestosRush · · Score: 1

      That can tell you what is actually happening, but not what the original programmer wanted to happen, or why he needs it to happen.

      Best example of the above: Mel.

      Not to be facetious, but how do you know it's the comments, not the code, that are wrong?
      Most coders update the code, not the comments. If the code works, and the comments don't corrospond, it's the comments that are borked, IMO.

      Hell, I've even been guilty of this stuff on my own projects, even tho they're only simple PERL stuff. I go back 3 months later to add functionality and say "This is what I said, but I'm obviously not doing that anymore". I usually take the time and correct the comments then, however. :D

      --
      EveryDNS. Use it. It works.
      AC's need not reply
  9. Meh-AI. by Anonymous Coward · · Score: 0

    "If your codebase is anything like what I've been working with, there's no tools that are going to make your life easier."

    Were's Artificial Intelligence when you need it?

  10. What is it with slashdot-Reenginering Perl. by Anonymous Coward · · Score: 1, Funny

    "that everyone is asking for code analysis software these days? There was a story just a couple of days ago already."

    I suspect some's trying to reengineer Slashdot's code.

    1. Re:What is it with slashdot-Reenginering Perl. by bitsformoney · · Score: 1

      I suspect you suspect right.

      --
      This comment is printed on 100% recycled electrons.
  11. SHriMP/Creole, JQuery by Earlybird · · Score: 3, Informative
    SHriMP (screenshot):

    • ... designed for visualizing and exploring software architecture and any other information space. SHriMP (Simple Hierarchical Multi-Perspective) is a domain-independent visualization technique designed to enhance how people browse and explore complex information spaces. Among the applications we are actively exploring is the exploration of large software programs, and the understanding of complex knowledge-bases (via the Protégé tool)."

    Currently SHriMP runs both as a standalone application and, using the Creole plugin, inside Eclipse to augment its existing, extensive code browsing capabilities. There's also a plugin for Protégé, a Stanford project to build "an ontology editor and a knowledge-base editor" supporting new techologies such as OWL.

    While Creole is currently Java-specific, SHriMP is a generic framework for code visualization.

  12. JQuery by Earlybird · · Score: 1

    I was actually going to mention JQuery, but changed my mind. But some people might find it useful.

    1. Re:JQuery by bitsformoney · · Score: 1

      This is actually very interesting. I have thought of doing prolog-like querying on the parse tree before, but never dared to ask for it.

      --
      This comment is printed on 100% recycled electrons.
  13. my favorite code bomb.... by St.+Arbirix · · Score: 2, Informative

    Doxygen does exactly what you described. See item #2 in the link.

    If that doesn't work look up programs that will convert to UML. Since you didn't mention it in your question I'll expand: Unified Modeling Language diagrams are a standardized means of describing the relationships between objects in classes. To any Slashdotters out there in college looking to take a software engineering course, you'll be seeing a lot of UML.

    --
    Direct away from face when opening.
  14. CAST by drsDobbs · · Score: 1

    Sometime ago I used Cast for this purpose. I think it's currently called Cast Enlighten (http://www.castsoftware.com/Products/platform/AMS /Enlighten/Features.html. It's a big and complex (and probably costly) product, but it really does the job. It covers lots of languages and it is even able to drill down from e.g. java into Oracle stored procedures.

  15. Roll-your-own by Tablizer · · Score: 2, Informative

    I tend to roll-my-own code analyzers because each system tends to have a different personality and there are different things to look for. Generally I try to parse the code and log each file, module, and subroutine into a relational database. Then I can query it later as needed. I also may log every variable and and token, filtering out common key-words. This risks over-indexing but is better than under-indexing becase extra tokens are less of a problem than non-indexed tokens. And, one can adjust the indexer to remove the extra ones over time. (Ideally one should parse it using perfect grammar parsers, but that is not always an option, especially with web stuff that mixes multiple languages.)

    Then I log all tables and columns of the databases (data dictionary). Once all the tables, columns, variables, subroutines, and files are logged in database tables, one can cross-reference it all either batch-wise and/or using ad-hoc queries. It is just regular database stuff at that point, so one is no longer dealing with code text but SQL (but I still like FoxPro for such because of its informal nature). However, it may launch a code viewer to inspect matches.

    It takes about 3-days to a week to do all this if you have done it before and know your tools, plus future tweaking to make improvements.

    I have seen commercial tools that do similar things for a lot of money. But to be frank, if someone besides you will be using such a tool and they don't like using SQL, then a commercial product may have a more mature user interface. They also don't bring complaints to you when there are glitches or omissions in the parser.

    1. Re:Roll-your-own by Anonymous Coward · · Score: 1, Insightful

      Bryce Jacobs, be quiet. I crapped out more code this morning than a broken-down obsolete relic of DOS 3.3 like you could ever comprehend in a lifetime. Blah blah blah table blah blah blah SQL blah FoxPro blah database. Prove us wrong -- put your alleged code analyzer tools on Sourceforge if they are so great, or even exist. Until then, stop trying to tell software developers how to do their jobs.

    2. Re:Roll-your-own by Anonymous Coward · · Score: 0

      Until then, stop trying to tell software developers how to do their jobs.

      It is only a suggestion. If you don't like the suggestion, don't use it. Lighten up.

      Regardless of the parsing step, don't you agree that it is nice to have all that info in a database so that one can query it to find stuff and investigate oddities?

    3. Re:Roll-your-own by Anonymous Coward · · Score: 0

      No. Databases are black holes into which information gets sucked and increases in entropy. The only way it ever gets back out is as indecipherable random quantum fluctuations. That is, if the DBA has blessed it and appropriate ablutions and incantions have been performed.

    4. Re:Roll-your-own by Anonymous Coward · · Score: 0

      You must be using Oracle.

    5. Re:Roll-your-own by Tablizer · · Score: 1

      Prove us wrong -- put your alleged code analyzer tools on Sourceforge if they are so great

      Like I said, they tend to be language or site-specific. Making such tools generic, well-documented, and with a decent interface would greatly increase their complexity and code-size. That is the value that roll-your-own tools have over "boxed" tools: you only have to consider your cases, not all possible cases it may encounter.

      For example, I don't need to have grammar parsing templates for every possible programming language, just only for the ones I am targeting. Further, the parsing is not always perfect, but I know what the imperfections are and know how to live with or work around them. I couldn't leave such in a boxed generic app. I am not saying it is always worth it to roll-your-own, but I have found it fruitful in some cases.

  16. Source Insight by murat · · Score: 1

    We use "Source Insight" and we are very happy. ;) It's not free, though.

    1. Re:Source Insight by Ennuieux · · Score: 1

      Duh, I mean at http://www.sourceinsight.com

  17. More on Doxygen by fm6 · · Score: 1
    Doxygen is an absolute must if you need to document C++ APIs. Used with Graphviz, you do get clickable web diagrams that are very useful for visualizing class relationships. But note that the diagrams are not publication quality, since Graphviz has only the most primitive line-drawing features.

    In theory you can use Doxygen with any OO language, provided you can get a parser for that language. But I haven't heard a lot about Doxygen outside the C++ community. I imagine Java people mostly stick with JavaDoc, since that comes with the JDK. But I consider Doxygen to be far superior.

  18. --...I know... by Refrozen · · Score: 1, Informative

    Okay, so this doesn't answer what he was looking for, but the title reminded me of Koders... the search engine sucks, but it's a great idea.

  19. Source Navigator by avdi · · Score: 1

    I second the recommendation for Source Navigator. It's been a a great help to me in comprehending legacy codebases.

    --

    --
    CPAN rules. - Guido van Rossum
  20. Literate programming by keramida · · Score: 3, Interesting
    As an aside, back in my university days, I worked on a project where we did all of our coding in FrameMaker. This allowed us to put in pictures, colored comments -- basically anything. The build script turned the FrameMaker file into C++ source, which then got compiled. It was kind of the extreme version of self-documenting code.

    This sounds a lot like a relatively old, but intriguing idea. "Literate Programming" is exactly what you describe.

    It is exciting to write heavily documented code, but I doubt it can be done after the fact :-/

    --
    My other computer runs FreeBSD too.
    1. Re:Literate programming by Anonymous Coward · · Score: 0

      Leo hasn't been mentioned, but may be useful along these lines. Also, cscope, cbrowser, codeviz, ncc, ctags(sorry, no links; use google). Sourcenav was already mentioned.

  21. For PHP try this... by todsandberg · · Score: 4, Informative

    PHPXRef: PHP Cross Referencing Documentation Generator
    http://phpxref.sourceforge.net/

  22. lxr by hitchhacker · · Score: 3, Informative


    how about LXR?

    I've been using it to browse linux source code lately: here

    from the site:
    A general purpose source code indexer and cross-referencer that provides web-based browsing of source code with links to the definition and usage of any identifier. Supports multiple languages.

    except for lack of syntax hilighting, it works well.

    -metric

    1. Re:lxr by brondsem · · Score: 2, Informative

      I've worked fairly extensively with LXR for my former employer to get it working on our large codebase. If you try it, use the CVS version, not the latest release because it has some good enhancements and fixes. Not much development happens on the project on a regular basis, though. It won't give everything the poster requested, but browsing with identifier cross-reference, and freetext searching are its two main features and it does those well.

      Also, hopefully your codebase runs off some sort of revision control system (SVN, CVS, etc). Fisheye (commercial, pre-1.0 but moving fast) will let you peer into the activity happening. It plans to have LXR-like featurs added after 1.0

      --
      "a quote" -me
  23. It takes a *long* time to learn large systems. by Richard+Steiner · · Score: 3, Insightful

    I worked on the flight operations system for a large airline for over eight years (actually ten if you count my contractor time), and I only learned the intimate details of perhaps 20% of it bu the time I'd left.

    Complex applications require a huge amount of specialized knowledge in order to understand, and most of that knowledge relates to the application or work process itself, not the technical environment...

    --
    Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
    The Theorem Theorem: If If, Then Then.
  24. KCachegrind... by dmayle · · Score: 2, Interesting

    Here's one that no one else probably thought of. If the software runs on linux, load it up in valgrind with the calltree tool, use it a little, and look at the kcachegrind visualizations. It'll give you an idea of what code is actually used, and how it's interrelated.

  25. Emacs Code Browser by shapr · · Score: 1

    I like Emacs Code Browser, it's fast, featureful, and it deals with a bunch of different languages, see the screenshots
    Of course, if you don't use emacs, it won't be nearly as handy.

    --

    Shae Erisson - ScannedInAvian.com
    1. Re:Emacs Code Browser by Anonymous Coward · · Score: 0

      That's pretty nice. It looks like someone has applied an XFt patch to the linux emacs screenshots. I guess it uses the etags database.

      The problem with etags is that it doesn't work with live code (as in it doesn't know anything about the code you're actually typing). Look at Eclipse or IDEA for examples of what can be done with real parser integration.

    2. Re:Emacs Code Browser by Anonymous Coward · · Score: 0

      The Emacs Code Browser has real parser integration. Of course, the real parser is implemented in Emacs lisp... Unfortunately they are lagging behind the best Java tools in stuff like refactoring.

  26. Please learn how to make links. by Anonymous Coward · · Score: 1, Informative
    Please learn how to make links.
    <a href="http://sourcenav.sourceforge.net/">Source-Na vigator</a>
    (without any spaces put there by Slashdot) yields: Source-Navigator

    If that's too much typing for you,
    <URL:http://sourcenav.sourceforge.net/>
    (without any spaces put there by Slashdot) yields: http://sourcenav.sourceforge.net/

    Oh, and for you "Well just right-click on the text and click 'Follow Link'." people, tell me how to open a selected-text link containing extraneous Slashdot spaces in a new tab using Mozilla, or shut up.

    Also:

    how a change will effect external source modules

    "affect".
  27. Look on sweetcode.org by Farq+Fenderson · · Score: 1

    I've written a few in Perl for quick breakdowns. No graphing, but the equivalent textual information. I recall seeing a few projects of a similar nature on sweetcode, with graphing (3D?) unfortunately I don't recall what they might have been called.

  28. someone had to say it... by loony · · Score: 1

    find, grep and vi is all you need! :-)

    1. Re:someone had to say it... by ajole · · Score: 2, Funny

      Well, maybe find, grep and emacs :)

      --
      -P ...and the boy pulled open his bleary eyes an discovered the python he always knew he was.
    2. Re:someone had to say it... by patonw · · Score: 1

      Funny you should say that. That's all I've been using for the past week.

  29. Cscope by Anonymous Coward · · Score: 3, Informative

    I can't believe nobody has mentioned cscope yet. We used that in the multi-million line project I worked on until a couple of years ago. My division was only responsible for a few hundred thousand lines of code with a relatively well defined interface, so we generally kept our own cscope subset (Hint: cscope has an option to cache its results, and I highly recommend doing that if your project is more than a few thousand lines). I never actually had to use cscope for the entire source tree, but it worked VERY well for my area of responsibility (several tens of thousands of lines).

    In order to stick to the original question, I should also mention that most nontrivial programs end up using dynamic programming styles, and there's no way to graphically display those. I also want to point out is that no source code analyzer is going to do a even a half-assed job at figuring out dynamic relationships, so if your project contains any drivers/vtables/virtual functions, then you're basically S.O.L, and you may as well just use cscope. However, if you really insist on getting a graphical output, check out the free code graphing project. It has a nice picture of the linux kernel.

    1. Re:Cscope by Anonymous Coward · · Score: 0

      Might make some /.ers cry, but cscope was open-sourced thanks to our good friend SCO, according to the sourceforge page.

  30. no call graph, but immensely useful for C by ChipMonk · · Score: 1

    CScope, originally developed at AT&T Labs, now under the GPL and available at SourceForge. It works amazingly well on the Linux kernel. I've even tinkered around in the XFree86 code using CScope.

    (Also comes with vim integration, if you're into that.)

  31. Source Insight by atlasheavy · · Score: 1

    Use it, love it. The UI is rather ugly, but it is the best damned source navigation tool available for Windows today. (Link)

    --

    iRooster, the Mac OS X a
  32. Tools like this for Perl? by harlows_monkeys · · Score: 1
    Doxygen and Sourcenav (the main recommendations most people seem to be giving) are pretty good for the languages they support.

    However, neither supports Perl. Has anyone seen a tool like this that works on Perl code?

    1. Re:Tools like this for Perl? by Anonymous Coward · · Score: 0
  33. Source Insight by Ennuieux · · Score: 1

    The one at is not free (my company pays for it...), but it works very, very well.

  34. Thanks Everyone by patonw · · Score: 1

    I'll try those programs and keep you posted.

  35. Live code by aCapitalist · · Score: 0

    There's several tools out there for static analysis. I guess source-navigator has real parsers for the language it supports. I wonder if someone has ever attempted to integrate source-navigator into Emacs or Vim for live-parsing. Ctags and Etags can't do that right now and aren't real parsers to boot. Look at an IDE like Eclipse (and others) that do live parsing. Until recently, editors and developer tools have been sorely lacking real parsers. Something that many windows tools have had for a while (especially for C++).

  36. Eclipse by Anonymous Coward · · Score: 0

    I found Eclipse very good for this in a recent new 600K lines Java + JSP project I needed to understand in a few weeks. Of course, your machine needs to be spiffy and it needs to have plenty of RAM.

    The features I found most useful were:
    - hierarchy browser
    - call graph (finds out who calls what)
    - debugger (when all else fails, debug to find out what is happening)
    - resumable debugging (change while debugging)
    - incremental building.. which in Eclipse immediately tells you where you broke the code when you make a change (sometimes the easiest way is to create a compilation error and see what it impacts)
    - refactoring tools

    I bet it isn't as good for C++ and other languages though.

  37. Windows specific by alexo · · Score: 1


    Microsoft's Visual C++ creates a "code database" containing information about functions and classes.

    Version 6 had operations like "call graph" and "caller graph" that graphically showed the function calling sequence from or to a given function.

    Unfortunately, Microsoft, in their infinite wisdom, decided to scrap this functionality in version 7 (a.k.a .NET).

    Theoretically, since the code DB still contains the full info, an add-on could be written to support this functionality but ,as far as I know, there is none that supports version 7.1 (Visual studio .NET 2003)

  38. Smalltalk by GnuVince · · Score: 1

    I'm surprised no one has talked about Smalltalk's integrated code browser yet. See how much languages and environments have to learn from Smalltalk?

  39. Codeviz by meowsqueak · · Score: 1

    There's a nice front-end called Codeviz that 'writes' the graphs for Graphviz to render, and lets you filter symbols based on regular expressions. I find it pretty useful on C source - can't comment on other languages.

  40. code browsing by tiks · · Score: 1

    i use visual slickedit & its code browser works just great for me , it uses incremental search to update the tags so it dosent takes hell of a time updating tags database, if u want 2 use a free too then use kscope which uses cscope & ctags.

    --
    We are always correct.. even when we realize we were wrong.