Navigation and understanding problems with C++ code, Please help

B

bcoder77

Experts & Beginners,

I'm definitely not an expert, but believe that can become one day....and
the journey has already started....and here is a possible milestone, if
you guys can help.

I work for a company that has a very nice embedded product, and I have
been involved in system design and testing for this product. Now, I am
trying to get some understanding of software, which is a model-based C+
+ software. It is developed using Rhapsody. My question is: I am not
able to follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am confused by
the syntax and naming rules. I tried to find some details on how
people (programmers) name structures, classes (special type of
classes), objects, constructors, destructors, functions,..etc., and
how to navigate between different parts of the code to follow the
implemented logic...but has no luck so far.

Can anyone help me how I should dive into this? How you did when you
were a beginner and had faced similar situation? I believe, all I need
is some guidance that can save me wondering around the code files.

All replies are greatly appreciated.

Thanks,
Bill.
 
J

Jeff Schwab

Experts & Beginners,

I'm definitely not an expert, but believe that can become one day....and
the journey has already started....and here is a possible milestone, if
you guys can help.

I work for a company that has a very nice embedded product, and I have
been involved in system design and testing for this product. Now, I am
trying to get some understanding of software, which is a model-based C+
+ software. It is developed using Rhapsody. My question is: I am not
able to follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am confused by
the syntax and naming rules. I tried to find some details on how
people (programmers) name structures, classes (special type of
classes), objects, constructors, destructors, functions,..etc., and
how to navigate between different parts of the code to follow the
implemented logic...but has no luck so far.

Can anyone help me how I should dive into this? How you did when you
were a beginner and had faced similar situation? I believe, all I need
is some guidance that can save me wondering around the code files.

Have you used tags files before? Start here:

http://ctags.sourceforge.net/

I have found Vim and Ctags to be reliable, portable, easy-to-use tools
for browsing C++ code. You can generate a tags file for a given
directory tree with:

ctags -R

The tags file is in a widely recognized format, and is compatible with
popular code editors. If you are using Vim, set the tags file path in
your vimrc:

set tags=./tags,tags,../tags,../../tags,../../../tags

