Slashdot Mirror


Ask Slashdot: How To Start Reading Other's Code?

BorgeStrand writes "I'm reviving an open source project and need to read up on a lot of existing code written by others. What are your tricks for quickly getting to grips with code written by others? The project is written in C++ using several APIs which are unknown to me. I know embedded C pretty well, so both the syntax, the APIs and the general functionality are things I wish to explore before I can contribute to the project."

254 comments

  1. Test and Break by jackyalcine · · Score: 4, Insightful

    If there's a lot of documentation, interpret it like your favorite religious text. Try to hit up some of the old developers from the VCS. Also, I'd like to help :)

    1. Re:Test and Break by Anonymous Coward · · Score: 3, Funny

      If there's a lot of documentation, interpret it like your favorite religious text. Try to hit up some of the old developers from the VCS.
      Also, I'd like to help :)

      The Great Programmer commanded his bytes to carry their bugs to the bitstream and drown them, or 7 years of seg faulting would follow.

      Join the Church of Emacs today!

    2. Re:Test and Break by ichthus · · Score: 5, Funny

      And lo, yea though ye shifteth right 8 bits, counteth not thy sign as verily carried henceforth unto the int8_t.

      --
      sig: sauer
    3. Re:Test and Break by aardvarkjoe · · Score: 2

      If there's a lot of documentation, interpret it like your favorite religious text.

      So it's got some pretty good ideas, but nobody really pays attention to what it says?

      Describes the documentation for most projects I've worked on.

      --

      How can we continue to believe in a just universe and freedom to eat crackers if we have no ale?
    4. Re:Test and Break by another_larson · · Score: 2

      Contacting the earlier developers is good advice.

      Unfortunately the OP doesn't say how much code there is. Understanding 10K lines by reading the source code is feasible; doing so for 1M lines isn't. Documentation is of some use, but it's typically scant and years out of date. Really, the best guide is an explanation given by someone who already knows the codebase.

      A good way to proceed here is to spend a bit of time digging around the codebase by yourself, write up a proposal for some significant improvement, and send it to folks who were active when the project was up and running. With a bit of luck they'll reply with criticism and suggestions for improvement.

    5. Re:Test and Break by Anonymous Coward · · Score: 0

      That's BS. In my experience the documentation of old embedded code is either superficial (pretend ^ is the less-than, I think html sanitizing is getting me):

      num_brd ^^= 3; /* mult by 8 */

      or downright wrong: /* prt_mnst can't be bigger than 8. */
      if (prt_mnst ^ 14)
      { ...

      Also, vowels apparently used to be very expensive in C variable names "back in the day."

    6. Re:Test and Break by mooingyak · · Score: 4, Informative

      Also, vowels apparently used to be very expensive in C variable names "back in the day."

      Certain early C implementations would only use the first 8 characters of a variable name. At that point, the vowels are usually the most expendable when coming up with names.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    7. Re:Test and Break by dotancohen · · Score: 2

      And lo, yea though ye shifteth right 8 bits, counteth not thy sign as verily carried henceforth unto the int8_t.

      16 bits is right out.

      --
      It is dangerous to be right when the government is wrong.
    8. Re:Test and Break by Anonymous Coward · · Score: 0

      If there's a lot of documentation, interpret it like your favorite religious text.

      With mixed feelings of disdain and amusement?

    9. Re:Test and Break by Anonymous Coward · · Score: 0

      That's BS. In my experience the documentation of old embedded code is either superficial (pretend ^ is the less-than, I think html sanitizing is getting me):

      num_brd ^^= 3; /* mult by 8 */

      or downright wrong: /* prt_mnst can't be bigger than 8. */ if (prt_mnst ^ 14) { ...

      Also, vowels apparently used to be very expensive in C variable names "back in the day."

      Would that be num_brd <<= 3;
      ?
      Is your point that board_number *= 8; would be clearer?

      If so, I agree.

    10. Re:Test and Break by TapeCutter · · Score: 1

      With humility. Because it's embarrassing when the "moron" who wrote it 10yrs ago turns out to be a younger you!

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    11. Re:Test and Break by Anonymous Coward · · Score: 0

      And if all else fails, use thy holy hand grenade.

    12. Re:Test and Break by ilsaloving · · Score: 2

      Back in the day, it was the current 'fashion' to remove vowels as a method of shortening variable names.

      Later on, it was determined that simply truncating longer words was actually significantly more readable.

    13. Re:Test and Break by lefin1 · · Score: 1

      Lest thou forget thy Holy Hand Grenade!

    14. Re:Test and Break by Meski · · Score: 1

      Then again, coming from some of the languages we were, variable names longer than one character were a sinful luxury. Vowels *and* consonants would be grounds to go straight to coder hell.

    15. Re:Test and Break by Meski · · Score: 1

      Maybe. If they aren't current devs on the project, they might have given up on it, and become embittered and cynical.

      http://en.wikipedia.org/wiki/Six_phases_of_a_big_project

    16. Re:Test and Break by niftymitch · · Score: 1

      Contacting the earlier developers is good advice. Unfortunately the OP doesn't say how much code there is. Understanding 10K lines by reading the source code is feasible; doing so for 1M lines isn't. Documentation is of some use, but it's typically scant and years out of date. Really, the best guide is an explanation given by someone who already knows the codebase. A good way to proceed here is to spend a bit of time digging around the codebase by yourself, write up a proposal for some significant improvement, and send it to folks who were active when the project was up and running. With a bit of luck they'll reply with criticism and suggestions for improvement.

      Yes and
      Make a copy!

      Find a good editor or development tool, build tag files and start reading. As you drill down annotate the code with XXX-your-initials-B:, XXX-your-initials-Q: and XXX-your-initials-A: (your bugs, questions and answers)...enhancement too.

      Write tests to validate what you know... or think you know.

      Consider adding "asserts()" if there are known but un-diagnosed bugs.

      Old school would be print it out, add thumb tabs, mark it up and build a flow diagram. Old green bar computer paper is still available as are the handy hand tools for making flow diagrams. The size of the paper is about right... Binders for green bar paper can still be had...

      Google and quickly read articles on "Literate" programming. There are many tools... One of which is Doxygen http://www.stack.nl/~dimitri/doxygen/

      --
      Truth is stranger than fiction, but it is because Fiction is obliged to stick to possibilities; Truth isn't. Mark Twain.
  2. Start with the headers by Beryllium+Sphere(tm) · · Score: 5, Insightful

    Knowing the data structures gives you the ground work for understanding what the code is doing. The data structures are a more direct description of the design decisions.

    1. Re:Start with the headers by girlintraining · · Score: 4, Insightful

      Knowing the data structures gives you the ground work for understanding what the code is doing. The data structures are a more direct description of the design decisions.

      This approach assumes the programmer hasn't gone native. Great for managed code, but when the data structures are basically pointers being passed back and forth and calls to APIs deep in the guts of the OS... well, how do I put this: You're screwed. It's a crap shoot on if the programmer even knows why it works... sometimes in C++ you stop debugging the moment it starts returning sane outputs and consider yourself lucky you didn't have to fully grok wtf just happened. :/

      --
      #fuckbeta #iamslashdot #dicemustdie
    2. Re:Start with the headers by gl4ss · · Score: 1

      well the headers are a way to learn what the pointers are pointing to...
      using os libs isn't always referred as going native though.

      here's a tip though, use an editor that lets you quickly jump to the definition of a thing(function, struct, whatever). it speeds up things a lot. even if you just end up in a header for some native lib you don't have the source for and that is uncommented.

      --
      world was created 5 seconds before this post as it is.
    3. Re: Start with the headers by Anonymous Coward · · Score: 0

      I hope that you don't write software where errors can result in a danger to life and safety.

    4. Re: Start with the headers by Grishnakh · · Score: 0

      Well with stuff like Windows being used to run ships, you can be certain that poorly-written software being used in applications where it results in a danger to life and safety is probably the norm these days.

    5. Re: Start with the headers by jones_supa · · Score: 0

      Interesting. Citation?

    6. Re: Start with the headers by Anonymous Coward · · Score: 0

      http://www.intelisea.com/ (flash-heavy warning)

      Unless they've moved off Windows there's your example.

    7. Re: Start with the headers by Grishnakh · · Score: 1

      Interesting. I was actually thinking of the infamous case when a US Navy ship running Windows NT had to be towed to port.

    8. Re: Start with the headers by iluvcapra · · Score: 2

      The "towed to port" story was apocryphal, though it was a nasty crash according to all reports. In Microsoft's favor, the particular ship involved was a testbed where failures of all kinds of new systems are to be expected, even ones that result in the ship losing power and requiring a tug.

      --
      Don't blame me, I voted for Baltar.
    9. Re: Start with the headers by Anonymous Coward · · Score: 0

      We used to trade %40 of the power in north America with an Access app.

    10. Re:Start with the headers by inasity_rules · · Score: 3, Interesting

      I maintain a huge C++ codebase written by someone else. Pointers are no problem at all. The structures and classes they point to are all defined somewhere. The problem is, after loads of features tacked on randomly, the code has become unmaintainable. Core features break other core features and ugly hacks abound. Also Microsoft's OLE library breacks because the original coder did some extreme use case things that expose a long unfixed bug in modern OLE32.dll libraries. Working with code like this leads to the conclusion, that once understood, sometimes it is better to reimplement the whole thing building in all the core functionality from the base.

      This has been my practical experience with fairly well written C++ code. Comming from an embedded angle, there should be no problem understanding what the code does, or the data it works on, but maintaining or extending it may be a lost cause.

      --
      I have determined that my sig is indeterminate.
    11. Re: Start with the headers by angel'o'sphere · · Score: 1

      You certainly would expect that a similar system was set up on land first.

      The latest thing a sailor is expecting that his ship loses power due to a computer failure.

      Even less on a warship!

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    12. Re: Start with the headers by karnal · · Score: 2

      So, the end result was the ship NOT running Windows NT?

      --
      Karnal
  3. How to read code by girlintraining · · Score: 5, Insightful

    What are your tricks for quickly getting to grips with code written by others?

    For me, it comes down to a lot of mountain dew, techno music, and hours of guru meditation. As you dissect each function, sketch out its relationship to other major functions. I take a two pass approach .. first, just look at the function call outs and the return values and make a rough sketch of the 'scaffolding' of a program. On the second pass, any function that you can't see the obvious application of, or appears obfusciated or complicated, dissect into functional units and sketch out what it does in your notes. I do this by actually physically drawing the relationships using something called a mind map.

    Until you get used to it, actually writing it down, even if it's just a bunch of messy arrows to blobs of circled text... it will help job your memory and help things sink in until you have the necessary 'ah ha!' moment.

    YMMV.

    --
    #fuckbeta #iamslashdot #dicemustdie
    1. Re:How to read code by BorgeStrand · · Score: 1

      Thanks! Are there tools that do this automatically? I haven't worked much with Doxygen and usually pick the programming environment most commonly used for the programming target. I've had some good experiences with Eclipse based editors but find the learning curve a bit steep. On the easy and less powerfull end I use Programmer's Notepad and grep in Cygwin.

      But if there are good automated tools, I'll take the time to teach myself how to use them.

      By the way, the code is for an open source windows driver.

      Borge

    2. Re:How to read code by Anonymous Coward · · Score: 0

      Understand can draw some nice looking call graphs.

    3. Re:How to read code by cdp0 · · Score: 5, Informative

      Are there tools that do this automatically?

      Have a look at Scitools Understand.

    4. Re:How to read code by girlintraining · · Score: 0

      Thanks! Are there tools that do this automatically?

      If there were, we would have little need for programmers. Sorry, but sometimes paper and pencil is the best approach. :/

      I've had some good experiences with Eclipse based editors but find the learning curve a bit steep. On the easy and less powerfull end I use Programmer's Notepad and grep in Cygwin.

      Honestly, I wouldn't get too comfortable with a given IDE -- some of them (I'm looking at you, Visual Studio) abstract away and hide a lot of the code and it can make for some really confusing times for you. Just open up the raw .c or .cpp files with whatever is comfortable... anything with color coded formatting... and then just sit back and try to absorb it without any preconceptions.

      Programming is a lot like sketching or other forms of art. It works best if you don't try and think about it. Thinking about is forcing it... and you'll find the best hackers tend to learn by osmosis... that is, they throw themselves in it, and trust that they'll absorb context and meaning as they walk through the functions and lines as they go...

      --
      #fuckbeta #iamslashdot #dicemustdie
    5. Re:How to read code by ian-sdot · · Score: 1

      +1. I've been using Understand since 1998 across multiple code bases C/C++ and Java. The cross reference facilities are really impressive if you take the time to set up the classPath or include settings. It also has an impact analysis feature so that when you make a change it will show the modules that are impacted by that change. Useful for identifying how much testing will be needed.

    6. Re:How to read code by Anonymous Coward · · Score: 0

      tl;dr version: Call Graphing, Function Tree Plotting, and Dependency Analysis.

    7. Re:How to read code by jones_supa · · Score: 2

      Honestly, I wouldn't get too comfortable with a given IDE -- some of them (I'm looking at you, Visual Studio) abstract away and hide a lot of the code and it can make for some really confusing times for you. Just open up the raw .c or .cpp files with whatever is comfortable... anything with color coded formatting... and then just sit back and try to absorb it without any preconceptions.

      Can you elaborate on that? I haven't seen Visual Studio hiding any code.

    8. Re:How to read code by stephanruby · · Score: 3, Informative

      For me, if I can't understand code written by someone else (which happens much more frequently than I care to admit), I'll do a spike and I'll try to rewrite the core functionality from scratch. Now don't get me wrong. This doesn't mean that my code will be half as good as the original implementation, in fact, it won't be for sure, since I won't spend much time on it. For me, that exercise is just a way for me to initially orient myself (and I do not keep the code I write during that phase).

      If I'm lucky enough to have a good original version history of the code base, I'll go and pull up the original 0.1 version of the code (while I'm doing my own rewrite). Even if that version of the code is completely wrong. It still has a much higher chance of being something I'll understand. And then, I'll have a better understanding of what the developers were trying to do in the subsequent evolution of the project. Then, I'll isolate the parts of the latest code base I can safely break without breaking the entire thing, and I'll focus on those parts first.

      Of course, during that next phase, I'd like to say I write unit-tests for the parts I modify before I modify them, but that's usually not how I work. I'll often have to fall down flat on my face a couple of times, cry in pain and frustration, and tear my hair out, before I'm willing give up and go back to doing things properly with unit tests. This does happen quite frequently, because I never seem to learn my lesson.

      And of course, like someone else said already, I will also draw all kinds of mind maps and doodles throughout the entire process. And also, if I have access to one of the original developers who wrote the code, that's even better. If I can pair program with one of those persons, that's the ideal. If I can't, then talking to that person is the second best alternative. That person will be the best person to know all the weak points of his code base, give you a thumbnail overview of the architecture, and he will also be the best person to point out what parts you can work on first (so that you can gain confidence and a gradual understanding) that are the least likely to break the entire thing.

    9. Re:How to read code by Anonymous Coward · · Score: 0

      Proof that you don't code. If you honestly thought that simply being able to decipher what someone's code does is the same thing as writing code then you've never coded.

      You can almost see your credibility growing as you make a decent point.

      So shut your fucking mouth. You know nothing

      And there it goes.

    10. Re:How to read code by ranton · · Score: 4, Insightful

      Honestly, I wouldn't get too comfortable with a given IDE -- some of them (I'm looking at you, Visual Studio) abstract away and hide a lot of the code and it can make for some really confusing times for you.

      Honestly, I would take more time to get comfortable with a given IDE so you can actually use it well instead of feebly. A good IDE like Visual Studio rarely abstracts away anything that you aren't trying to abstract away. And since most of the time you want almost every part of your program to be abstracted away from you, ,which is most of the power of a good IDE, this is what makes an IDE so useful.

      Not being competent with a good IDE is far worse than not completely grepping your coding environment at a low level. At least in today's world (I had a different opionion 15 years ago). Google and coworkers can fill in a lot of gaps in knowledge when necessary, but spending day in day out using an IDE and never realizing how much better it is than command line tools is a big waste of productivity.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    11. Re:How to read code by Anonymous Coward · · Score: 0

      Seconded. That, combined with this:

      Programming [...] works best if you don't try and think about it.

      made me pitch a giant WTF fit in my head.

      Visual Studio does have an annoying tendency to collapse folds in the most irritating way possible (and my co-workers LOVE adding manual folds), but I've never had it hide anything so that I had to use another editor to find it (although it's sometimes easier to find something in a .csproj file if you don't already know where to look in the UI).

    12. Re:How to read code by mooingyak · · Score: 1

      For me, if I can't understand code written by someone else (which happens much more frequently than I care to admit), I'll do a spike and I'll try to rewrite the core functionality from scratch. Now don't get me wrong. This doesn't mean that my code will be half as good as the original implementation, in fact, it won't be for sure, since I won't spend much time on it. For me, that exercise is just a way for me to initially orient myself (and I do not keep the code I write during that phase).

      This is especially helpful in understanding some of the "Why the hell did he do it like THAT?" questions you get when reading someone else's code. Sometimes it's because the original developer was an idiot, but very often it's because you haven't fully grasped part of the problem yet. Or as I like to put in when I need to communicate in cliche-esque speak, "It's a lot easier to appreciate a round wheel when you've built a square one."

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    13. Re:How to read code by girlintraining · · Score: 1

      Can you elaborate on that? I haven't seen Visual Studio hiding any code.

      Mostly the initialization routines. In the old days, it would have been called winmain() and it would do all kinds of (pretty standard) initializations before regurgitating a useful handle to a window that you'd then nail the rest of your code to. It can also be frustrating when it derps on some dependency and you have to go searching for the right reference to add. When it derps hardcore, it won't even display the full IDE, spitting out a clusterfuck of errors over something you deleted but forgot to remove all the references to, and throws a shit fit... and you wind up having to rebuild the entire project and copy pasta your code into the new one to get it to build clean.

      Visual Studio is fine for "lightweight" programming, but when you leave the sandbox Microsoft has made for you, shit gets real ugly, real fast.

      --
      #fuckbeta #iamslashdot #dicemustdie
    14. Re:How to read code by laejoh · · Score: 1

      Out of curiosity, what do you mean by guru meditation? Back in my younger days it meant a crash! See http://en.wikipedia.org/wiki/Guru_Meditation for more information. Are you implying hacking at the software or do you mean contemplating about the software?

    15. Re:How to read code by Anonymous Coward · · Score: 0

      Doxygen works mostly on assumption people held to the commenting rules which is often not the case but it can also show you general structure of your classes etc. so it is a good place to start. I hated eclipse until I saw how easy it is to traverse the code - now I hate it still but I like some of its features. Beware however that GP most likely meant that the process of drawing your own picture is supporting process of understanding the product.

    16. Re:How to read code by Anonymous Coward · · Score: 0

      Of course, during that next phase, I'd like to say I write unit-tests for the parts I modify before I modify them, but that's usually not how I work. I'll often have to fall down flat on my face a couple of times, cry in pain and frustration, and tear my hair out, before I'm willing give up and go back to doing things properly with unit tests. This does happen quite frequently, because I never seem to learn my lesson.

      I'd like to say I do those things, too, but my clients are never willing to pay for it.

      - T

    17. Re:How to read code by Anonymous Coward · · Score: 0

      Huh. You wanna play the 'hidden code' game? Open up something in Labview's GUI where there's lots of sequences and state-machine-crap embedded.

    18. Re:How to read code by chrismcb · · Score: 1

      Honestly, I wouldn't get too comfortable with a given IDE -- some of them (I'm looking at you, Visual Studio) abstract away and hide a lot of the code and it can make for some really confusing times for you. Just open up the raw .c or .cpp files with whatever is comfortable...

      I don't know what you think an IDE does, but any good IDE pretty much ONLY allows you to work on the "raw" .c or .cpp files. IDEs will usually have dialog editors that allow you to visually edit the resource files. But this is about the only "abstracting" away an IDE will do for you. Of course the advantage of using an IDE, the IDE will allow you to jump around and access definitions and declarations much easier.

    19. Re:How to read code by Anonymous Coward · · Score: 0

      great post. yeah, you gotta get a good overview and it must have in it a lot of nitty gritty. without this, yr just going to add another problem source.

      thanks very much for yr service to the community

  4. Find a good editor/IDE by Anonymous Coward · · Score: 1

    Find a good editor or IDE that allows you to quickly navigate the code.
    Figure out how to build it
    Figure out how to test it
    Read the API docs. Understand the objects and how to interact with their interfaces.

    YMMV, depends on how smart you are I guess.

    1. Re:Find a good editor/IDE by andreiolaru · · Score: 1

      This. And you IDE shouls have an easy way to go to the declaration of variables and methods, classes, etc, as well as a way to see the Call Hierarchy - who calls a certain method / variable and where.

  5. The only way by Anonymous Coward · · Score: 2, Funny

    Look straight at the code for a few hours without moving an inch. After that its details should be printed into your brain.

    1. Re:The only way by Anonymous Coward · · Score: 0

      ...After that its details should be printed into your brain.

      So then it'll then speed up like running it on a ramdisk?

  6. Unit Tests by Anonymous Coward · · Score: 5, Informative

    If possible, I would try writing unit tests for the existing code. This tests your understanding of what you are reading and will come in handy later if you change the code. If unit tests already exist then I suggest that you read them since they will tell you the intention of each function.

    1. Re:Unit Tests by benjfowler · · Score: 1

      Please, mod parent up. This is excellent advice, particularly when you're refactoring.

    2. Re:Unit Tests by Anonymous Coward · · Score: 0, Insightful

      Mod parent down.

      If you don't "understand" code, in this context this means you don't know what its good for (what requirements it fulfils), but only what it does (which is the information you're getting from reading the code). Therefore, it's impossible to write any test-case for it, except one that verifies that it does what it does. And that's pretty useless, unless your plan is to test the compiler.

    3. Re:Unit Tests by skids · · Score: 4, Insightful

      This. Looking at existing tests is also very educational. They often show where the codebase was confusing enough to cause recurring regressions.

      The other place to make very, very sure to read is the repository commit logs, if you have them. They'll tell you a lot about why the code is in its current state, and will often show you where refactors have been left half-complete.

    4. Re:Unit Tests by gd2shoe · · Score: 5, Insightful

      No, unit tests are a good idea. They wouldn't be my first choice, but they're a good option when deciphering a particularly difficult project.

      (1) It gets you to interact with the code. This is always a good idea when leaning how something behaves. Fiddle with it for a while and see if you can figure it out.

      (2) The unit tests don't need to be particularly true to their original requirements to be useful. When you do eventually start making changes, the law-of-unintended-consequences comes into play. If you make a change and one of your unit tests starts failing, then it will give you a clue that things may be interacting in a way that you did not anticipate.

      --
      I won't join Slashcott. OTOH, If Beta goes live, I just won't be back until it's fixed. Sorry Dice.
    5. Re:Unit Tests by dotancohen · · Score: 2

      If possible, I would try writing unit tests for the existing code. This tests your understanding of what you are reading and will come in handy later if you change the code. If unit tests already exist then I suggest that you read them since they will tell you the intention of each function.

      Unit tests are a lot like documentation: they will tell you what the code is _expected_ to do. (Not what the code actually _will_ do, especially in corner cases). Thus, if you are already digging in to see what any section of code is doing, document what you've found: write a unit test.

      --
      It is dangerous to be right when the government is wrong.
    6. Re:Unit Tests by Anonymous Coward · · Score: 0

      Therefore, it's impossible to write any test-case for it, except one that verifies that it does what it does. And that's pretty useless, unless your plan is to test the compiler.

      It's pretty damn useful when your goal is to learn what it does. The point isn't to make good unit tests, it's to learn, and to make a scaffolding that warns you when you've broken something. You can make better unit tests once you understand the program.

  7. Main or Bugs by Anonymous Coward · · Score: 0

    It depends on what you need to do. I usually start with main and trace through it slowly but surely. Usually it takes me a week or two to fully comprehend the pieces of the code to the point where I feel comfortable with making big changes.

    Another approach is to find some small bugs that need fixing and fix them. Something that will force you to have to find what function the bug is in and then step through the code with a debugger.

    Good luck!

  8. Practice by Anonymous Coward · · Score: 0

    Lots of practice reading and writing C++ code. Reading decent books like the Addison-Wesley C++ series edited by B. Kernighan helps, although the snippets of code presented by the authors aren't representative of a real code base.

    If there's any documentation, read that first. Usually there isn't much, or not nearly enough, and the code has been written by multiple programmers at different times.

    Google for tutorials and sample code on the relevant external APIs.

  9. Tried once to read MS C++ STL implementation by Anonymous Coward · · Score: 0

    I gave up !!!!
    Same think can be said about my attempt to read EXT2 source code.......

    1. Re:Tried once to read MS C++ STL implementation by Immerman · · Score: 1

      In fairness I don't think I've ever read *any* STL implementation that wasn't hideous. Seems like non-trivial template programming internals are sort of like VB - without exhaustive self-discipline the result defaults to hideous abominations you pray you never have to look at again. And it doesn't help debugging that compilers all seem to be optimized to deliver maximally-obfuscated error messages if they encounter a problem related to templated code.

      Don't get me wrong, I love templates and even engage in metaprogramming from time to time, but there must be a better way.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
  10. Read someone elses Perl code first by jd2112 · · Score: 4, Funny

    Everything else will seem simple after that...

    --
    Any insufficiently advanced magic is indistinguishable from technology.
    1. Re:Read someone elses Perl code first by Anonymous Coward · · Score: 1

      Have written a perl script to not my displeasure your comment.

      +=^~#}{$&;"?!,.'

    2. Re:Read someone elses Perl code first by c0lo · · Score: 1

      Everything else will seem simple after that...

      Everything? I doubt it.

      --
      Questions raise, answers kill. Raise questions to stay alive.
    3. Re:Read someone elses Perl code first by broknstrngz · · Score: 2

      Better yet, read your own 3 year old Perl code. Everything else will seem simple after that...

    4. Re:Read someone elses Perl code first by fyngyrz · · Score: 2

      I can vouch for this.

      Reading old Python? Easy. Reading old C? Easy. Even reading old C++? Not too bad.

      But... reading old Perl after a break from the language? I need to go re-learn the language, find out what all the obscure special variables do, do a complete refresh on regular expressions (remember when that was how people routinely parsed text? omg/lol), re-learn the broken parts (like, no 2D or higher arrays) and how the work-arounds look, and that only *preps* you to read the old code... it's still like slogging uphill in molasses.

      I give Perl credit where it's due: It's pretty fast for a scripting language. Back when I wrote in it, knowing a lot less, and pre-Python, it did seem like the best choice. That was the mid- to late-90's.

      But I would *never* use it again. Right now, for scripting, Python (2-series) is the choice I'd make, I'm utterly comfortable in it, it's totally easy, almost transparent to read, or at least the way I write it, it is, it's powerful as heck and it is also very fast, the exception mechanisms allow really solid, dependable code to be written in a very, to me, intuitive manner. Database interface is a doddle, in fact pretty much any common task is a doddle. Just a great language all around.

      I do keep one snippet of perl code around: The code that lets me call an external Python procedure, so that when old Perl needs attention, if it isn't time-critical, it can get it by replacement. A huge time saver, many times over.

      Otherwise, C or C++, depending on what the task is. I can read my old c code easily; I was always very conservative and consistent about bracing, tabbing, and so on, and I'm a liberal commenter, so generally the code is well explained too. Other people's code does throw me though... all you have to do is throw K&R style formatting in there and I immediately lose track of the brace levels, and it goes downhill from there. Luckily, I'm not in a position where I have to deal with anyone else's code except those who work for me, and therefore do it my way anyhow.

      --
      I've fallen off your lawn, and I can't get up.
    5. Re:Read someone elses Perl code first by jd2112 · · Score: 2

      Coding in Perl with a chronic case of CRS taught me the importance of writing legible code. After rewriting my own code a few times because I couldn't figure out how it worked I found that writing legible code is even more important than writing well documented code. And one you learn to write legible code in Perl (yes, it can be done) you can do it in any language.

      --
      Any insufficiently advanced magic is indistinguishable from technology.
    6. Re:Read someone elses Perl code first by Anonymous Coward · · Score: 0

      Don't blame the language for your lack of / inability to code clearly.

    7. Re:Read someone elses Perl code first by Anonymous Coward · · Score: 0

      That is interesting - possibly worthwhile knowing view into your world. However the actual q. that started this thread was about exactly opposite situation: the guy has not own but foreign code, written most likely by different people without adhering to one coding standard whereas you talk about a code base that you either wrote yourself or told other people to write and controlled afterwards if they did what you asked for. In a sense you gave two advices : instead of working for other people and using other people software go write one yourself and arrange for a company that you own so that other people have to follow your rules. The second advice is actually perfect unless of course your company grows big enough for you not to be involved in software coding matters and have some coding standards on its own together with guardians of those standards etc.

    8. Re:Read someone elses Perl code first by Anonymous Coward · · Score: 0

      hmm I must say I got confused and interested too: wiki gave me a lits of CRS of which only term I found moderately relating to the subject oft his discussion would be 'Colorectal surgery'. Indeed directly after such surgery you cannot sit all that easily for a while so long periods of staring into code are not possible.

    9. Re:Read someone elses Perl code first by fyngyrz · · Score: 2

      Somewhere, I have a coffee cup that says CRS on it in large letters, and underneath reveals this to stand for "Can't Remember Shit"

      I love that cup. Wish I knew where it was.

      --
      I've fallen off your lawn, and I can't get up.
    10. Re:Read someone elses Perl code first by fyngyrz · · Score: 1

      I was responding to advice to read your own code first. You need to follow the context in order to understand who is responding to what. Lots of subthreads exist, and they tend to vary in direct relevance.

      --
      I've fallen off your lawn, and I can't get up.
  11. manage your mood by Anonymous Coward · · Score: 1

    They will be doing horrible, horrible things from your point of view. Manage your mood, to be able to stick to the goal.

  12. Basic pointers by rolandomartins · · Score: 1

    1) Start by understanding completely the target language, in this case C++. 2) Get a IDE that is able to provide full support for finding references and definitions in C++. For now only Netbeans CND is able to proper do that for Linux-based OS. Alternative for WindowsOS use Vision Studio. 3) Then you just have to start reading the code and build the mental map of the project.

    1. Re:Basic pointers by DarkOx · · Score: 1

      You should have a look at Codeblocks. Its a nice IDE and it does a pretty good job. Runs on Linux

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
  13. Read, read, and read by Horshu · · Score: 1

    Read as much code of as many different styles as you can. Eventually, you will hopefully start just getting a feel for programming much like music, where different code has different styles. You'll see manifestations of different patterns and start to gain a deeper understanding of it (it can have an almost zen-like quality to it)...why certain patterns get used, why certain developers use patterns that don't make sense to you, what kind of developers the authors are. It took me years before I started to get a feel for reading other people's code, but I have an idea as to how good a programmer is and even what kind of everyday personality they have from reading their code. It really is like music. And one more thing: don't count on comments for guiding you through this; it's rare to come across well-commented code, especially in a professional environment (ironically enough).

  14. Doxygen by mapinguari · · Score: 5, Informative

    Even without Doxygen's specific format for comments, you can use it to graph object relationships, call-trees, etc.

    You can generate docs limited to a few files or classes if you just want to focus on them.

    www.doxygen.org

    1. Re:Doxygen by Anonymous Coward · · Score: 1

      Doxygen is a steaming pile of poo. A poor substitute for actual, thought out, written documentation. Speaking as someone who has had to read doxygen generated docs a LOT, I can tell you that just reading the code is easier. They're practically worthless 99.9% of the time.

    2. Re:Doxygen by Immerman · · Score: 1

      Well what do you expect? Lazy programmers focussed strictly on functional components result in comments that are useless 99.9% of the time. GIGO. Have someone go in and incorporate decent documentation into at least your top-level comments and doxygen will collect them into reasonably well organized hyperlinked documentation that can be easily kept up to date by simply updating the comments when the associated code changes. Of course nobody will bother to do that so it will rapidly become useless again, but hey, tat's not doxygen's faule. Hire some decent technical writers to keep your comments up to date.

      Yes, I'm lazy too, but when writing good code, especially interfaces, I spend at least as much time on the comments as the code. In fact I often write the comments first just to keep myself honest.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    3. Re:Doxygen by Anonymous Coward · · Score: 0

      Exactly. Most of the comments are obtuse at best, meaningless at worst. I am chief offender #1 with crap comments. About 100% of my comments are meaningless outside of what I was thinking at that particular time. I prefer to design the architecture so it is reasonably easily to understand without comments, while documenting it by hand elsewhere. That said, the only option the OP has is to read, read it again, read it some more, pause, breathe, really read it, then read it while listening to yourself reading it from earlier. Then pass out.

    4. Re:Doxygen by SLi · · Score: 1

      +1

      Doxygen has for years been my tool of choice for grokking complex, undocumented code bases in any of the languages it supports. Give it a try. You will be surprised how much good documentation can be automatically generated even without document comments.

  15. pretend you are the computer by Laxori666 · · Score: 3, Informative

    First, figure out how the code gets loaded and runs. Find the equivalent of the 'main' function. Then start tracing it, seeing what functions get called, how things are loaded, etc. What really helps here is an editor you can CTRL+click on a function on to go to its definition. When you hit a function that doesn't call any other unknown functions, then you can start understanding what it does without having to step into it. These are the basic functionality units. Then when you know enough of those, you can start going a level up, etc. Eventually a picture forms in your mind of just how things work. You can optionally skip over functions for preference of looking at them later if it seems pretty clear what they do based on the name & how they're called, but you might find important stuff in there later. This is how I go about it, anyway. It can be very frustrating and very confusing at first, but eventually the picture starts making sense, then things click in a most satisfying manner. That being said, the above is also the reason I can dislike complicated frameworks. There's so much indirection that it can take quite a while indeed until you hit something concrete. The mark of a good framework is, either it doesn't do that, or it does but soon enough you figure out its parts and then you can treat it intuitively.

    1. Re:pretend you are the computer by taoboy · · Score: 1

      Yep, find main/WinMain, work your way down...

  16. Reformat, Reformat, Reformat by zieroh · · Score: 4, Insightful

    I find that going through some key functions (assuming you can find them) and reformatting them to your own liking can be helpful, commenting code along the way. Then if you want to get more aggressive, start cleaning up some code in minor ways that still stay true to the function's meaning. After you've done a bit of that, you should probably have at least a vague idea what's going on.

    --
    People who say "sheeple" have about as much sophistication as an AOL user, and in fact are probably actually AOL users.
    1. Re:Reformat, Reformat, Reformat by MAXOMENOS · · Score: 1

      This is good advice. I've gotten to know the guts of some massive core systems mostly by cleaning up code, making minor bug fixes, and adding a new feature (10 digit SSNs instead of nine).

      Openhatch is a great place to get started....

    2. Re:Reformat, Reformat, Reformat by Anonymous Coward · · Score: 0

      It is good advice, but unfortunately you only saw what you wanted to see and missed the good advice. GP specifically says to discard the results. This is not refactoring. This is understanding existing code without forcing changes on everybody else.

      The subtle point makes the difference between a superstar and a primping prima donna who has to change all of the code to their liking. I've had the pleasure to work with superstars and the extreme displeasure to work with the prima donnas.

  17. Run, run, and run by Anonymous Coward · · Score: 1

    I disagree with reading too much code.

    Run the code to see what it does. Add some printfs to validate the understanding of what the code is doing.

  18. Try some good quality marijuana by stevegee58 · · Score: 4, Funny

    It won't help you understand the code but you'll stop worrying about it so much.

  19. Format / Edit the Code by ionrock · · Score: 1

    I've found the best way to learn a code base is to start editing it. There are almost always formatting details and names that don't feel right. Start changing those and see what happens. The process will force you to understand the logic and help you really understand the code. Even if you throw all your formatting changes away, you'll definitely learn something.

    Hopefully, the project has tests as well that will let you see if your formatting changes break things, in which case you've begun to understand the relationship between different code blocks.

  20. Don't by Anonymous Coward · · Score: 0

    C++ is a very very different language from C, it's way more powerful and so more complex: It will take time (a lot of it) to learn first C++. The C skills are pretty much useful as the first 50pages in the C++ book: you've still 850 more to go from there.

    1. Re:Don't by jones_supa · · Score: 1

      A person is a genius if he knows every nook and cranny of C++. But no one is expected to. Even just classes and objects are a fantastic addition over C, so there is really no reason to shun C++.

    2. Re:Don't by Anonymous Coward · · Score: 0

      A person is a genius if he knows every nook and cranny of C++.

      No, they're a specialist. Undoubtedly bright, maybe a Ph.D type, but not necessarily brilliant.

    3. Re:Don't by mooingyak · · Score: 3, Interesting

      A person is a genius if he knows every nook and cranny of C++. But no one is expected to. Even just classes and objects are a fantastic addition over C, so there is really no reason to shun C++.

      The problem is that taking C and just adding classes and objects would have been nice, but the changes in C++ go so far beyond that they can reach a perl-like level of syntax confusion.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    4. Re:Don't by jones_supa · · Score: 1

      The problem is that taking C and just adding classes and objects would have been nice, but the changes in C++ go so far beyond that they can reach a perl-like level of syntax confusion.

      You still have that option. Just take the basic OOP parts and don't use the crazy stuff at all. :)

    5. Re:Don't by mooingyak · · Score: 1

      The problem is that taking C and just adding classes and objects would have been nice, but the changes in C++ go so far beyond that they can reach a perl-like level of syntax confusion.

      You still have that option. Just take the basic OOP parts and don't use the crazy stuff at all. :)

      That's a good idea when you're the one writing it. It's not always in your control when you're maintaining.

      --
      William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
    6. Re:Don't by toddestan · · Score: 1

      Unfortunately, if it's someone else's code that got dumped in your lap, you're pretty much stuck figuring out what crazy stuff the original programmer(s) managed to do with C++.

  21. A mandatory declaration. by Anonymous Coward · · Score: 0, Offtopic

    We will feast on what is inside!

  22. Start with the foundation... by Anonymous Coward · · Score: 0

    First I'd start by learning the library/apis it is using. Write a few test programs in them to solidify the knowledge. Work your way up, layer by layer... which is the way you'd write it in the first place.

  23. Bug hunting by tinkerghost · · Score: 3, Insightful

    I recommend starting by working on the bug list. It gives you something to work on constructively and it also makes you look through all the code to track the problem.

    1. Re:Bug hunting by MerlinTheGreen · · Score: 1

      This is right on the money.

      Don't learn the code base. Work on something. Change something. Do something.

      If you're worried about breaking stuff then read back the change very carefully and follow all the impacted variables (and data types) back in a source navigator. That is when you really start learning because there's some focus. Following the variables back also gives you an insight into how to write a test case for your new work.

      However for me the biggest myth in programming is that you have to understand how it all works. You only need to understand a couple of really basic common idioms (approach to threading and thread-safety, coding style) before diving in. The new code doesn't have to be right... merely make the code base better than it was before.

  24. Write your own documentation by Required+Snark · · Score: 1
    As others have said, read the code. Do this top down; start at the main function and look at the call tree.

    As you are doing this, start generating you own documentation. If the code doesn't use DOXYGEN, add that. Reformat and add comments. Write external documentation. When you are documenting, think of what you wish the previous coders had done for you, and then do that.

    This is the way I write code from the beginning, and it leads to better code. If I can explain what is going on then I know I understand it. If I can't explain it, then there is a pretty good chance that there are bugs. It's good practice whether you are taking over someone else's code or starting from scratch.

    --
    Why is Snark Required?
  25. Reading code is hard by benjfowler · · Score: 5, Insightful

    The trouble with university education, is that most people who teach there are computer scientists, not software engineers with years of experience in the trenches.

    If this were actually the case, there would be a recognition that reading code is far harder than writing it. And far more emphasis would be on coming to grips, understanding, and working on large code bases. There'd be more stuff on things like unit testing, breaking dependencies, troubleshooting, and refactoring at least.

    1. Re:Reading code is hard by Anonymous Coward · · Score: 1

      The trouble with the lack of a university education, is that you drone on for a paragraph instead of simply saying "We need more emphasis on how to reverse-engineer code."

    2. Re:Reading code is hard by reluctantjoiner · · Score: 1

      At the university I attended, courses did include some of that material, and I doubt it's curriculum was anything out of the ordinary. I recall a project where we had to document sed, the UNIX utility, using only it's source code for reference. (I know that doesn't count as a large code base, but there's limited time available) Even if the only point was to experience the feeling of being handed a vast code base to maintain with no documentation, I'd say it was a success :)

      I think I'd rather try to prove programs correct using Hoare logic than do something like document sed again.

    3. Re:Reading code is hard by Zalbik · · Score: 5, Insightful

      he trouble with university education, is that most people who teach there are computer scientists, not software engineers with years of experience in the trenches.

      Exactly. And it's why I always encourage programmers to write for readability rather than for terseness or whatever the latest cool tool is. Code is also read many more times that it is written.

      I'd much rather see a procedure that takes 10 lines is immediately obvious what it does than an "optimized" 5 line procedure that takes some head scratching to figure out.

      People who claim "more lines of code mean more probability of error" are typically very wrong. .

    4. Re:Reading code is hard by Anonymous Coward · · Score: 0

      That is why community colleges were created.Universities are supposed to make you think by using many other tools from other areas of knowledge. If you have only a mechanic can teach mechanical engineering, what happens when the whole technology has changed? Who will teach you and will you have enought basic background knowledge to learn further. What you shoul be asking is, in addition to my theoritical knowledge, can I intern with some company to learn the skill sets that are not taught at the university level. Skill sets development if possible if you have ability to learn skills. So, instead of complaining, tell some psoitive ways the questioner can learn.

    5. Re:Reading code is hard by CodeBuster · · Score: 1

      There'd be more stuff on things like unit testing, breaking dependencies, troubleshooting, and refactoring at least.

      A big obstacle to more unit testing, breaking of dependencies and refactoring in industry is that all of these things take time and effort, time and effort that could be put into new code and features, and mostly for things which have little or no immediate business payoff. To invest in these things is to invest in the future of the code base and the productivity of future programmers who may come in years after the code was written or long after the original programmers have moved on. In an industry that often moves at "Internet speed" these practices are seen as luxuries to be indulged in by larger and more established companies, not startups that have to compete now or be gone in six months. So industry is just as much at fault, if not more so, for the lack of these things in practice. Indeed, it's often said that breaking dependencies, writing unit tests and refactoring are like eating vegetables; we all know that we should do it but few of us actually do. Finally, it doesn't help when you have large and established companies like Facebook saying, "move fast and break things" and sponsoring "hackathons" to crank out features and change code quickly, maintainability and testing be damned.

    6. Re:Reading code is hard by benjfowler · · Score: 1

      Cranking out fresh code is all nice and lovely, but for a couple of observations:

      1) old code is generally much better tested, and more likely to be free of defects.
      2) a feature is an asset, but a line of code is a liability (you have to maintain it)

    7. Re:Reading code is hard by angel'o'sphere · · Score: 1

      I agree that a "refactoring project" is expensive and you have to figure for yourself if it is worth it.

      However I did not see teams for decades that did not refactor continously while developing.

      If you do XP or Scrum it is more or less mandatory that you keep your code base without "technical depts".

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    8. Re:Reading code is hard by Anonymous Coward · · Score: 0

      The trouble with university education, is that most people who teach there are computer scientists, not software engineers with years of experience in the trenches.

      If this were actually the case, there would be a recognition that reading code is far harder than writing it. And far more emphasis would be on coming to grips, understanding, and working on large code bases. There'd be more stuff on things like unit testing, breaking dependencies, troubleshooting, and refactoring at least.

      And it would reduce or mitigate the terrible, unreadable code that comes out of fresh grads (and some veterans of programming).

      Nothing encourages creating an unmanageable code base more than never having to look at it once the project is done. College students, when you become big boy and big girl programmers in the REAL world, no project is EVER done and gone like it was in class. Think of university coding as using a diaper: every semester, all your code poop gets cleaned up and thrown out, and you don't have to sit in it. Professional coding is more like pants: if you poop all over, you get to clean it up. Depending on how / when you do it, co-workers and bosses may be unsympathetic at best and severely upset at worst.

      I've seen some of my early code and said "who was this idiot? who would ever think this was a good idea? .... oh ... nevermind"

    9. Re:Reading code is hard by Hognoxious · · Score: 1

      Well that plus you, don't know where, to, put c,o,m,m,a,,,,,,s.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    10. Re:Reading code is hard by Hognoxious · · Score: 1

      Neither universities nor community colleges can teach Joe_Dragon how to remember his password.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    11. Re:Reading code is hard by CodeBuster · · Score: 1

      If you do XP or Scrum it is more or less mandatory that you keep your code base without "technical depts".

      If by "technical depts" you mean technical debt, forget about it. Most organizations have very large technical debts, but they're invisible because management doesn't care and bean counters refuse to recognize them as debts. Unless and until technical debt is listed in the liabilities column of the balance sheet, with the accounts and notes payable, as real debt with monetary value nobody gives a crap except maybe some of the developers and not even all of them.

    12. Re:Reading code is hard by chrismcb · · Score: 1

      Less is generally better. Fewer lines (I should say fewer statements) are generally easier to read, and typically have fewer errors. Of course that doesn't mean you have to cram everything into one line.

    13. Re:Reading code is hard by angel'o'sphere · · Score: 1

      Well you are half right :D

      Most developers I know really care about the code base. After all they have to dig around in it daily.

      In other cultures that might be different though.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  26. Substances and coding by spasm · · Score: 4, Insightful

    Find out what drugs the original coder was using when writing, and take the same.

    1. Re:Substances and coding by AmiMoJo · · Score: 2

      In all seriousness it can help to find out what books he read and thus what bullshit design paradigms he was into. Also try to get his username on Stack Overflow so you can find all is questions to get an overview of the development process and the challenges he faced.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    2. Re:Substances and coding by Anonymous Coward · · Score: 0

      Also try to get his username on Stack Overflow so you can find all is questions to get an overview of the development process and the challenges he faced.

      I fucking hope you're not being serious.

    3. Re:Substances and coding by Anonymous Coward · · Score: 0

      In all seriousness it can help to find out what books he read and thus what bullshit design paradigms he was into. Also try to get his username on Stack Overflow so you can find all is questions to get an overview of the development process and the challenges he faced.

      Facepalm... :)

    4. Re:Substances and coding by Anonymous Coward · · Score: 0

      In all seriousness it can help to find out what books he read

      Funny, /. is re-inventing Hermeneutics.

    5. Re:Substances and coding by Anonymous Coward · · Score: 0

      If you have unlimited time, sure. In the real world that time is much better spent reading the actual code, though.

  27. Re: refactor, discard, repeat by Anonymous Coward · · Score: 5, Interesting

    Find a function. Refactor it until you grok it. Discard the results.

    Keep in mind that it will be VERY tempting to commit your changes, but you must throw away the work and chalk it up as a learning experience if you ever want to be taken seriously by the others who work on the project. Junior developers (and even some senior developers) often think they're doing everyone a favor by doing drive-by refactors, but they're not; they're just slowing down the entire team and coming across as that a**hole who keeps f***ing up the diffs and destroying the useful output of tools like git blame.

    If you found any bugs in the previous step, make a patch with the absolute minimal change to fix each individual bug. IMPORTANT: Before committing the patch, first be sure that you can reproduce it in the old code, and that the test case is fixed by your new code.

    Repeat the process until you understand the entire system.

    With any luck, you will finish with a solid understanding of how the code actually works, and you will most likely also fix a few dozen bugs (if you didn't find at least one bug per kLOC, then "you're doing it wrong" or the code was written by an inspired genius with OCD). At that point, you will be the team's expert on how things work, and you will be in a position where you can start proposing simple refactorings that will improve the code quality.

  28. C vs C++ by Rob+the+Bold · · Score: 4, Insightful

    You mentioned you have embedded C experience and the code of interest is written in C++. You didn't mention if you had any C++ or other object-oriented programming experience. I assume the C++ code uses the OO features of C++ that distinguish it from C -- but this assumption is not necessarily true.

    So, if you lack OO experience and the code is truly OO C++ code, you might want to do a little reading up on the basics of OOP in order to spend less time spinning your wheels.

    --
    I am not a crackpot.
    1. Re:C vs C++ by rasmusbr · · Score: 1

      If he's used to working with electronics he'll probably find the basics of OOP quite easy to grasp.

      OOP : Electronics
      Object : Component
      Class : Production line
      Public functions/methods : Interconnect
      Private functions/methods : Internal connections

      Even this basic mental model naturally leads to interesting theoretical questions like "can a program generate a class at run time based on information that it has gathered?". (Probably not in any easy or recommended way in C++ or Java AFAIK.)

    2. Re:C vs C++ by angel'o'sphere · · Score: 1


      OOP : Electronics
      Object : Component
      Class : Production line
      Public functions/methods : Interconnect
      Private functions/methods : Internal connections

      With this fake/fail analogy you miss most interesting parts of OOP and more important the pitfalls of C++.

      OOP: virtual methods, inheritance, multiple inheritance etc.
      C++: templates, constructors, destructors (virtual destructor in the base class) etc.

      Even this basic mental model naturally leads to interesting theoretical questions like "can a program generate a class at run time based on information that it has gathered?". (Probably not in any easy or recommended way in C++ or Java AFAIK.)

      For Java: yes. Worst case you need to write it out to disk and use the compiler. However you can generate the bytecode in ram into an byte array and instanciate that bytecode as class.
      In C++ you unfortunately need the compiler, but ofc you can create a class dynamic! If you know how to load it as a dynamic linked library. (OFC you could do the same as in Java if you knew how to craft the assembly/machine code in memory).

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  29. Rewrite some parts by eulernet · · Score: 5, Interesting

    Here is how I work on legacy code:

    1) I don't look at the whole picture because there are too much details, so I prefer to attack little by little.
    2) I quickly check what I can rewrite in order to optimize the code. If I have no idea, I run a profiler, and take a look at the routines that take the most time.
    3) once I understood or rewrote the most consuming parts (sometimes it's heavily optimized, but most of the time, I can make a real improvement), I decide what most important functionality I would like to add, and I just focus on that.
    4) if I really need to have robust code, I write tests for the routines before optimizing them, so that I can validate if there are regressions
    5) whenever possible, I use "assert" and put some bound-checking tests, in order to validate the ranges of certain values or conditions.

    The important thing is to start by taking ownership of a small part of the code, then a bigger part, etc...
    Take one slice at a time, not the whole pie.
    And one last point: knowing every little detail is useless, concentrate on what is important for you: performance, functionalities, ... ?

    1. Re:Rewrite some parts by Anonymous Coward · · Score: 0

      I always thought, that you'd start at the top, looking for an overview
      with some kind of diagram, of what calls are made, starting with main()
      there used to be "xref" for this, not aware of any tools to diagram / graph the links tho, anyone got any suggested tools?
      then drill down into whatever interests you most.

      Writing those unit tests, tests your knowledge of the application, as well as the code.

      Sometimes if I think, how would I do this?
      It gives me some ideas about how the "original" programmer(s) attacked the problem.

  30. Visual SlickEdit/ Emacs ctags help a lot. by 140Mandak262Jamuna · · Score: 1

    At work I am a big fan of Visual SlickEdit. It builds complete tags of all the functions, variables, classes etc into tags. Allows me to find all callers of a particular function, definitions, references etc. In Linux it will work with gdb to do step through debugging. I believe most of the functionality is available in emacs, with its ctags. Though most developers in our company use Microsoft IDE, I build all my sln files using slickedit and edit using slickedit. It has good integration with version management tools too.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    1. Re:Visual SlickEdit/ Emacs ctags help a lot. by jasno · · Score: 1

      SlickEdit has saved my ass time and time again. I'm a cheap bastard and I hate paying for software, but SlickEdit is worth every penny. I can't imagine dealing with a large codebase without it. Yes, I've also tried cscope+vim and ctags, and it's fine, but SlickEdit is faster and easier to deal with.

      --

      http://www.masturbateforpeace.com/
    2. Re:Visual SlickEdit/ Emacs ctags help a lot. by Anonymous Coward · · Score: 0

      Isn't Komodo IDE better?

  31. Debug by Anonymous Coward · · Score: 1

    I find it useful to follow the flow of control using a debugger. For C/C++, I like GDB in "TUI" mode because I can see the code easily.

    If the program is multi-threaded, it's worthwhile to read up on how to handle threads in GDB. Understanding what's going on in a multi-threaded program can be especially difficult. Having the ability to switch between threads, to get backtraces (so you can see how that thread got where it is currently) and inspect its variables can be very informative.

  32. Swearing helps by Anonymous Coward · · Score: 0

    Especially at the so-called engineers' deceased pet hampsters.

    (going anon for this)

    1. Re:Swearing helps by jones_supa · · Score: 1

      Actually Linus wrote a follow-up for that in rc6. :)

      And I didn't even need to curse all that much at people. Sure, I talked smack about some of your hamsters, and I declined a couple of pull requests, but let's face it, it was pretty halfhearted. Most of the time things were good.

  33. I start reading other's code with... by Tracy+Reed · · Score: 1

    less

    1. Re:I start reading other's code with... by PuZZleDucK · · Score: 1

      You didn't grep into it first? :p

      --
      Can a person program a new solution to a problem? Why should anyone be able to stop such a thing? -Richard Stallman
  34. Keep Some Rules In Mind by Greyfox · · Score: 5, Insightful
    1) Just because your predecessor was paid to program doesn't mean he craps daisies and unicorns. I have often gone in with the assumption that the guy before me knew what he was doing. Quite often I find I was wrong.

    2) Just because the code is awful doesn't mean it has no value -- No matter how bad it is and how difficult it is to read, if it works at all it has probably got years (maybe even decades) of bug fixes and feature requests. Until you have a handle on it, any little change could cause a catastrophic cascade of side-effects.

    3) No, we don't need to rewrite it. See 2. A working program now is worth more than all the pie in the sky you can promise a year from now.

    4) It takes 6 months to have a reasonably good grasp of any moderately complex in-house application. It could be a year before you get to the point where someone can describe a problem and you immediately have a good idea of where in the code the problem is occurring and what functions to check.

    Maintenance programming is as much about detective work as anything else. The only clues you have about the previous programmer are his source files. Once you've read them for a while you can start to tell what he was thinking, when he was confused, when he was in a hurry. Most of the atrocious in-house applications have changed hands several times and each programmer adds their own layer of crap. You can redesign these applications a chunk at a time until nothing remains of the original code if it's really bad, but it's best to save really ambitious projects until you understand the code better. I heartily encourage the wholesale replacement of "system()" calls with better code immediately, though. In several languages I've run across these calls to remove files, when they could have simply called a language library call (Typically "unlink".) If the original programmer used system("rm...") you can pretty much assume that they were a bad programmer and you're in for a lot of "fun" maintaining their code.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    1. Re:Keep Some Rules In Mind by hedwards · · Score: 1

      What, you mean doWhatImean( X ) isn't a valid way of coding?

    2. Re:Keep Some Rules In Mind by Anonymous Coward · · Score: 0

      1) Just because your predecessor was paid to program doesn't mean he craps daisies and unicorns. I have often gone in with the assumption that the guy before me knew what he was doing. Quite often I find I was wrong.

      Corollary, just because each individual member of a good team knew what they were doing when they added to a piece of code, doesn't mean the resultant output isn't utter ****. Sometimes someone needs to look at the bigger picture of the code and notice all the additions are badly hacked into place.

      Maintenance programming is as much about detective work as anything else. The only clues you have about the previous programmer are his source files. Once you've read them for a while you can start to tell what he was thinking, when he was confused, when he was in a hurry. Most of the atrocious in-house applications have changed hands several times and each programmer adds their own layer of crap. You can redesign these applications a chunk at a time until nothing remains of the original code if it's really bad, but it's best to save really ambitious projects until you understand the code better. I heartily encourage the wholesale replacement of "system()" calls with better code immediately, though. In several languages I've run across these calls to remove files, when they could have simply called a language library call (Typically "unlink".) If the original programmer used system("rm...") you can pretty much assume that they were a bad programmer and you're in for a lot of "fun" maintaining their code.

      Pretty well true of almost any time system() is used, whether or not it is for removing files. Then there are tricks like trying to de-quote filenames before passing them through the shell (think filenames with parentheses), instead of carefully avoiding system().

    3. Re:Keep Some Rules In Mind by Greyfox · · Score: 1

      All you have to do to avoid system("rm...") is "man 2 unlink". There's a C API call for every function the OS can perform., It's just a matter of knowing about it or bothering to spend a second googling it. Though google wasn't really an option when some of these things were written. "apropos rm" would probably turn up "man 2 unlink" too, if you knew about apropos.

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    4. Re:Keep Some Rules In Mind by Anonymous Coward · · Score: 0

      If the original programmer used system("rm...") you can pretty much assume that they were a bad programmer and you're in for a lot of "fun" maintaining their code.

      May you please explain why using 'system("rm...")' might indicate a bad programmer?
      Is it because instead of doing it programmatically they offload it to scripting?
      Thanks.

    5. Re:Keep Some Rules In Mind by Anonymous Coward · · Score: 0

      "Just because your predecessor was paid to program doesn't mean he craps daisies and unicorns."

      This.

      I'm taking over some code and it's the most juvenile crap I've ever had the displeasure to set my eyeballs on. I've used Doxygen with the Eclox plugin in Eclipse and it helps but the comments!! GIGO is right.

      I'm fighting the urge to trash it and start again with FreeRTOS (it's embedded) but it's hard to keep plugging at it.....

      DON'T TRUST ANYTHING!! Go in with the mindset that the previous guy/gal was a douchebag (I met him - he is!). Hopefully, you'll come across some code that makes you say, "Hmmmm well that bit isn't all that bad!"

    6. Re:Keep Some Rules In Mind by Tarsir · · Score: 1

      2) Just because the code is awful doesn't mean it has no value -- No matter how bad it is and how difficult it is to read, if it works at all it has probably got years (maybe even decades) of bug fixes and feature requests. Until you have a handle on it, any little change could cause a catastrophic cascade of side-effects.

      3) No, we don't need to rewrite it. See 2. A working program now is worth more than all the pie in the sky you can promise a year from now.

      So very true--take note all you young programmers out there. Especially those of you who are suggesting to dive right in and begin refactoring code immediately. I shudder to think of the damage you can do by "refactoring" code which you've just started investigating and which you don't yet understand.

  35. Document it by ItsIllak · · Score: 1

    Chances are that no-one else has and doing so will help you understand it as well as producing some useful output to get the project going again.

  36. Use the tools Borge by meta+slash · · Score: 0

    Reading other people's code is a punishment that one must master if you hope to grow as a programmer.  My favorite approach these days is to use callgrind and kcachegrind, walking up and down the call stack for each stimulus I can muster.  I often build a custom client to send malformed requests for these tests, it usually becomes part of my unit/regression tests.  Then I make note of the most prominent function names and data structures.  I construct an outline as if I were writing a book.  GDB is also a fantastic tool for understanding software.  You can learn a lot about code merely by setting a break point in malloc or read.  Don't be afraid to use 'set var' to explore an interesting test case.  strace, particularly with -c or -ff, can give you a quick idea of what a program does.  Eventually I start to change it.  First I use indent or some IDE to fix the whitespace, then I start to refactor. Eventually the code begins to look more like something I wrote than what I inherited.  That's how I know when it's time to hand it off to someone else ;)

    1. Re:Use the tools Borge by drinkypoo · · Score: 3, Interesting

      Reading other people's code is a punishment that one must master if you hope to grow as a programmer.

      So what is the reward for reading comments which are unnecessarily set in monospace type?

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    2. Re:Use the tools Borge by Anonymous Coward · · Score: 0

      +5, Interesting, apparently

    3. Re:Use the tools Borge by Anonymous Coward · · Score: 0

      Monospace is actually quite restful for the eyes...

    4. Re:Use the tools Borge by Anonymous Coward · · Score: 0

      being able to write a reply to it???

  37. Architecture Recovery by prefec2 · · Score: 1

    You can use static and dynamic analysis to gain knowledge on the structure of the program. Static analysis can be done with tools like Modisco (however, Modisco is not for C++ I guess). For the dynamic analysis, you need to add a monitoring feature to the code. This can be done with AspectC++. Instrument entry and exits of public methods (if it is OO code) or structural blocks detected by the static analysis.

    However, if the program is rather small, then you can do the analysis also by hand.

    1. Re:Architecture Recovery by H0p313ss · · Score: 1

      Try grabbing the demo version of RSA, (Rational Software Architect), it's great for turning Java and C++ code into UML models and has a neat way to explore models through diagrams.

      The trial version is free for 30 days.

      I am sure there are open source tools out there for this, but nothing so complete.

      --
      XML is a known as a key material required to create SMD: Software of Mass Destruction
  38. I usually do this by Anonymous Coward · · Score: 0

    Start a text file. what you want to do is this: basically putting code into English (or your primary language)
    function A
            calls function B
                    function B
                            cleans and persists the data
                            returns the clean version
            puts the clean data from b() into htm

    Reading AND writing code puts it into your head in two different places, which is strangely useful.

                         

  39. Since this is an OSS project ... by hedronist · · Score: 5, Interesting

    Since this is an OSS project, can you suggest any tools similar to Understand that don't cost $995?

    The only thing I could find was source navigator NG, but I have zero experience with it.

    1. Re:Since this is an OSS project ... by Bruce+Stephens · · Score: 2

      source navigator still works OK. doxygen can provide reasonable callgraphs (especially for C). DXR has improved dramatically recently---it's not just for Mozilla now. DXR requires the code to be compilable by clang, but doing whatever's necessary for that might be a useful exercise.

    2. Re:Since this is an OSS project ... by Anonymous Coward · · Score: 0

      You can also use valgrind --tool=callgrind, interactive mode. Yes, it is usually for optimization but using it would give you an idea what functions get called (and the call graph) for certain types of user actions. One run won't give you an overall picture but you can use it to help understand which classes are doing the heavy lifting.

    3. Re:Since this is an OSS project ... by Anonymous Coward · · Score: 0

      Since this is an OSS project, can you suggest any tools similar to Understand that don't cost $995?

      perl, sed...

    4. Re:Since this is an OSS project ... by enz · · Score: 1

      Doxygen doesn't cost anything and is very useful for exploring an unknown C++ code. You should configure it to include private functions and the source code browser. Then you can navigate through the source/reference with a simple web browser, and it will allow you to dive deeper into the details when necessary and easily backtrack after it.

  40. easy.... by Idimmu+Xul · · Score: 2

    echo "i am here";

    or print or console.log or printf or ...

    --
    The problem with slashdot is that most of its users were bullied and stuffed into lockers as kids!
  41. It's hopeless. by Anonymous Coward · · Score: 0

    Abandoned pile of C++ code ... well, if you've got a self-defeating personality disorder, you may try to make it work. Or even do whatever you want to be done.

    Normal response would be to forget it and start from a clean slate.

    Forgetting about C++ as well would do much towards keeping you sane.

  42. CCVisu by PLAST · · Score: 3, Informative

    You can use doxygen to create a dependency graph and visualize it using CCVisu.

    http://www.stack.nl/~dimitri/doxygen/
    http://ccvisu.sosy-lab.org/
    http://ccvisu.sosy-lab.org/manual/main.html#sec:input-dox

  43. Use an IDE with a debugger by namgge · · Score: 1

    Learn to use a debugger with a nice interface for exploring call stacks, data structures, threads, etc. Then, get the mystery code to do something simple. and put a breakpoint at the point its about to complete the task. (Try grepping for a string you see in the output.) Work up the call stack putting a breakpoint at the start of each procedure that is being called. Now repeat the task and look at each procedure as it is invoked.

    This will be a slow and painful process. Make sure you don't have anything better to do with your life before embarking on it.

    Good luck.

    Namgge

  44. you dont! by ddfire · · Score: 1

    i just start fixing problems or adding features and learn the code on the go... you dont need to read all the code from the start...

  45. Try and error by drolli · · Score: 1

    If a function is to arcane to be understood in 10 Minutes, start breaking it down into smaller *documented* functions while maintaining the same test results. Good chance that this will also help the project directly

    1. Re:Try and error by superwiz · · Score: 1

      If your code needs comments, it needs re-factoring. If the code is not self-documenting, it's worthless.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    2. Re:Try and error by drolli · · Score: 1

      Yea. Sure. Ideally speaking, yes. However i found one line about hte intent of creating a function not too much. But yes, breaking it down *is* refactoring (Could still be that you arrive at a function which is so fucked up its better to start from zero than to break it down)

    3. Re:Try and error by Anonymous Coward · · Score: 0

      If a function is too arcane to be understood in 10 Minutes

      FTFY

    4. Re:Try and error by Zero__Kelvin · · Score: 1

      Bullshit. If you think your code doesn't need comments it is because you have absolutely no idea how to develop software. Properly commenting code is an art form to be sure, and most people don't know how to do it, but when you encounter a project that is truly best in class software it will have comments. If your code doesn't have comments then your code sucks, no matter how great you think it is.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    5. Re:Try and error by superwiz · · Score: 1

      The names of your objects, classes and functions should be the comments. If they are not, then no amount of commenting will help to understand your code. No one gives a damn what you think your code should do (and what you claim it does in the comments). The only thing that a person unlucky enough to have to read YOUR code cares about is what it actually does. And if the symbols in your program are not properly named, you might as well be writing it in assembly. All the higher-level language crap is useless if the programmer thinks that his code will be understood from reading the comments. If a comment is absolutely necessary to understand a particular piece of the code, the code needs rewriting. If a comment is as much as remotely useful in understanding a particular piece of code, then the code needs re-writing.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    6. Re:Try and error by superwiz · · Score: 1

      I read a lot of oss code. If it gets to the point where I start looking at the comments, it's because the code itself is too buggy to fix on its own.

      --
      Any guest worker system is indistinguishable from indentured servitude.
    7. Re:Try and error by Zero__Kelvin · · Score: 1

      You don't have a clue, do you? Obviously well chosen variable names, function names, class names, etc. are important. You wouldn't want to create a class called car and add a comment that car is actually an implementation of bicycle, for example. You seem to think that ... scratch that ... I'm not convinced you think at all. Thanks for helping to ruin the software industry though!

      P.S. If you don't know how to comment code properly, please seek a new career; one for which you may actually be qualified.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    8. Re:Try and error by Zero__Kelvin · · Score: 1

      If the code is too buggy to fix then assuming that the comments will be accurate and clean is a pretty phenomenally stupid thing to do, now, isn't it. You seem to be of the opinion that, since you can't program*, and you have encountered lots of code done by others who cannot program, that nobody is capable of programming.

      * If you believe comments are useless then you are a phenomenally incompetent programmer. There is a reason that all those brilliant and highly skilled language developers universally include a way to comment code, and it isn't because their is no utility in it.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  46. Add Comments by Anonymous Coward · · Score: 0

    Add comments to the parts that aren't clear as you're reading through the code.

  47. Two steps by michaelmalak · · Score: 1

    Two steps:

    1. Make an act of thanksgiving that you're not dealing with code written by someone trained in FORTRAN, where all variable names are two characters long and all function names are six characters long. "You can write FORTRAN in any language." If you do happen to be dealing with FORTRANesque code, give up now.

    2. Become familiar with the idioms of every programming language, of every programming paradigm (structured, object-oriented, functional, event-driven, dataflow, etc.), and of every programmer educational background (high school/self-taught, CS degree, startup pressure cooker, etc.). If you don't have time to do that prior to starting on the current project, then let your attempt to reverse engineer the current project serve as a building block for the next time.

    1. Re:Two steps by HornWumpus · · Score: 1

      Calculated gotos in FORTRAN aren't trivial to reproduce in C/C++. Jumping to a pointer is the obvious analog. In FORTRAN you GOTO an int variable line number.

      --
      John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
    2. Re:Two steps by PhloppyPhallus · · Score: 1

      It's interesting that Fortran allows and can support GOTO from a variable line number; do you have a *good* example of why one might want to do this?

    3. Re:Two steps by HornWumpus · · Score: 1

      No.

      I've seen it used, but never for a good reason. It was used as a next iteration entry point for a utility simulation, which was a nightmare. They should have used a series of boolians to remember what constraints were violated this iteration. Instead they did things like (obviously not FORTRAN) If(fuelconstraints.Violated) NextInterEntry-=FuelShadowPriceRecalcOffset;

      Fucking applied math PhDs should not be allowed to write code, much less design databases.

      --
      John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
  48. Kno your languages by paysonwelch · · Score: 1

    The first thing is that you need to know the language you are working in. So if you are coming from a C background, it's similar but you should pick up a book on C++ (or whatever language you happen to be working in). Secondly it takes practice. Every day I am working with other people's code to fix problems. Once I find the problem area I have to sit and digest what's going on line by line, and usually add comments, where were not there to begin with. Lastly learning how to effectively read other people's code is one THE BEST skills you can have as a developer. Anyone can read their own code but to work as a team you need to be able to read other people's code and not get turned off by it. Small rant, most people who can't read other people's code seem to think that no one else knows what they are doing and that their code is sacred and they are the best coders ever, which is rarely the case and usually the opposite.

  49. Write Tests by GiganticLyingMouth · · Score: 1

    Write unit tests for the code and develop a regression test suite for it. This in itself can help you understand what's going on, but then also when you later start re-factoring or changing the code, you can be sure you're not breaking other parts of the code in subtle ways (or at least if you do break it, you'll know sooner than later). This will also help anyone else who might contribute to the project. Your mileage will vary depending on the size of the code base of course.

  50. make it move by superwiz · · Score: 4, Insightful

    It's just how your brain works. It's a lot easier to examine a piece of mechanical machinery when it's in motion. You notice more. Do the same with the code. Run it. Run components independently. Put plenty of log statements or if it's feasible, watch under a debugger. But don't try to look at stale code just sitting there. You'll notice more as it moves.

    --
    Any guest worker system is indistinguishable from indentured servitude.
  51. i usually start with the beginning by Anonymous Coward · · Score: 0

    just sayin..

  52. Is it under version control? by Anonymous Coward · · Score: 0

    If it's under version control I would go with the commit history to see what they were thinking as the project progressed.

  53. Maybe. by Max+Threshold · · Score: 2

    That's assuming the original programmers followed the MVC pattern. Very often they didn't. That's when you start reading tea leaves.

    1. Re:Maybe. by Anonymous Coward · · Score: 3, Funny

      That's when you start reading tea leaves.

      Well, at least that's better than reading JavaBeans...

    2. Re:Maybe. by Endophage · · Score: 4, Informative

      There are plenty of design patterns other than MVC and depending on the particular application, MVC may not even be applicable.

  54. King's route to mastering algebra ... by Kittenman · · Score: 2

    This calls to mind the story of the king who was in a class for learning algebra, and after realizing it was hard, he took the teacher aside and said 'I'm the king - show me the easier route'.

    There's isn't one. Sit down and read it. Then re-read it. Then think. Then read it again. Think again. Repeat.

    --
    "The greatest lesson in life is to know that even fools are right sometimes" - Winston Churchill
  55. This is a naive question. by dragonk · · Score: 1

    I would start by finding a chair. Seriously. The only way to read code is by reading code. The more code you read the more you realize the futility of any method other than -- sitting in a chair and reading the code.

    1. Re:This is a naive question. by Anonymous Coward · · Score: 0

      exactly.

      you can read it through linearly.

      or follow call chains until you know some of the lower functions well

      or just scan it through quickly and shop when something looks a little funny and dig into why its that way

      or just pick up a bug and focus on that, the next one wont take quite as long

      or most likely, do all of those things and over time you develop an understanding of the codebase

      pure magic

  56. Free ebook: Object-Oriented Reengineering Patterns by Anonymous Coward · · Score: 0

    This free book by Prof. Serge Demeyer gives a good introduction to software re-engineering.
    Serge Demeyer, Stéphane Ducasse and Oscar Nierstrasz, "Object-Oriented Reengineering Patterns," Morgan-Kaufman, 2003.

    The book is available as free .pdf download the author's page: http://win.ua.ac.be/~sdemey/
    http://www.iam.unibe.ch/~scg/OORP/OORP.pdf

  57. print statements by decora · · Score: 2

    print statements are the greatest debugging tool ever invented.

    it will work on any piece of code, any language, any type of situation. you can trace anything.

    1. Re:print statements by Anonymous Coward · · Score: 0

      it will work on any piece of code...

      I was once writing my own kernel and needed a function to print some text on the screen (partly for debugging the rest of the kernel). Trying to debug my print function using print statements would have been a very bad idea...

    2. Re:print statements by Anonymous Coward · · Score: 0

      Yeah, all you people who are using debuggers that can interrogate state, evaluate statements, change values in mid-process, analyze the number of active threads, control the program flow, and so on you are all missing out on the magic of "printf"! Seriously, this is like claiming walking is the best from of ground transport or that assembly is the best language. Use tools grandpa!

  58. UML by eggstasy · · Score: 1

    Well, if it's not documented, write the documentation. Skip the automated crap. You need to do this yourself in order to ensure that you understand it.
    That's why people take notes in classes, etc.
    I'd start with a class diagram, some sort of high-level flowchart, and grouping modules into layers.

    1. Re:UML by Zero__Kelvin · · Score: 1

      "Skip the automated crap"

      Absolutely! This is the best advice ever. And don't use any automated means of editing the source either. Open up that IC and use a scanning electron microscope and a laser to manually edit the bits. Avoid as many automated tools for making your job easier and for improving your effectiveness. Get rid of that chair, too. Real programmers stand when they program, damn it!

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  59. Be aware of object oriented code by Anonymous Coward · · Score: 0

    If you only have done C but no C++ or Java, there is one important thing you will have to learn: Interfaces between code. Codified as object hierachies and in headers. If you know C you will think: so my interfaces are just what the code does and what information it needs, so from reading the interfaces I know the code, and you could not err more. Due to the overhead of C++ and Java classes the interfaces are some entity of their own. They cannot be simply changed and usually will be there earlier than the code. So you will see interfaces that lack essential information that code will get elsewhere, interfaces passing information not needed. You will see "glue code": some code only written to make code behind one interface talk with code between another interface.You will find modules that interface with nothing else but glue code. You will find so many classes doing nothing (except connecting other classes that could not be rewritten to talk to each other) that you will end up needing some source code browser just to navigate the class hierachies. And no, this is no sign of bad C++ code, that is inherent to the language and if you dive into some bigger C++ or Java project, it will inevitably look like this.

  60. Build it and run it by Java+Pimp · · Score: 3, Insightful

    You will never fully understand the code just by reading it. My approach is to ignore all of it until something needs to be changed. When you need to change something, add a feature, etc... find where in the code the functionality is and tweak it a bit. See what happens. Tweak it some more. See what breaks. You will start to get a deep understanding of a focused section of the code and not have to worry (yet) about other unrelated areas. Start with small changes first. Larger changes may require a deeper understanding of the architecture and how pieces interact. This will come in time. After a few iterations of this and you will eventually become intimately familiar with all the pieces of the code.

    --
    Ascalante: Your bride is over 3,000 years old.
    Kull: She told me she was 19!
    1. Re:Build it and run it by Tablizer · · Score: 1

      You will never fully understand the code just by reading it...Tweak it some more. See what breaks.

      Aaah, the Toddler Method of learning. Just keep that copy in the sand-box, please.
       

    2. Re:Build it and run it by carnivore302 · · Score: 1

      best advise I've seen here.

      --
      Please login to access my lawn
    3. Re:Build it and run it by an_orphan · · Score: 1

      Maybe you're a good coder, but this would not be advice I'd give anyone except the most elite folks, who don't need it. I personally prefer to spend extra up-front time to learn a system and would advise anyone I work with to do the same. How do you know when things might interact when you don't know the premises of the system? You would have to rely on someone else to provide negative feedback. The approach seems a little flippant, but the details of how you implement it might make it work.

    4. Re:Build it and run it by Java+Pimp · · Score: 1
      I've never been able to get a full understanding of an unfamiliar project by simply reading the code (and mapping out relationships, though I have done that from time to time). The most insight (for me at least) comes from running the code, changing it to see how it breaks, and running it again. Nothing tells you more about a piece of code than seeing how it works normally, then seeing how your changes affect it.

      How do you know when things might interact when you don't know the premises of the system?

      By deliberately breaking it. When you make a change and something else breaks you know immediately that those components are coupled. No reading/mapping required. Once that coupling is identified you can focus your code reading to understanding how tightly or loosely coupled they really are.

      Rinse and repeat. It might seem simplistic or naive, however, once you've spent hours/days reading and mapping code, you're ultimately going to need to run it and modify it. In which case you are going to break it and learn something about component interactions that reading alone didn't tell you. My personal preference is to skip all that business up front and dive in. I'll still end up reading all the code. Just focused on certain areas of functionality one at a time.

      --
      Ascalante: Your bride is over 3,000 years old.
      Kull: She told me she was 19!
  61. Circle around for awhile. by shess · · Score: 3, Insightful

    Spend an afternoon or three skimming around the code pulling threads and following them. Jump around kind of randomly, if things start making sense in one module, go somewhere else for awhile. Take frequent breaks. Take notes about what you think things are doing, or perhaps ideas about how to improve the code - but don't start improving things now, you just want to figure out how much you're in for.

    After awhile doing that, you should have a few ideas about good accomplishable problems, now pick one and go deep for a limited time (hour, afternoon, week, depends on the scope of the code and your commitment to it). Again, keep notes, and then throw all your work away (or check it in somewhere - but don't focus on shipping, that detracts from learning). Again, go somewhere else in the code, fix something, take notes, throw it away. Alternate back and forth between research and application, trying not to bias towards one or the other (which can be a form of procrastination).

    Now throw away all your notes. They were written by someone who had no idea what was going on. By now you're pretty sure you know what's going on (you don't) and how to make things better (you have no idea), so circle around for another pass. Stop when you start finding that your notes seem to be recognizing actual immediately-actionable problems and solutions, rather than hypothesis and speculation. Or just stop because you're now so busy fixing things that you don't have time for exploration.

  62. Start by running Doxygen on the code by Anonymous Coward · · Score: 1

    Using Doxygen with dot (part of GraphViz) you can generate HTML with UML like diagrams that will help you visualize the design.

    Also, it you don't use an modern IDE, Doxygen can build the code with HTML links that you can use to jump to the method call or to see a variable definition.z

    BTW: I'm assuming you are looking at code in a language supported by Doxygen.

  63. Find the author by Antique+Geekmeister · · Score: 3, Insightful

    Find the person who wrote the code. Make sure that educating you or your colleagues is part of their paid responsibilities, and make sure that you respect their work when reviewing it: this helps them share the ir work and take it well if you need to revise things. My colleagues and I often bring new features or help stabilize old projects, and a working relationship with the original author is invaluable.

    And ff the author says "just read the code, I don't do documentation because documentation can lie", or if they say "don't bother checking the data for correctness, just don't make mistakes", be ready to throw out _everything_ they ever wrote. It may work at the moment, but it's likely to be as broken and unsustainable as their attitudes.

  64. hard to say by bloodhawk · · Score: 3, Funny

    I always find this greatly depends on the quality of the code, which varies greatly from well written and documented and just involves some boring reading and tracing through of execution paths too the absolutely appalling where you can sometimes only understand why the fuck they did something when you change the code and see how it breaks. The former I usually rely on a quiet room and lots of caffeine, the later requires swearing, loads of code changes to trace what is actually happening and cursing the original author, their relations and the goat you are sure they must have been molesting while writing the code.

  65. Depends... by countach · · Score: 1

    Depends on whether you understand what the code does. If you understand what the code does from the user perspective, then find the code which does the most critical and interesting bits and find out how it works. If you have little clue about what the code does then its trickier. I think just browse the code and be guided by your own curiousity. Examine any documentation that might exist, or any user interface that might be available to find clues to what is important.

    Look at what external libraries it uses. How it interfaces to the outside world, whether it be a user interface, network connections, files used, etc etc.

  66. you begin by Anonymous Coward · · Score: 0

    well you start reading... and then you continue reading... and then you end... did you understand what you read? Good? you didn't? retry! imbecile

  67. Call graphs by hand by Anonymous Coward · · Score: 0

    I start by making call graphs by hand. Forcing myself to slow down and write it down with a pencil on a piece of paper challenges me to answer "wait, what did I really read!?" questions. I usually don't have to continue this for very long before I start to identify the structure and then I can stop scribbling. But I need to see a mass of detail to begin up-levelling to structure because the structure I build up in my head has to be grounded in real code paths. If I find myself glassing over and just scanning the code, later, I force myself to make some more pencil and paper call graphs until I'm in touch with reality again.

  68. Use breakpoints by Anonymous Coward · · Score: 0

    Put a breakpoint in your main method and trace through. Find event handlers and breakpoint those as well.

  69. Don't bother. by anarcobra · · Score: 1

    There is really no point trying to memorize what all the code does.
    Just identify what functionality you want to add and start coding away.
    As you go you'll get familiar with the code base automatically.
    If there's some internals documentation (like there is for GCC and binutils) read that.

  70. gdb or equivalent by Anonymous Coward · · Score: 0

    fire up gdb or equivalent and walk through major flows while examining states. We had great success with it in embedded systems when absolutely no documentation exists.

  71. Bottom-up by jfisherwa · · Score: 1

    Load up the UI/interface, find a very specific piece of functionality, and then find the UI hooks in the code and work backwards from there. Repeat for another function that involves something completely different, i.e. access control/data/rendering/logic.

    Once you are comfortable with that process, you are ready to absorb from the top-down.

  72. or their equivalent by decora · · Score: 1

    spitting hex into a buffer, then reading that buffer later = primitive form of print statement

  73. first read rfc by Anonymous Coward · · Score: 0

    After read the rfc you can understand better the struct variables names and the algorithm. You cannot edit correctly a proxy source code if you don't read http || spdy || etc etc

  74. If you have to ask.... by Anonymous Coward · · Score: 0

    Reading other peoples code comes with experience. Tools may make it easier initially but I tend to find that jumping in is a great place to start. Get the code compiled and start making it your own. Another mentioned refactoring. I like this approach myself.

    Good luck.

  75. I like starting with data structures by Cyrano+de+Maniac · · Score: 1

    If possible, I usually like to start by getting an overall understanding of the various data structures used to implement the program. Sometimes this can be very helpful, particularly if the code was written by someone who designed the code rather than hacked it together. Ever since I took my first data structures class I have maintained that if you can understand the structures, the algorithms become almost self-evident. However, it's not always tremendously helpful, particularly if the implementor just accreted functionality into the program, or who views a big struct or two full of every little thing the program needs as good engineering. It also tends to break rather badly if the code has had a succession of short-to-medium term caretakers rather than one person maintaining it all along. That seems to be a fairly typical situation in commercial code.

    If following the data structures isn't helpful, then I tend to follow a top-down linear approach. That is I start with main(), get an overall sense for the flow of the program at that level, then start at the beginning again and work my way section by section or line by line through the code (or at least the parts of it that I think I care about). In other words at I first do a high-level read-through until I get the basic idea of what it's trying to do, and then fill in the details of how it does it. I repeat this at each level as I dig deeper into the code. It sort of ends up being a breadth-first summary scan followed by a depth-first extraction of details.

    Others have suggested commenting or reformatting code as you go along. My opinion is that if you do so be fully prepared to throw all that work away unless you know you're about to become the head maintainer of the code in question. Original authors don't seem to be able to see how bad their code is because it often isn't bad to them -- their code reflects their mental processes and expertise. It's just not worth the struggle, usually, to even reformat the code underneath them. There's lots and lots of terribly ugly code out there in the world, and almost every time I start looking at something new I call down curses and damnation on the authors. However in the end I just learn to live with it. Unless it's so terribly abhorrent as to actually be broken because of how it's written, I play the code chameleon and modify code following the same nature of ugly as the pre-existing code.

    --
    Cyrano de Maniac
  76. Learn from it, but that is all by Anonymous Coward · · Score: 0

    There is no point in "reviving" anything. It was abandoned for a reason.

    You can learn from it, but never modify it, its not your property.. even if its open sourced.. someones ego will be bruise and you will be at fault.

    Forking or branching is an advanced skill.

    Just remember you can't change the past, its over and done with.

  77. Run it through... by Anonymous Coward · · Score: 0

    Run the code through a debugger and study the flow of data. Learn by analyzing component relationships.

  78. the secret to reading code: by Anonymous Coward · · Score: 0

    Spend two or three hours reading code, a couple of times a week, for a few years.

  79. Make sure it compiles... Check the release version by Tim12s · · Score: 1

    Step 1. Make sure it compiles and you compile with the same options used in the current version deployed on production

    Step 2. Make sure you understand which version was deployed on the production system. Were any fixes applied to the source but not deployed.

    Step 3. Understand the scope of the component. The scope of a system is its user interface and its database. Input -> (Program) -> Output. The program can only do its job based on inputs (Screen, Config Files, Database, Integration Interfaces) and its output (Screen, Database, Integration Interfaces).

    Step 4. Understand the list of open issues/defects. Separate between architecture problems and functional problems. Understand potential "flaws" and where the difficult bits are.

    Step 5. Do a quick 1 hour skim over every module, file, and every function. Try and understand how it is logically organized. See if there are unit tests, any tests, how its built, how its layered, etc. These things you will not understand from the various functional analysis tools. (They only work if he's been a stickler for functional coding in conjunction with OO coding). Step 4 helped you prioritize your "attention". Figure out where the boilerplate code is (generated web services, UI interfaces, DAO, etc), which are the functional utilities classes, and which are the database/interface objects. The rest should be the problematic business logic/processing code.

    There are alot more but the above should get you onto the right track.

  80. Relevant advices by Yvanhoe · · Score: 1

    This was posted on reddit a few days ago (pdf warning yadi yada). I think that the "From Legacy Code to Clean Code" section may be relevant to you.

    --
    The Wise adapts himself to the world. The Fool adapts the world to himself. Therefore, all progress depends on the Fool.
  81. Requirements breakdown. by Anonymous Coward · · Score: 0

    First change nothing.
    Work top-down.
    Write down each requirements that the code implements.
    Group them.
    Understanding what the code is suppose to do, will help you when you get into details later.
    Do unit tests.
    One that tests each requirement.
    Follow the chain of the code for each action.
    Then the structure will be reveled.

  82. Goal-driven re-write by Peter+(Professor)+Fo · · Score: 1

    Start FIRST with what YOU want to do and WHY it is important to do it your way. Without this motivation you're wasting your time.

    If you don't know anything about the architecture of the system then sketch your own over a cup of coffee to find out what are likely to be the key components.

    Now you have a goal you can see what parts of the existing system are applicable, missing etc. Your basic knowledge of the inside cogs, wheels and not forgetting irrelevant bells and whistles will be a great help in focussing on elements, themes or modules. (For example the original might be full of cruft concerning what you regard as a dead-end but the original developers considered a bonus feature.) With the knowledge gained from the original system you may be able to look upon it as a prototype and build a much simpler system that isn't full of serial adaptations.

    If you have a 'porting' job then there are probably tools to at least highlight places to deal with.

  83. Debugging! by zmooc · · Score: 1

    Fire up your debugger and start stepping!

    --
    0x or or snor perron?!
  84. Whats the point? by angel'o'sphere · · Score: 1

    Whats the point in reading foreign code if you don't plan to work on it?

    If you want to work on it, isolate the area your code will touch the old code and work on that with a debugger.

    Reading huge C/C++ code bases is rather pointless ...

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  85. First rule by Anonymous Coward · · Score: 0

    Read code from top to bottom, left to right. Understanding it then becomes a trivial exercise that is left to the reader.

  86. Create a simplified outline. by Anonymous Coward · · Score: 0

    When I am trying to figure out what code is doing I create an outline of it. Most of the time I just do it with pen and paper, other times with a simple text editor. Start with the main function and map out what the code is doing at a high overview level. If you come across something that your not sure about you can mark it with a question mark and come back to it later. The point is to translate the code into a simpler form that you can understand and reference. I like to use the numbered outline because it is easy to group logic and create references to other sections. It's kind of like reverse engineering an use case. It is better to focus on what the code is doing / trying to do, instead of the how is it doing it.

  87. Go back to the beginning - flow chart by Gothmolly · · Score: 1

    Remember writing BASIC in 3rd and 4th grade, where you had to flowchart everything out first? Go do that.

    --
    I want to delete my account but Slashdot doesn't allow it.
  88. Pseudo code it. by lscoughlin · · Score: 1

    Pseudo code it.

    Read the major blocks of the application in what ever editor makes you happy, with a text editor next to it ( preferably one that does arbitrary text folding ) and just psuedo code the hell out of it. The more of this you do, the more you'll be able to look back at your own pseudocode for a definition of some obscure thing, and the more a pattern will appear as you notice yourself typing the same things over and over again.

    Also works as sl/hack documentation when you're done.

    --
    Old truckers never die, they just get a new peterbilt
  89. Refactor by Anonymous Coward · · Score: 0

    Refactor into self-documenting code. Developers who think they are being clever by being cryptic are morons and assholes. "Oh, you don't know what 'incept' means?"

  90. Close. by azav · · Score: 1

    It's actually "How to Start Reading Others' Code?"

    You put the apostrophe after the s, otherwise, it's only one other that the code belongs to, which is just strange.

    --
    - Zav - Imagine a Beowulf cluster of insensitive clods...
  91. Start with the Requirements by ZombieBraintrust · · Score: 1

    Knowing the Requirments gives you the ground work for understanding what the code is doing.

    Try to get a hold of the requirements document, specifications, and detail design. Once you have the requirments you should have pretty good idea of what should be in the code. Header comments often do not repeat the contents of the specs.

  92. gprof (and anything under the sun.) by luis_a_espinal · · Score: 1

    Since this is an OSS project, can you suggest any tools similar to Understand that don't cost $995?

    Eclipse CDT has a very powerful index (when it works) with which to search who calls what, or who depends/inherits from who.

    It is still a crapshot when the code is atrocious (or complex/large enough that even good coding efforts are not enough.) Slowly but surely identify what look like important functions. Screenshot the call/type graphs in Eclipse and put them on a document.

    Sometimes I (grep|awk|find|sed|tr)+ the crap out of source files looking for types and functions/methods, massaging them into submission until they can look like a CSV file. Then I load them into Excel or Access.

    Sometimes, not always, but sometimes you can glimpse a lot of knowledge when you look at code structures (functions and types) in a tabular format (in particular when dealing with CORBA IDL elements and their C/C++ implementations for instance.) Another advantage is that sometimes (again, sometimes) you can take those elements, and massage them into a DOT file from where to generate a graph of sorts.

    Similarly, I've generated DOT-based graphs of file dependencies, object dependencies, etc. You can run nm or objdump to generate a list of "things" included in the obj files, and generate a sort of component dependency graph.

    But the cheapest way to go about it, if you are using the GNU compiler suite, is to use gprof. If you have a set of test cases that can exercise a substantial portion of your code, you might be able to get a partial call graph. The call graph might be dependent on the test scenario, but it is something that can get you going in the right direction.

    Sometimes a code coverage tool like lcov, running in tandem with gprof, can help as well. It might give you an indication of dead code (if your tests are comprehensive enough) or code that still needs inspection (if your tests are not comprehensive.)

    It is all manual and thus prone to error. That is the price of not using a good code navigation tool (which unfortunately the ones worth a spit are commercial-based.)

    But with some good elbow grease, spit and diligence, you can go a long way by clobbering something together using existing tools (gprof, lcov, nm, objdump, grep, awk, sed, tr, perl, excel, etc.)

    The only thing I could find was source navigator NG, but I have zero experience with it.

    1. Re:gprof (and anything under the sun.) by aled · · Score: 1

      +1 to parent.

      I used ecipse, doxygen, nm, dot to understand code. Understand, control, refactor, repeat is the main method. The details vary from project to project.
      If something is too complex to understand try to isolate it. Maybe you will need to replace it later. Modular code is your friend.
      Very important: make small changes and commit them often so you can backtrack if you make a misstep. Use your favorite version control tool. I used hg+svn but use whatever you like best. Prefer to commit atomic changes, for example single changes in functionality, so you can undo one thing without breaking another.
      I don't use source navigator since more than 10 years but I don't think you'll need it with Eclipse+doxygen.
      FIrst add documentation and small changes. I use to add doxygen comments and convert old K&R code to ansi c o c++ first to gain type checking without changing any semantic.

      --

      "I think this line is mostly filler"
  93. Comment the code by pturley · · Score: 1

    I find that the best way to read and understand someone else's code is to comment it.

  94. a systematic approach by an_orphan · · Score: 1

    I've always been a little ADD and impatient with having to do things systematically, unfortunately I found this is the only approach that works for me. If I don't do this, I end up staring at the screen for long periods of time and not getting anywhere. So, I wrote up a worksheet to help myself in these situations, here are the steps I identified as helpful to deal with massive levels of complexity in unfamiliar code:

    1. Establish a clear goal and sub-goals.
    2. Use the goals to determine the scope of your reading.
    3. Allocate quite a bit of time in large chunks.
    4. Identify key layers of abstraction.
    5. Enumerate classes (functions, namespaces) of interest.
    6. Systematically, read through each class superficially.
    7. Pick 8 classes to focus on.
    8. Do a deep dive.
    9. List/sketch inputs and outputs in terms of function names, types referenced.
    10. Look at relevant tests for usage as needed.
    11. Check off each class once looked through.
    12. Measure the complexity of a component by how many checks are required for full understanding.
    13. Iterate until goals achieved.

  95. Format by visionbeyond · · Score: 1

    There is a good side to reading another programmers code, which is in seeing other methods and approaches to solutions. For any given task, there are many ways in which it can effectively be programmed for. Grant 90% of solutions done are usually inefficient, unstable, bloated, or just outright wrong, but out of that other 10% you can find some interesting things, even if it isn't your preference or end choice. The main thing is to be open-minded. A programmer that believes their way is the only good way (which is most programmers) is a programmer that expands their knowledge and capabilities very slowly.

    As for being able to read it, I would strongly suggest customizing a plug-in to your favorite IDE and have it reformat the code. Every programmer codes with their own style, and while you wish everyone used correct indenting and such, the reality is far from that. If you want to save yourself a lot of headache and time, just auto-reformat each page as you go through it. This not only will make it so you can save the source code with good formatting, but will also make it much easier for you to read and review. At least that's my two bits, which in today's economy counts for next to nothing. 8-) I've been in your position too many times, and any way you look at it, you've got a bunch of scanning through files ahead of you. Good luck.

  96. There are no tricks; just perseverance!! by Anonymous Coward · · Score: 0

    There's no trick. Basically you slog through it. You figure out the structure by spending time studying it. QED.

    Basically it's up to YOU do decide the effort is worth it.

  97. Class Diagrams / Doxygen by Anonymous Coward · · Score: 0

    I generally try to get some class diagrams and such using doxygen or some such tool. This at least gives you a nice sorted and cross referenced index into the code with class herarchy diagrams.

  98. need to read my old code by Anonymous Coward · · Score: 0

    um..I forgot how to read Visual Basic. I even forgot how to type code in VB 6. and basic is supposed to be easy to learn. lol

    i remember C though. weird
    I need to find my old book on C too

    #include /* main function */
    int main()
    {
            printf( "Hello World!\n" );
            getchar();
            return 0;
    }

    1. Re:need to read my old code by Anonymous Coward · · Score: 0

      slashdot didn't post stdio.h. opps. guess the forum doesn't like greater and less than signs.

      #include "stdio.h"

  99. Re: refactor, discard, repeat by Anonymous Coward · · Score: 0

    the others who work on the project.

    Which others? There aren't any. Otherwise he wouldn't be reviving it.

  100. patience and sleep by Anonymous Coward · · Score: 0

    I'm doing this right now, going through JavaScript/Dojo code that was written by various people that are no longer with the company. It's a lot to absorb for me, because although I've worked with several JavaScript frameworks, Dojo is a little different than all of them. My strategy is to use lots of console.logs and get an understanding of the flow. I've done this pretty much on every job I've ever had - reverse engineered code. It's like climbing a mountain - it's daunting at first, but the higher you climb, the more you can see around you. You can look at this code all day, and at some point you may be like, "WTF is going on?", but your unconscious mind will work on it while you sleep, and the next day you'll wake up knowing a little bit more than you did the day before.

    Just keep at it. Yes, marijuana helps in the beginning to focus on the gibberish, but I don't seem to need it anymore.

  101. Strip out the comments... by rthille · · Score: 1

    You should use a script to strip out the comments. If any are actually present, they are almost certainly misleading.

    --
    Awesome furniture, accessories and cabinetry in Santa Rosa, CA: http://humanity-home.com/
    1. Re:Strip out the comments... by Anonymous Coward · · Score: 0

      You should use a script to strip out the comments. If any are actually present, they are almost certainly misleading.

      Only if the author is a complete selfish bastard idiot who doesn't give a shit about the code.

      Good programmers write good, useful documentation and keep it up to date. Only bad programmers allow comments to languish.

  102. Reverse engineering design from code by Anonymous Coward · · Score: 0

    Try using a reverse engineering tool like Understand for C+ -- this tool gives you many different views of the code like call graphs, data dictionaries, class diagrams, cross references, ... Another approach would be to generate class diagrams with one of the OO design tools like IBM/Rational Rose or Rhapsody, or even Microsoft Visio -- these tools will reverse engineer desing (class diagrams) directly from source code.

  103. Reformat the code... by Anonymous Coward · · Score: 0

    ... by hand.

    Everyone has their own coding style and assuming the original code is not in a style that you "like", recoding it all by hand is a great way to learn the code!

    Documentation is often out-dated and simply incorrect! :(

    By reformatting the code, you "touch" and "read" almost every line of code ... it takes time, obviously, but you'll learn a lot as you go!

  104. Search it by cwsumner · · Score: 1

    Get a good global search utility. Search for every use of the symbol names that you are working with, to see what their scope is and how they are used. You can see how the other code uses them, steal snippets of working code you need, and tell what might "break" your use of them. If you have seen every use of a symbol, in the whole code set, then you can feel more confident that what you are doing will not break things.

    Don't try to learn everything at once, your brain can't hold it all right away. Study about the modules and symbols that you must work on. Start with finding out how much you actually -do- have to work on. Then widen your scope as you find more "connections" to other things.

    Everything is more complicated than you think, and more complicated than your boss thinks. Be cautious, go carefully, and don't go "running full speed off a cliff". This will actually end up being much faster to a working version.

    Frustration is normal, when learning something new. It does not necessarily indicate that the thing you are studying is screwed up (although it might be). Work through the frustration before making changes. (Except, it might be good to make temporary "test" changes to help in the learning.) It is painful, but you will learn and grow from it.

    Strongly resist the temptation to re-write stuff that is new to you, no matter how bad it looks. There will usually be good reasons that it is that way, and you will make a disaster. Make good backups of everything before each change and at least every day. There will be places where you must throw away what you have done and go back.

    On the other hand, don't be afraid to make global changes to the code set if it is really needed. Just back up a working copy that you can go back to, and be careful.

    Do things in phases, even if the "customer" only wants a final version. Make a reasonable set of changes than get it working and debugged. Then do it again for the next changes. Debugging as you go is actually much faster in the long run. Learn to use a Debugger, it is like turning on a light in a dark room.

    Find quiet time for several hours to work on it, so that you can get into a "state of flow" mentally. This is much more effective than normal work with interruptions.

    HTH.