View Full Version : Reverse Engineering Code
fredlo2010
12-10-2013, 02:42 PM
Hello,
I applied for a job as an Excel VBA programmer (my questions about interview here ) (http://www.vbaexpress.com/forum/showthread.php?48406-Excel-VBA-Programmer-Interview) and one of the questions they asked was if I was able to reverse engineer a code. Apparently they have some code another programmer did before and they sort of want me to be able to understand it and if needed modify it.
Assuming that the previous person follow most of the naming conventions and was organized more or less; how can a person that takes over a project fully understand whats going on?
There are modules, forms, classes...
I was thinking to create a list of all the routines and classes and they link them visually to create a sort of map?
Thanks a lot in advance for the response.
Kyle234
12-11-2013, 01:55 AM
I find VBA actually one of the more difficult languages in which to follow someone else's code, typically it is written by self taught individuals (there is nothing wrong with that per se) that have varying levels of understanding as to how to properly structure an application. As such the flexibility of structure and ease of learning as well as being VBA/VB6's strength is also its downfall, I've seen a lot of poorly documented spaghetti code spread across multiple unrelated modules, a heavy reliance on public variables and pretty shoddy documentation. It doesn't help that the vast majority of VBA code I've come across has no automated testing - that might be a good place to start, write some tests - it will allow you to understand parts of the code and if necessary re-factor which will help your understanding.
The IDE doesn't help much in following code either; if you've used something like Visual Studio, you'll know what I mean ;)
That said I've also seen some (what I consider) to be well structured code, off the top of my head have a look at Tim Hall Excel-REST on Git Hub or mcpher.com (I can't post links)
Generally when trying to understand someone else's code, I'll get it up and running then comment it copiously as I step through it so I can see what it does. Though it's rare that you have to understand every nuck and cranny and solid overview should suffice; when changes need making/problems occur you can then start delivering into the relevant detail.
Mapping the project can be a good thing something like UML might be useful though is less handy with something like VBA that isn't really OOP. The good news here is that there are actually classes in the code, so this indicates that you predecessor had at least an intermediate understanding of code - so hopefully it shouldn't be too horrific!
I wish you the best of luck :)
Have you actually seen the code?
macropod
12-11-2013, 04:20 AM
It might be worth asking whether anyone has documented what the code is supposed to be doing, and where you can find the test doco from before it was implemented. That should provide a good reference point. If there isn't any, how do they know what it does compared to what they think it should be doing?
fredlo2010
12-11-2013, 05:06 AM
Thanks a lot for the answer guys.
I don't know I feel like I am venturing into open sea here. I am not sure if I am ready to do this yet. :)
Have seen my coding before? What do you think about me getting a job ? (I am not supposed to ask direct questions in the forum so I leave it open like that)
Also by any chance have you guys seen my other post Here (http://www.vbaexpress.com/forum/showthread.php?48406-Excel-VBA-Programmer-Interview)
Thanks a lot for the help guys. You are right Kyle a class would be a good indicator of some level of proficiency. :)
Google is your friend :devil2:
CodeCleaner
namemanager
CodeDocumentor
VBA_Smart_Indenter
Code refactoring - Wikipedia, the free encyclopedia (https://en.wikipedia.org/wiki/Code_refactoring)
Refactoring Home (http://refactoring.com/)
What Is Refactoring (http://c2.com/cgi/wiki?WhatIsRefactoring)
fredlo2010
12-11-2013, 10:15 AM
Thanks a lot for the information guys. I will certainly look into this articles.
grichey
12-30-2013, 02:45 PM
Will they let you run the code or do just get a print-out and have to go w/ it?
I like using Excel to store data because it allows the visual representation of the data and it is not restricted by page width.
An example is attached. The file name is based on the workbook be annotated or analyzed so that it shows up next to the annotated book in Windows Explorer. Each Sheet name is the same as each module in the annotated book.
When analyzing a book be sure to differentiate your comments from the original ones. I would use four or five comment marks because I have never seen that style in common use. I have seen '/ and '// and other languages' various comment tags used. I also format all code in a procedure with a leading Tab, except my 4 comment marks lines.
After you have finished commenting a procedure in the book you are analyzing, merely paste your comments into the Annotation book as appropriate.
Do not be tied to any one style of annotating. The attachment is just a start. Modify each annotation book and worksheet as needed to best describe the book you are analyzing.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.