Understanding Some one else's code - beginner

Discussion in 'C++' started by Slain, Jul 16, 2007.

  1. Slain

    Slain Guest

    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.
    Slain, Jul 16, 2007
    #1
    1. Advertising

  2. Slain wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jul 16, 2007
    #2
    1. Advertising

  3. Slain

    Jim Langston Guest

    "Slain" <> wrote in message
    news:...
    >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!
    Jim Langston, Jul 16, 2007
    #3
  4. On 2007-07-16 21:50, Victor Bazarov wrote:
    > Slain wrote:
    >> 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.


    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.

    --
    Erik Wikström
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 17, 2007
    #4
  5. Slain

    JohnQ Guest

    "Slain" <> wrote in message
    news:...
    >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
    JohnQ, Jul 17, 2007
    #5
  6. Slain

    James Kanze Guest

    On Jul 16, 9:50 pm, "Victor Bazarov" <> wrote:
    > 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.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jul 18, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    25
    Views:
    648
    MonkeeSage
    Oct 1, 2006
  2. kj
    Replies:
    15
    Views:
    535
    Lawrence D'Oliveiro
    May 23, 2009
  3. A
    Replies:
    8
    Views:
    782
    James Kanze
    Aug 28, 2010
  4. Gergely Kontra
    Replies:
    16
    Views:
    218
    Devin Mullins
    Sep 20, 2005
  5. Terry Reedy

    Understanding while...else...

    Terry Reedy, Jan 22, 2013, in forum: Python
    Replies:
    0
    Views:
    101
    Terry Reedy
    Jan 22, 2013
Loading...

Share This Page