The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Code Reading technique

Hi,

I have been given a massive task of reverse engineering. The task is to read the java code and produce a document about what it actually does. Although, I know the application, what it does and how, but understanding of code is none. I just thought, are there any efficient ways of reading code, I mean can code-reading is also a tactics in itself. I'm searching on internet about this and found a little....

It would be great if you could provide sensible tips and links to article that illustrates code-reading technique.

Thanks,

Kris Gautam
Gautam Send private email
Tuesday, September 13, 2005
 
 
I prefer to start in the main() function and work down, producing a hierachical organizational structure.

Obviously this works best for C rather than Java, but even then, you should be able to identify threads and other objects, and the like.

Alternatively, you can get a great deal of insight from the way the project is organized, in files (Again, slightly more useful in C)
Arafangion Send private email
Tuesday, September 13, 2005
 
 
Running through the main use cases in a debugger can be useful. Get all of the sources into a decent IDE so you can navigate about easily.

Apart from that its best to be patient and make no assumptions about what code may be doing.

It sounds like there may be an interesting story behind why you are being asked to perform this task!
Arethuza
Tuesday, September 13, 2005
 
 
I would certainly run the code through javadoc. Even if there are no javadoc comments in the code, the resulting lists of classes and their properties might be quite useful, depeneding on how "creative" the original authors were with their naming practices.
Berislav Lopac Send private email
Tuesday, September 13, 2005
 
 
Java syntax is clean enough that you can also use static analyzers to get call and class graphs.

You can probably find something for free... try googling for "java code static analyzer" or similar word combinations and see what you get.
Paolo Marino Send private email
Tuesday, September 13, 2005
 
 
"Java syntax is clean enough"

Generally true - although terrible things can be done in JSPs.
Arethuza
Tuesday, September 13, 2005
 
 
Peter
Tuesday, September 13, 2005
 
 
Hi  All,

Thanks for the responses. Its great reading suggestions of bigwigs.Especially the javadoc and links to amazon.

Thanks again to all....I've now something to kickstart the work ..

Kris Gautam
Gautam Send private email
Tuesday, September 13, 2005
 
 
In addition to javadoc you might find the free tool 'essmodel' useful.  It provides a graphic overview of the class structure of the application.  I haven't used it with java, but I have used it to help comprehend some very large Delphi projects.

http://essmodel.sourceforge.net/
Herbert Sitz Send private email
Tuesday, September 13, 2005
 
 
I wouldn't recommend the "Code Reading" book - I thought it spent far too much time on basic topics (introducing the syntax to various language constructs, and how to use version control) and didn't have enough real meat to it.

Working Effectively with Legacy Code, however, is excellent. I'd definitely get that.

I suggest:

Load everything into a good IDE first. You've said it's Java - IntelliJ IDEA is the best IDE, and Eclipse/NetBeans are also very good (and free).

Spending an hour scanning the whole codebase; not reading code in depth, just getting familiar with the package structure, layout, naming conventions, general approach.

Generate the JavaDoc and look through it. If the developers were good, then there'll be package.html files that describe what each package does. If not, then create them yourself - as soon as you've got a vague idea what a package does, then write a sentence or two to summarize it. This will help your understanding, and make life easier when you have to do more work with it.

Identify the important tasks that the code does, and trace through the code for them. Find entry points (such as main() methods, servlets, GUI code) and start from them. Skip over anything that's too unclear, but make a note for later reference.

Try compiling and building the code (hopefully there'll be an ant build.xml). If that works, then try stepping through the code with a debugger - don't do this too soon, though, or you'll get bogged down in details.

Ask the original authors for help if you possibly can.

There are various tools that will reverse-engineer UML diagrams from code. I don't know of any that are any good, though.
Inigo Send private email
Tuesday, September 13, 2005
 
 
www.scitools.com has "Understand for Java", which gives you a very nice code navigator, can draw some of the class diagrams, and lets you 'walk' the code.

UMLStudio is a very nice, affordable ($500) tool which can reverse engineer class diagrams from Java code.  I use it more to generate documentation, but the ingest can be helpful.
AllanL5
Tuesday, September 13, 2005
 
 
One thing you can do is "scratch refactoring", where you go through reorganizing, cleaning, renaming, etc. with no intention of saving the results.  Since you have to do a lot of following code paths to do this decently, it helps you see how things fit together.

Just make sure you discard your refactoring afterwards!
Kyralessa Send private email
Tuesday, September 13, 2005
 
 
You could use something like Altova UModel (30 day free trial available).

It will blaze through the code and create UML diagrams for you:

.    Use case diagrams
.    Class diagrams
.    Object diagrams
.    Packages
.    Component diagrams
.    Deployment diagrams

http://www.altova.com/products_umodel.html
redeye Send private email
Wednesday, September 14, 2005
 
 
I'm bad code reader myself but I thought that using your version control tool might be a help. You could pull out an early revision of the project which would be simpler and easier to follow (but also wrong and incomplete). The version log comments might also explain things better than the code comments and they might hint how the complex functions got so hairy.
setsquare Send private email
Wednesday, September 14, 2005
 
 
Umbrello will also import your Java code and create UML diagrams.  Free if you're running a Linux/KDE system.
Steve Moyer Send private email
Thursday, September 15, 2005
 
 
I don't think using code to UML tool ease code reading in any way.
Carfield Yim Send private email
Tuesday, September 20, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz