Understanding Some one else's code - beginner

S

Slain

I am a new hire in a company and have started working for the
development team. Ofcourse, I took some C++ courses in my grad school,
but there is such a big difference in the programs you encounter at
school versus here, where it sems there is a completely different
style of writing.

Is there some tool etc to help understand some one else's code. I have
been given some responsibilities to fix some minor defects, which
involves understanding some one else's code. Any pointers would be
helpful.
 
V

Victor Bazarov

Slain said:
I am a new hire in a company and have started working for the
development team. Ofcourse, I took some C++ courses in my grad school,
but there is such a big difference in the programs you encounter at
school versus here, where it sems there is a completely different
style of writing.

Is there some tool etc to help understand some one else's code. I have
been given some responsibilities to fix some minor defects, which
involves understanding some one else's code. Any pointers would be
helpful.

Version control. It can get you the information who was the last one
to touch the code, or who made the most changes to it. It is fair to
speculate that the person who's already seen the code would know more
about it. Ask him/her.

The code is supposed to be documented (comments, separate electronic
and other diagrams and tables). Read the documentation. If reading
the electronic portion requires special software, use it.

Debugger. Step through the code to see what it does, where execution
takes you, and how the values change.

Document your changes to the code, observe the changes in behaviour.
If you can keep it all in your head, good, otherwise use some type of
sandbox in the same version control software.

There are tools out there that can reverse-engineer C++ code and draw
class diagrams, entity diagrams, etc. I haven't tried any of them,
but I heard of people who heard of people who swory by those.

V
 
J

Jim Langston

Slain said:
I am a new hire in a company and have started working for the
development team. Ofcourse, I took some C++ courses in my grad school,
but there is such a big difference in the programs you encounter at
school versus here, where it sems there is a completely different
style of writing.

Is there some tool etc to help understand some one else's code. I have
been given some responsibilities to fix some minor defects, which
involves understanding some one else's code. Any pointers would be
helpful.

Bug fixing is one of the first thing usually given to someone new to a
company for just that reason, so they can start to understand the code.
Also, you'll find that >80% of the time you'll be fixing programs rather
than writing new ones. Maintainance is a big part of being a professional
programmer.

Anyway, to start out what I always did was trace backwards. For example,
they tell me that some box on some edit form is showing the wrong number,
I'll look at the edit form (or report, or screen, or whatever), find out
whree it's being displayed, then find out where it's being
displayed/printed/shown in the code. Sometimes it's a simple variable, then
I'll trace back where that variable comes from. Sometimes it's a formula,
then I'll have to figure out how the formula is calculated, etc...

Make absolutely sure you know you are changing the right thing before you
change it, then document it. Something like:

showField( Foo, age * weight + height );

then you make a change

// replaced line 7/16/07 JML - Formula wrong
//showField( Foo, age * weight + height );
showField( Foo, age * weight + height - bodymass );

I'll then usually find a programmer that's been around a while, show him
what I found, what I'm fixing. They'll usually say, yeah, looks good, then
I''ll remove the commented out line (if it's how its done there). In one
company lines changed needed the old line left in. One company didn't want
it.

It will probably take a while of fixing things like this until you start to
see a pattern in code, how they call their functions, etc... then it'll
become easier.

Good luck!
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Version control. It can get you the information who was the last one
to touch the code, or who made the most changes to it. It is fair to
speculate that the person who's already seen the code would know more
about it. Ask him/her.

The code is supposed to be documented (comments, separate electronic
and other diagrams and tables). Read the documentation. If reading
the electronic portion requires special software, use it.

Debugger. Step through the code to see what it does, where execution
takes you, and how the values change.

Document your changes to the code, observe the changes in behaviour.
If you can keep it all in your head, good, otherwise use some type of
sandbox in the same version control software.

There are tools out there that can reverse-engineer C++ code and draw
class diagrams, entity diagrams, etc. I haven't tried any of them,
but I heard of people who heard of people who swory by those.

Doxygen is one quite popular. Also, most IDEs nowadays have some cross-
referencing functions in them, so you can select a function call and go
to the function declaration and so on.
 
J

JohnQ

Slain said:
I am a new hire in a company and have started working for the
development team. Ofcourse, I took some C++ courses in my grad school,
but there is such a big difference in the programs you encounter at
school versus here, where it sems there is a completely different
style of writing.

Is there some tool etc to help understand some one else's code. I have
been given some responsibilities to fix some minor defects, which
involves understanding some one else's code. Any pointers would be
helpful.

In addition to what has already been mentioned, the use of a code-folding
editor is usefull also as it gives a high level view of a source file and
then detail on demand. This is especially usefull in C++ because the norm is
to put all member functions of a given class in the same file and the
code-folding editor makes it a lot easier to work with (less scrolling and
searching and the like).

John
 
J

James Kanze

Slain wrote:
There are tools out there that can reverse-engineer C++ code and draw
class diagrams, entity diagrams, etc. I haven't tried any of them,
but I heard of people who heard of people who swory by those.

Or at them:).

Seriously, I've used Rational Rose and Together for this, at
different times. Both help some, but don't expect any
miracules; bad, poorly documented code remains bad, poorly
documented code even when it is reverse engineered.

Much further in the past, I used a tool called Sniff+; for
trying to understand undocumented code, it was better than
either Rose or Together (but it didn't have a lot of the other
functionalities those tools have). I don't know if it's still
on the market, however.

And all of the above are (or were) relatively expensive. While
IMHO a company developing software would be foolish to not use
Rose, it's not the sort of thing a student or a hobbyist is
likely to be able to afford.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top