To make sure that Vim will be able to find various files (so that you
can, e.g., jump to #include'd files with the "gf" command) by adding to
Vim's include path:

set path+=/usr/include/myheaders
set path+=/some/other/include/path

Emacs (as usual) has its own variant of tags, called etags, and a set of
configurable key-bindings. Some IDEs generate and update
application-specific equivalents of tags files for you automatically, so
you just have to learn the IDE's key bindings, menu entries, etc.

Good luck. Please post back if you come across any particularly nifty
solutions.
 
A

AnonMail2005

Experts & Beginners,

I'm definitely not an expert, but believe that can become one day....and
the journey has already started....and here is a possible milestone, if
you guys can help.

I work for a company that has a very nice embedded product, and I have
been involved in system design and testing for this product. Now, I am
trying to get some understanding of software, which is a model-based C+
+ software. It is developed using Rhapsody. My question is: I am not
able to follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am confused by
the syntax and naming rules. I tried to find some details on how
people (programmers) name structures, classes (special type of
classes), objects, constructors, destructors, functions,..etc., and
how to navigate between different parts of the code to follow the
implemented logic...but has no luck so far.

Can anyone help me how I should dive into this? How you did when you
were a beginner and had faced similar situation? I believe, all I need
is some guidance that can save me wondering around the code files.

All replies are greatly appreciated.

Thanks,
Bill.

Also, I've found doxygen invaluable in learning the dependency
structure of code via the diagrams you can get it to create.

HTH
 
B

bcoder77

Have you used tags files before?  Start here:

   http://ctags.sourceforge.net/

I have found Vim and Ctags to be reliable, portable, easy-to-use tools
for browsing C++ code.  You can generate a tags file for a given
directory tree with:

   ctags -R

The tags file is in a widely recognized format, and is compatible with
popular code editors.  If you are using Vim, set the tags file path in
your vimrc:

   set tags=./tags,tags,../tags,../../tags,../../../tags

To make sure that Vim will be able to find various files (so that you
can, e.g., jump to #include'd files with the "gf" command) by adding to
Vim's include path:

   set path+=/usr/include/myheaders
   set path+=/some/other/include/path

Emacs (as usual) has its own variant of tags, called etags, and a set of
configurable key-bindings.  Some IDEs generate and update
application-specific equivalents of tags files for you automatically, so
you just have to learn the IDE's key bindings, menu entries, etc.

Good luck.  Please post back if you come across any particularly nifty
solutions.- Hide quoted text -

- Show quoted text -

Thank you guys for your inputs, but still this is not what I was
looking for, and the reason is that I was not clear enough in
describing the question. Let me ask this specifically: When I read
through the code, I read ItzDelegate...this....ItsMonitor....etc. I
figured that there are some guidelines for naming certain components
of code (such as delegate(abstract) classes are named with
itsDelagate), and I am not aware of that. I mean, how do I manually
navigate different parts of code? Where do I find the information
about such styles( names of different components) of writing code? I
am really a beginner.

Thanks,
Bill
 
P

Puppet_Sock

On Feb 11, 10:01 am, (e-mail address removed) wrote:
[snip]
I work for a company that has a very nice embedded product, [snip]
My question is: I am not
able to follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am confused by
the syntax and naming rules.
[snap]

Well, I'm having trouble reading your company's
software documents from here. Could you hold them
up a little higher?

Say, about your own eye level?
Socks
 
L

LR

Thank you guys for your inputs, but still this is not what I was
looking for, and the reason is that I was not clear enough in
describing the question.

I'm not sure that you're being clear here either as it seems to me
you're asking about several different, but related things

Let me ask this specifically: When I read
through the code,

How are you reading through the code?


I read ItzDelegate...this....ItsMonitor....etc.

I'm not quite sure what you actually see when you read the code. Do you
literally see the above string?

I figured that there are some guidelines for naming certain components
of code

Yes, there are. Probably many of them. And they vary. I suggest you
start with a google search for something like
"naming conventions" C++


(such as delegate(abstract) classes are named with
itsDelagate), and I am not aware of that.

I'm not quite sure what you mean by that. 'itsDelegate'? Is that the
name of a class, an instance, a member? Part of the name of a class?



I mean, how do I manually navigate different parts of code?

Manually? As opposed to what? I'm not sure that I follow that. I'm
going to assume that you have all the source code on a hard drive
somewhere. Why not get an IDE of some kind that will allow you to
navigate around and look at the code?

Ok, let's say that you can't get an IDE. Then there may be some brute
force solutions that will be less than perfect. You could write a small
tool to read through the source and produce a mostly incorrect cross
reference. This will not be an easy task to do correctly, but it's
possible that an incorrect solution will work for you. Or there may be
tools avaliable that will do this for you. I think some have been
mentioned already.

There is always grep or whatever similar tool your OS supports.

But it will almost certainly be easier to get a nice IDE that allows you
to navigate around the code.

Where do I find the information
about such styles( names of different components) of writing code?

I think you should try google.

I'm not certain I understand what you're asking, so it seems to me that
you may be looking for some style that is expected and accepted by all
C++ programmers and I don't think there is one.

LR
 
B

bcoder77

My question was: How do I understand the implemented functionality by
navigating through the code, depending calls and data access within
files (cpp). I have all source code, but did not have IDE, instead I
was using Understand for C++. I had created a project in that but was
not able to differentiate among filename, class, constructor. Here is
the situation: If I want to understand how a specific task is
implemented in the code (or say someone ask me how software would
react to a certain scenario), I would first go to the file (cpp) that
has similar name as the task. There I would see two files, one .h and
the other .cpp. Now when I read .cpp file, I come across some code
that directs me to another file (may be function or pointer to a
structure, or something else) so I do a search for that word in the
project files, and it brings up a lot of files that also contain the
same word...here is my confusion bcoz i don't know where to go now.
What I understood is that there is a common naming style (not for
everything as mentioned in the previous replies)as an example
delegator class. I want to know more so that I can go back and forth
between files and understand the functionality.

Sorry, I can't provide any information or code sample as it is
confidential. Please help.

Bill.
 
P

Pascal Bourguignon

My question was: How do I understand the implemented functionality by
navigating through the code, depending calls and data access within
files (cpp). I have all source code, but did not have IDE, instead I
was using Understand for C++. I had created a project in that but was
not able to differentiate among filename, class, constructor. Here is
the situation: If I want to understand how a specific task is
implemented in the code (or say someone ask me how software would
react to a certain scenario), I would first go to the file (cpp) that
has similar name as the task. There I would see two files, one .h and
the other .cpp. Now when I read .cpp file, I come across some code
that directs me to another file (may be function or pointer to a
structure, or something else) so I do a search for that word in the
project files, and it brings up a lot of files that also contain the
same word...here is my confusion bcoz i don't know where to go now.
What I understood is that there is a common naming style (not for
everything as mentioned in the previous replies)as an example
delegator class. I want to know more so that I can go back and forth
between files and understand the functionality.

Sorry, I can't provide any information or code sample as it is
confidential. Please help.

Well, it sounds like you have to learn programming first.
This includes understanding the semantics of programming languages.

It looks like you can read, and you can compare words, and find them
in a dictionnary, but since you still don't understand any word of the
language, you can only further search the referenced workds in the
dictionnary. Ok, you know how to navigate in the sources, but you
cannot read it and don't really understand a word of it.


About naming style, of course, good programmers (or teams) have naming
conventions helping them to orientate themselves, but this is nothing
but some hints for the human reader. The way names are formated is
totally irrelevant for the semantics of the program.

int f(int x){ return x<1 ? 1 : x*f(x-1); }

has exactly the same meaning as:

int f(int integer){ return integer<1 ? 1 : integer*f(integer-1); }

as

int f(int foobar){ return foobar<1 ? 1 : foobar*f(foobar-1); }

as

int factorial(int n){ return n<1 ? 1 : n*factorial(n-1); }

etc...

You shouldn't rely on the identifiers to understand the meaning of the
programs.



The semantics of whole programs can be infered from the semantics of
the subcomponents of the program, decomposing down to the elementary
expressions and statement defined in the language specifications.

With natural languages where words have some basic meaning, but
associating words according to syntax and grammar rules you build
propositions with composed meanings, and meaningful whole
phrases. Then you associate phrases in paragraphs, paragraphs in
sections and sections in chapters and then books to make stories with
lots of complex meaning.

Likewise, with programming languages, you start from the token of the
language, group them according to the syntax and grammar of the
programming languages, which allows you to identify the semantics of
the basic expressions or statements. These semantics are explained in
the programming language references, something you will have to read
and learn when you'll learn programming. Then reading groups of
expressions and statements you get compound structures (eg functions,
methods, classes) with their own meaning you can build from the
meaning of the basic items. To help you infer the meaning of these
compound groups of expressions and statements, you can use formal
semantics of various sorts
http://en.wikipedia.org/wiki/Formal_semantics_of_programming_languages
in particular Hoare logic, which is rather simple and helpful to
understand procedural programming languages like C++ (functions and
method bodies). http://en.wikipedia.org/wiki/Hoare_logic

Once you've deduced the meaning of a function with such a formal
method, if it happens to correspond to the name of the function, good.
Otherwise, you can curse the original programmers, and rename the function.

In conclusion, it sounds like you should go back to school to learn
programming, because all this are subjects that are taught there.
 
L

LR

My question was: How do I understand the implemented functionality by
navigating through the code, depending calls and data access within
files (cpp).

Could you please clarify that? What are "depending calls"?


Sometimes the answer is: You just have to read the code.

I have all source code, but did not have IDE, instead I
was using Understand for C++.
I had created a project in that but was
not able to differentiate among filename, class, constructor.

I'm unfamiliar with the product. Perhaps they have a support group.
Here is
the situation: If I want to understand how a specific task is
implemented in the code (or say someone ask me how software would
react to a certain scenario), I would first go to the file (cpp) that
has similar name as the task.

Lucky coincidence that the task and files have the same name.

There I would see two files, one .h and
the other .cpp.

Where would you see these? In a directory listing? Using someething
like windows explorer?


Now when I read .cpp file, I come across some code
that directs me to another file (may be function or pointer to a
structure, or something else) so I do a search for that word in the
project files, and it brings up a lot of files that also contain the
same word...here is my confusion bcoz i don't know where to go now.


I think this is something that you have to decide by reading the code.
You may want to check out various IDEs to see what kind of tools there
are available to do this.

What I understood is that there is a common naming style (not for
everything as mentioned in the previous replies)as an example
delegator class.

Assuming that we're not discussing the standard library, then if your
code has a common naming style, I suspect it would be used in the code
you have. The rest of us may not know about it.

> I want to know more so that I can go back and forth
between files and understand the functionality.


I'm really not sure what you're asking here. I think you should
investigate a good IDE. If for some reason you are unable to do that,
then please tell us why, because it may influence other possible answers.
Sorry, I can't provide any information or code sample as it is
confidential. Please help.

Perhaps you could write a little project, say less than 30 lines total
or so, and four or five files and show us what you'd like to be able to do.

LR
 
J

James Kanze

Experts & Beginners,
I'm definitely not an expert, but believe that can become one
day....and the journey has already started....and here is a
possible milestone, if you guys can help.
I work for a company that has a very nice embedded product,
and I have been involved in system design and testing for this
product. Now, I am trying to get some understanding of
software, which is a model-based C+ + software. It is
developed using Rhapsody. My question is: I am not able to
follow the huge code with several packages and libraries with
accurate understanding since I have not written it. I am
confused by the syntax and naming rules. I tried to find some
details on how people (programmers) name structures, classes
(special type of classes), objects, constructors, destructors,
functions,..etc., and how to navigate between different parts
of the code to follow the implemented logic...but has no luck
so far.
Can anyone help me how I should dive into this? How you did
when you were a beginner and had faced similar situation? I
believe, all I need is some guidance that can save me
wondering around the code files.

Most design tools have back-engineering options: Rose, Together,
etc. (In the past, I found Sniff+ very good for understanding
existing code as well, although I'd prefer Rose or Together for
developing new code.) Doxygen can also be used to create class
diagrams, although it is somewhat more limited.

The syntax should be the same for all C++ code. On the other
hand, conventions concerning indenting, placement of the braces
and naming vary greatly from one place to the other; there are
no universal rules (although I've noticed that a number of
places like to add on all sorts of junk in code that they
deliver, presumably to make it more difficult for the client to
back engineer it).
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top