Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have some experience with C++ and I have such task.
To read someone else's code (he implemented some project in C++)
and probably understand it, how it is structured what happens
there etc.
do you have some tipps how to approach such task?
What is the good way to make sure you well understand
what someone other wrote?

e.g., for example, I started adding comments/explanations to his
code, which weren't present before.

Thanks.
Posted
Comments
[no name] 19-May-13 13:25pm    
Run the code through a debugger and step through it so you can see exactly what the code is doing.
Dan page 19-May-13 13:42pm    
That's actually a problem: The code is written for an embedded device and you can't debug it. I think they just use logs for debugging.
[no name] 19-May-13 13:59pm    
I have worked on embedded devices where the code could be debugged. If you are unable to run the code in a debugger for some reason, print the code pages and follow the logic the good old fashioned way with a pencil, make notes, create logs.
Dan page 19-May-13 14:06pm    
hi what do you mean with "print code pages?". No I can't debug it. As I mentioned the only way is possible to debug is to write to log files and then read those logs from the device.
[no name] 19-May-13 14:25pm    
Take the source and print it.... or can't you print the source code either?

In order to understand someone else's code, you need to do RE (reverse engineering) ,i.e. disassemble or analyze in detail in order to discover concepts involved in manufacture.

Wikipedia:
"Reverse engineering is the process of discovering the technological principles of a device, object, or system through analysis of its structure, function, and operation. It often involves taking something (a mechanical device, electronic component, computer program, or biological, chemical, or organic matter) apart and analyzing its workings in detail to be used in maintenance, or to try to make a new device or program that does the same thing without using or simply duplicating (without understanding) the original.
Reverse engineering has its origins in the analysis of hardware for commercial or military advantage.The purpose is to deduce design decisions from end products with little or no additional knowledge about the procedures involved in the original production. The same techniques are subsequently being researched for application to legacy software systems, not for industrial or defence ends, but rather to replace incorrect, incomplete, or otherwise unavailable documentation"

In brief:
Through reverse engineering, a researcher can gather the technical data necessary for the documentation of the operation of a technology or component of a system. When reverse engineering software, researchers are able to examine the strength of systems and identify their weaknesses in terms of performance, security, and interoperability. The reverse engineering process allows researchers to understand both how a program works and also what aspects of the program contribute to its not working. The creation of better designs and the interoperability of existing products often begin with reverse engineering. It is desirable to do some of UML diagrams.
For example : a class diagram, sequence diagram and etc.
About UML, please see here:http://en.wikipedia.org/wiki/Unified_Modeling_Language


Reverse engineering consists of the following steps:
* Observe and assess the mechanisms that make the device work.
* Dissect and study the inner workings of a mechanical device.
* Compare the actual device to your observations and suggest improvement.
 
Share this answer
 
v2
Comments
Dan page 19-May-13 14:04pm    
Hi thanks. Yes, but as I said I have access to the *source code* of the project, so why do I need to reverse engineer it?
Volynsky Alex 19-May-13 17:20pm    
Firstly for well-understanding and managing what someone other wrote
and in addition, after that you can even improve(design or/and realization code) of other people
This is a big problem, and not just because of your code-reading skills, but because of those "other people" often really write unreadable code. Even though developers get isolated from each other better and better, through all kinds of ever (but slowly) improving technologies related to modularity and unification, reading the code of each other is still needed. It's absolutely important for people supervising development and making solution, and for everyone, because in good big teams, software reviews should be practiced.

As the main problem is still existence of unreadable code, you should start from yourself. Here is a brief plan for you.

  1. Learn how to write code very well. At this stage, don't care if you cannot read code of others.
  2. Make sure that your code is so good that you can understand your own code.
  3. Make sure that your code is so good that other people of enough qualification can understand your own code.
  4. Become a person with advanced development skill. Make sure that your code is so valuable that you can teach others. Up to this point, don't care that you cannot understand code written by others.
  5. The remaining skill is learning how to read the code written by others. It's perfectly OK. Now, make sure you already got the skills mentioned above and then start answering questions on this CodeProject forum. You well get this skills very, very quickly.


With you the best of luck,
—SA
 
Share this answer
 
v2
Comments
Dan page 19-May-13 14:39pm    
Hi Sergey Alexandrovich Kryukov. Thanks. But I can't wait for the 1,2,3,4 stages. I need to get involved in doing this already now (what I posted). I can say that I have already average (maybe even above average) coding skills. What to say about the code I need to read. Just it is not documented. Some of its classes I understand relatively easily too. Some of them I still need to look at, just they use I think functions classes (maybe from some SDK) which I am not familiar with yet...
Sergey Alexandrovich Kryukov 19-May-13 14:48pm    
I just hoped to give you some ideas. This is the simplified and somewhat humorous schema, but from real life. Use some mixed strategy then. After all, I hope you understand that there is no a way to get some skill without trying hard...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900