Slashdot Mirror


Learning and Maintaining a Large Inherited Codebase?

An anonymous reader writes "A couple of times in my career, I've inherited a fairly large (30-40 thousand lines) collection of code. The original authors knew it because they wrote it; I didn't, and I don't. I spend a huge amount of time finding the right place to make a change, far more than I do changing anything. How would you learn such a big hunk of code? And how discouraged should I be that I can't seem to 'get' this code as well as the original developers?"

78 of 532 comments (clear)

  1. Time by wmbetts · · Score: 5, Interesting

    If you don't have access to the original developers and they didn't document it you're going to just have to spend a lot of time reading the code. =\

    --
    "Ubuntu" -- an African word, meaning "Slackware is too hard for me". - stolen from Dan C alt.os.linux.slackware
    1. Re:Time by Anonymous Coward · · Score: 5, Insightful

      Everyone, including me, always wants to go for the clean rewrite. But in my experience it almost never turns out for the best. There's a reason for all that messy code. Much of it was bug fixes that real-world users needed. Other complexities were needed in the first place to make the user experience simple (natural, giving it that "hey, it's just works like I expected" feeling).

      The reason you don't understand the code is that you weren't part of the original design discussions, in which weeks or months were spent learning, debating, arguing, etc., about many different design decisions at many different levels of abstraction. You don't know why the trade-offs were made. You just see the finished product.

      Rewriting the code won't give you insight into any of this. Learning the code the hard way, fixing bugs, rewriting *small* pieces and seeing what breaks the regression tests, etc. will eventually help you to understand it.

      There is no point in rewriting it before you fully understand it. Attempting that can kill a product. Conversely, by the time you fully understand it, there won't be any need to rewrite it, because you'll own the code.

    2. Re:Time by ztransform · · Score: 2, Insightful

      There is no point in rewriting it before you fully understand it.

      I fully support this statement.

      I recently worked with a guy new to contracting. He came onboard to a project that had a lot of problems. He argued for re-writing it thinking he could do it quickly and simply; I didn't dispute that the system could use significant changes, and I asked him to read through and understand the existing code.

      He never did.

      Consequently I suggested to senior managers that he should be let go. Reading other people's code, particularly undocumented code, is painful - even for experienced coders. But it is necessary and failure to do so before recommending changes is unprofessional, dangerous, and lazy.

  2. A good starting point by RCL · · Score: 3, Interesting

    Try to single-step it in debugger from the beginning up to main loop.

    1. Re:A good starting point by robot256 · · Score: 3, Insightful

      I didn't get this one until I switched to my alter ego, the assembler programmer.

    2. Re:A good starting point by Anonymous Coward · · Score: 2, Interesting

      I think this is the fastest way to find the right place to make a change. Stepping the application through a debugger is probably faster than reading through the code to learn how things are done.

  3. don't feel bad at all by iggymanz · · Score: 5, Insightful

    So you have been handed the steamin' pile o' code, it is great that you are very cautious and deliberate when modifying it. Make a set of regression tests, that is, make a set of test data and procedures and expected results to ensure original functionality that is still desirable is still working and no other errors introduced. It is hard, much more tedious than just creating new code with few constraints.

    1. Re:don't feel bad at all by kaiser423 · · Score: 5, Insightful

      Definitely what parent said. Also:

      I have inherited huge code bases. I actually kind of like it. Lots of people whom I thought were idiots, and cursed their code, I later found out that they were quite smart. Others, I found that they just thought about problems vastly different than I, and learning how they tackled problems gave me many more tools in my personal arsenal.

      That said, find a big wall or something. Use a debugger or code analysis tool to find the main execution paths (what calls what and when, etc). Diagram that up on the wall really large. Then use the tools to determine when and why certain auxiliary functions get called. Diagram that up, and you'll start getting a spider on your wall. Go from there using your new understanding to re-arrange the program flow not in terms that make sense to you, but rather seem to be how they are programmed (functional, objective, some pattern). Rinse and repeat until you know pretty much what the code is trying to accomplish in 90+% of the situations, and it's general plan for attack.

      With that diagram, dive in! There's tons of little details in every function that look useless but are usually bug fixes. Use a scalpel, not a hatchet.

      I was deployed remotely with no way for the main programmer to get at me. We had prepared 9 months to collect 4 minutes of data, and the test wouldn't wait for us. I found an odd bug hidden somewhere in ~22k lines of code. I did this over a weekend, and found about 4-5 nasty bugs that were combining to produce what I was seeing, and fixed them. I did this with zero input or help, over a weekend in code I had never seen spread around about 60 files. I spent the first half day just diving in and trying things, and nearly shot myself. That's when I went high-level and dug in from there.

      When that was done, I the took over code maintenance and updates on that project. The other guy had wrote it 100% himself, but because after that exercise I knew the code better him. Sometimes being new is good; you don't have all that cruft of implementations that didn't work, etc, but still linger in the original programmer's head.

  4. Use Doxygen by gbrandt · · Score: 5, Insightful

    Doxygen is your friend. run it over the source code and keep the HTML handy for searches and cross references.

    1. Re:Use Doxygen by eggy78 · · Score: 2, Informative

      I have found that equally useful to Doxygen's standard documentation are the caller/callee graphs (and the source browser as well!). These features are invaluable but they don't get used when you generate documentation with a more-or-less default config.

    2. Re:Use Doxygen by erictheturtle · · Score: 2, Informative

      I feel the same way as OP when trying to make sense of some open source library I'm interested in extending. Doxygen has been a big help. In the future I might also try Source-Navigator.

  5. It depends on the language by $RANDOMLUSER · · Score: 5, Funny

    If it's Perl or VB, you might want to consider self-immolation as a first step.

    --
    No folly is more costly than the folly of intolerant idealism. - Winston Churchill
    1. Re:It depends on the language by martin-boundary · · Score: 5, Informative

      No, he meant that as an actual offering to the Perl God, Quetzal$@[&shift]L. It's a bloodthirsty god, who never sends the Divine Debugger without at least two pints of the red stuff. I would have immolated a coworker, but the parent poster seems to have been alone in the room :-/

    2. Re:It depends on the language by chill · · Score: 5, Funny

      No, he meant that as an actual offering to the Perl God, Quetzal$@[&shift]L. It's a bloodthirsty god, who never sends the Divine Debugger without at least two pints of the red stuff. I would have immolated a coworker, but the parent poster seems to have been alone in the room :-/

      The fact the above comment is +5 Informative and not +5 Funny makes me very glad I stopped programming in Perl when I did.

      --
      Learning HOW to think is more important than learning WHAT to think.
    3. Re:It depends on the language by BerntB · · Score: 2, Informative

      Funny you should say that.,,

      I quite like this reference from the Perl world about understanding large systems: http://www.perlmonks.org/?node_id=788328

      --
      Karma: Excellent (My Karma? I wish...:-( )
  6. Not lots of code by www.sorehands.com · · Score: 5, Insightful

    First of all, 30-40,000 lines of code is not lots of code. Try, 250,000 of code.

    To start, use a good programming editor/environment (Xcode, Vslick, Visual Studio, etc.) that gives you the ability to easily go to definition or references to variables, functions, structs and such. Run some sort of profiler or flowchart type program on it to get a high level view of the code and how it fits together. If you can get the person(s) who worked on it before you to give you an idea of it fits together.

    1. Re:Not lots of code by Coryoth · · Score: 4, Insightful

      First of all, 30-40,000 lines of code is not lots of code. Try, 250,000 of code.

      To start, use a good programming editor/environment (Xcode, Vslick, Visual Studio, etc.) that gives you the ability to easily go to definition or references to variables, functions, structs and such.

      30-40,000 lines can be lots of code, it really depends on how maintainably it is written. I've had to pick up codebases that were somewhat smaller but were still diabolical ... good programming environments don't buy you much when the code consists of functions that are many thousands of lines long making little or no use of typedefs or structs (arrays and lots of variables should be enough right?) and convenient variable names like 'e', 'ee', and 'eee'. Even small codebases can become practically incomprehensible if written with little thought given to long term maintenance.

    2. Re:Not lots of code by snowgirl · · Score: 2, Funny

      so like... perl?

      More percisely 30-40,000 lines of code is 29,999-39,999 times more lines than one needs to write shitty code...

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    3. Re:Not lots of code by greg1104 · · Score: 2, Insightful

      Sure, if you only have a trivial 250K lines of code, I guess you can use crappy tools like Xcode and Visual Studio to maintain your project. The rest of us have to use grown-up tools that look like this:

      src$ find . -print | xargs wc | tail -n 1
        1950894 7085675 56777966

      There's only one way to learn your way around a new codebase, and the worst thing you can do is use a tool that aims to help with the job. Want to know how stuff flows through the program? Find where the program starts and draw the diagram yourself as you map it out. What I do is find something that I think I need to change, and a clear goal for what change I want to make to it, then map out exactly how the program reaches that point. You need to have a targeted goal to make progress with a stack of new code; just trying to read the whole thing or stare at diagrams of it won't teach you anything. Put the sucker into version control, generate regression tests of its output, figure out how to build after making a trivial change, and then try making a small non-trivial one. That's the only real way to learn how a program really works that internalizes enough of it into your brain that you can move upward to bigger maintenance tasks.

      And, for the record, I would like to tell everyone who suggested using a debugger to trace through the code instead of figuring it out by inspection and experiments that you are all a bunch of pussies. Good luck with that when the code breaks in production and you've got nothing but log files from the period loading up to the crash to work with. If I can get a debugger to attach to a broken program when the problem exists, it is by definition a trivial problem to solve; if I can even get a backtrace of where the thing is stuck at when it goes bad that's automatically an easy one. The only way to learn what you should be logging and defensively doing is by only relying on logs, assertions, and testing all the time--never a debugger. Because when things go really wrong, you won't have your debugger to save your ass--but if you built in good testing and logging capabilities, they'll be there.

  7. Hunt down the original developer by Anonymous Coward · · Score: 5, Funny

    (And then shoot him.)

    1. Re:Hunt down the original developer by ottothecow · · Score: 5, Funny

      shouldn't that be more like shoot(huntdown(first(developers)))?

      --
      Bottles.
  8. Not at all. by hemorex · · Score: 5, Insightful

    I find that if the other programmer wrote it in such a way where it's too complex for me to follow, I'm not the one who's a moron.

    1. Re:Not at all. by tsm_sf · · Score: 5, Insightful

      Man, always when I run out of mod points.

      Nothing like being handed a steaming plate of spaghetti and hearing about how much of a "genius" its creator was.

      --
      Literalism isn't a form of humor, it's you being irritating.
    2. Re:Not at all. by CorporateSuit · · Score: 3, Insightful

      Yes, but there's also when you hire the new guy, fresh from college, and he sits down at his work station. After a few days of getting absolutely no work done, he comes to you and tells you he wants to rewrite the core 50K lines of tested, trusted company code because he thinks it's not written "by the book". To which, the only sane reply is "You touch that code, and I will set you on fire."

      --
      I am the richest astronaut ever to win the superbowl.
    3. Re:Not at all. by Chris+Newton · · Score: 2, Insightful

      Nothing like being handed a steaming plate of spaghetti and hearing about how much of a "genius" its creator was.

      I always thought clever code was code that everyone could understand, not code that no-one could understand.

      It’s like Blaise Pascal’s apology for writing a long letter because he didn’t have the time to make it shorter: it’s often easier to produce some grandiose design that treats anything awkward as a special case than it is to identify a simpler, more consistent underlying concept and then write simpler code to model that.

    4. Re:Not at all. by ajlisows · · Score: 2, Insightful

      Then again, the creator MAY have been a genius. Perhaps he was told "Put this enormous program together in one month or the company is screwed." In cases like that, poorly thought out algorithms, bloated classes, using variables with names like "x", "y", "z" with no comments, nothing really works except for the absolute bare minimum required and other coding no-nos probably do not seem that important. Given appropriate time and resources, perhaps he could have written the greatest code EVAR! Given a very limited time frame and managing to save the company would probably qualify them as a genius.

    5. Re:Not at all. by Tablizer · · Score: 2, Interesting

      I find that if the other programmer wrote it in such a way where it's too complex for me to follow, I'm not the one who's a moron.

      But YOU get the blame, which is the problem. This kind of thing happened to me recently when I inherited a big pile of MS-Access code with variables like A34 and 300 objects (tables, reports, queries, etc.). I went from an "excellent" rating to a "C" rating on my evaluation because they wanted quick turnaround. I felt like the victim of a hit-and-run. I'm not the one who did the crime, yet I'm the one with the black eye and a missing wallet. The Pasta Mugger did a number on me.

      At least with text source code you can find or write variable, function, and command indexers/profilers to help one see the structure, find definitions, and browse relationships. Not so easy to do that with MS-Access with all it's proprietary binary crap. I found a way to extract some of the info, but it looks different from how you'd see it inside MS-Access so it's hard to relate to. Gotta love MS.

  9. Visualisation by gilleain · · Score: 5, Informative

    Anything ranging from just sketching out some informal package diagrams on some paper (I quite like using an A3 sketchpad) to something more like Code City which can work with code in smalltalk, java, and c++. There are UML diagram makers, of course, but automated diagrams like that probably need to be edited.

    In fact, it is not the finished diagram that helps so much as the drawing of it, which is why paper and pencil is so good. Or a vector graphics package.

  10. Trace sessions and time by oldhack · · Score: 4, Insightful

    I'll echo some earlier comments.

    Set up an execution environment with debugger, and run several typical scenarios and trace them with debugger. Get the feel of the big-picture execution scenarios/paths.

    It will take time for your brains to get comfortable with it, though. And the details, when you look into them, will throw odd stuff at you. But that's the nature of our work.

    --
    Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
  11. Tried and True by cosm · · Score: 2, Insightful

    For culinary folks...
    The time and money you spend tracing and inserting noodles in the spaghetti will end up being larger than the time it takes to cook a new batch (no pun intended).

    For auto folks...
    The time and money you spend bondo-ing, welding, rewiring, duct-taping, and C'n'Cing parts for the car will end up being larger than the time it takes to design and build a new car. (Although restoring an old/vintage car for the sake of nostalgia is a much more pleasing experience than buying a new one).

    Gain an understanding of the purpose of each pivotal region. Know what your desired result should be, then begin the rewriting endeavor.

    --
    'We are trying to prove ourselves wrong as quickly as possible, because only in that way can we find progress.' RPF
    1. Re:Tried and True by Piquan · · Score: 3, Insightful

      These projects invariably have lots of tiny gotchas that you're going to steamroll in your effort to rewrite it. See Joel on Software on this.

  12. Some things I do to figure out code... by CFBMoo1 · · Score: 2, Interesting

    PL/SQL or cobol or whatever they throw at me I poke, prod, and play with it in a test environment. Someone up above mentioned pencil and paper to draw out how everything relates and that is a very good practice I've found to just get to know things. It's not instant but it helps more then you initially think. Also I use Open Office Draw to map out things as well. :P

    --
    ~~ Behold the flying cow with a rail gun! ~~
  13. Re:30 to 40 thousand lines isn't large by any meas by etymxris · · Score: 3, Interesting

    I inherited a code base of 1.5 million lines of code at the last job I was at. Thankfully I wasn't the only one responsible for it. My advice to the original poster is to add lots of logging information. Log statements should document what the code is doing at any point in time and tell you where it is doing it. If it's java you can get the stack trace from anywhere--this is very handy for logging.

  14. Large? by VirginMary · · Score: 2, Insightful

    Ha, ha! Just 4 months ago I joined a project with a code base of about 500k lines. I would call that (the 500k lines one) intermediate in size. There are code bases with many millions of lines. I now feel pretty comfortable finding things in it. And I mostly use find and grep.

    --
    When 1person suffers from a delusion,it is called insanity.When many people suffer from a delusion,it is called religion
    1. Re:Large? by snowgirl · · Score: 4, Insightful

      Ha, ha! Just 4 months ago I joined a project with a code base of about 500k lines. I would call that (the 500k lines one) intermediate in size. There are code bases with many millions of lines. I now feel pretty comfortable finding things in it. And I mostly use find and grep.

      At my job at Microsoft, we were in the support end of the core os group. That meant that core os wrote WinXP, Server 2003, Vista, etc, and then it got completely moved over to us to maintain.

      Unfortunately, Windows doesn't really have find and grep, but it does have "dir /s /b [pattern]" and "findstr /sipc:"[pattern]"" Once I learned those, that's a lot of what I used to find the code that I needed to fix.

      All I can say is that it takes time, and effort to become familiar... and you're just stuck with it.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    2. Re:Large? by snowgirl · · Score: 5, Interesting

      Are you Microsofties really so stupid and ignorant that you're not aware of the ports of GNU utilities to Windows or Cygwin or even your own company's Interix and Services for UNIX products?

      No, but to explain this, I need to give you some background.

      When I joined Microsoft, I hadn't used any version of Windows at all for any reason other than playing games. After joining Microsoft, I never used Windows at home for any purpose other than logging into the VPN to work from home... and since I did not even have an x86 machine, this required using Virtual PC on my Mac OSX box.

      Now, I know of all of these tools, and I even could install GVim on the machine as well. However, I was working in a Build Group. This required me to occasionally log into 100 different machines at once in order to start the build process for WinXP/Server 2003. Most of these machines require no more input than logging in and starting up a single app... thus no reason to install special software on them.

      Then, something would break, and I would have to read logs, and/or code on the actual box that had the exact problem. Spending an hour installing apps to do my job would be an unacceptable use of my time, and delay the build unnecessarily.

      I learned to use the tools that were available with the environment that I was in. Thus, I did almost all of my programming at Microsoft in notepad.exe, and I'm not kidding you.

      Were I in a different group? The results could have been different... but having 100 different machines, most of which I didn't have admin rights to, meant that even just installing Notepad++ or something like that would have been a waste of time.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    3. Re:Large? by snowgirl · · Score: 5, Interesting

      What the hell? Are you serious?

      So Microsoft themselves hired you to work on Windows, although you were a Mac user and had absolutely no real experience with Windows?

      Not only that, but you had to manually log in to hundreds of systems just to run a script? They didn't push for this to be automated, and you tossed back on the street where you belong? What the hell?

      Don't get me wrong, I don't doubt that your story is true. It's the sort of shit that we should expect from any large company, especially Microsoft. Please tell me you're an H1B, though. At least then it'd make some sense why they'd hire you. H1Bs typically aren't worth more than a batch file.

      Yeah, it took me about a month before I understood that my entire group would be replaced by a few scripts in the Open Source world.

      The primary problem was that because the source code was not a "product", the build code was so full of holes and edge-cases and hacks, that it broke almost constantly, and required someone to babysit it for the whole 14-some hours that it takes to compile.

      Actually, in my orientation class, we went over patents, copyright, and trademark, and I knew it all, and the teacher asked me how I knew so much, and I told her that I owned a registered copyright on some GPL code, and she was like, "and your managers hired you knowing that?" And I was like, know about it? It's the only reason I got hired by Microsoft... be damn sure I didn't submit a resumé.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    4. Re:Large? by snowgirl · · Score: 3, Informative

      Most of these machines require no more input than logging in and starting up a single app... thus no reason to install special software on them.

      Then, something would break, and I would have to read logs, and/or code on the actual box that had the exact problem. Spending an hour installing apps to do my job would be an unacceptable use of my time, and delay the build unnecessarily.

      "Then something would break" contradicts the earlier statement "no more input than logging in"

      The fact that something is likely to break, and you will need to troubleshoot it, should be reason enough in itself to install some (small) convenient, unobtrusive troubleshooting tools, as standard practice, and as part of the standard initial installs for those servers, to make troubleshooting faster and not require software installations or elaborate practices when things do break.

      You missed a part before the quote that you pulled out. "Most of the machines required no more input".

      My statements remains consistent and not contradictory when only 2 machines typically need direct interfacing.

      And small convenient, unobtrusive troubleshooting tools WERE installed as standard practice on the machines... I already said that there was dir /s /b, and findstr... do I have to have "find" and "grep" when I had tools with the same functionality?

      When I started off, there was a big learning curve because of the new tools, but by the time I left, it was as second nature to me as was find and grep when I joined.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    5. Re:Large? by benjamindees · · Score: 3, Informative

      At my job at Microsoft, we were in the support end of the core os group.

      Windows doesn't really have find and grep, but it does have "dir /s /b [pattern]" and "findstr /sipc:"[pattern]""

      When I joined Microsoft, I hadn't used any version of Windows at all for any reason other than playing games.

      I did almost all of my programming at Microsoft in notepad.exe

      it took me about a month before I understood that my entire group would be replaced by a few scripts in the Open Source world.

      Dear lord, this is the most hilarious thing ever posted to /.

      --
      "I assumed blithely that there were no elves out there in the darkness"
    6. Re:Large? by StuartHankins · · Score: 2, Informative

      Sysinternals has a great tool you can use to automate installs / run software on multiple machines at once, called psexec. Depends on whether you need to run them interactively, in which case you'd have to also script a login. In the future maybe that's a workable solution for you, especially if you have to use large numbers of computers running Windows. Without grep, head, tail, less, etc I'd feel a bit frustrated. Of course if you're discouraged from installing something that's another issue as well. If nothing else there's always group policy. YMMV.

    7. Re:Large? by snowgirl · · Score: 2, Interesting

      I used to work in a similar environment in a university. Tons of windows machines, that I didn't have admin access to. I just carried a usb with me with all sorts of tools that didn't require any more access than a user would have. Seriously borland made a grep for dos that was 7 k back in the 90's. It doesn't sound like you were very creative, but your story does illustrate why the lack of decent command line tools *by default* sucks.

      I didn't even have physical access to the machines. We just RDPed into them, and I had to be logged into every machine at the same time.

      While I had a DFS share that had some of my own tools in it, the problem with running GVim or such off of that is just one of convenience... there were already decent command-line tools available... findstr really does cover everything that I've ever tried to do with grep...

      So, the effort of going out of my way to jury rig all this stuff together wasn't any better than just using the tools that were present.

      We don't really NEED grep... We just need a tool that works LIKE grep.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    8. Re:Large? by ac666 · · Score: 2, Insightful

      BTW - you've been remarkably evenhanded in responding to some pretty snarky, socially-challenged comments. Good on you.

  15. Re:30 to 40 thousand lines isn't large by any meas by istartedi · · Score: 5, Funny

    Very well, sir. Here's your 40,000 lines of Perl from the late 90s. It's mostly regex to parse revisions 30 through 451 of our in-house provisioning system. Oh, and BTW don't screw up like the last guy who had this job. He provisioned 32767 customers with tier-1 service, and it was the director's job to explain why we either had to let them have it for the remainder of the year, or else deal with the CR issues.

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  16. You don't. You find out what the software did by Colin+Smith · · Score: 4, Funny

    And then you re-implement it in the latest language.

     

    --
    Deleted
  17. Hope your management understands by syntap · · Score: 3, Insightful

    I have inherited projects and do my best to convince management that a pause is needed to document the code. Personally I try to flowchart the functionality and cover a couple of office walls with Visio printouts. Later on I can use such work to add detail and further documentation.

    I inherited some code where the developer used names of girlfriends in variable names, it was just dumb and completely unprofessional. I didn't worry so much about keeping track of those, I was more worried about a change in one spot having unintended (and perhaps unknown until too late) consequences. Rather than spend time fixing problems, I thought it best to do some up-front documenting to at least provide a path to successful maintenance.

    When I left the project, the manager had a binder of documentation and almost cried.

    1. Re:Hope your management understands by greg1104 · · Score: 2, Funny

      I inherited some code where the developer used names of girlfriends in variable names, it was just dumb and completely unprofessional.

      I once inherited a coding project where the naming conventions involved anti-depressant, anti-anxiety, and sleeping drugs. Let me tell you, that's a fun preview of how one's future working on the project might turn out.

  18. Try to learn the structure by phantomfive · · Score: 5, Insightful

    I had an English professor who always said, "Structure is the key to understanding." He was talking about literature, but I think the same is true for programs as well.

    Try to understand the structure of the program. What is the basic flow? It should have an initialization routine, a main loop, and a shutdown routine. Find out roughly where they are, then focus on the main loop. Usually there will be one piece of code that is central, and it will occasionally pass control into other large pieces of the program. Sometimes there will be more than one main loop, and control switches back and forth between the various main loops. If the program is event drive, this will make a difference in the structure.

    If you are just trying to make a small change, try to find the sequence of events that will lead up to where that change needs to be made. Follow the sequence of execution until you get to the line you need to change. If you are changing a single variable, sometimes it's helpful to do a search and find all the places that variable is used, to make sure your change won't have any side effects. This may seem time consuming, but it can save 10 times more in debugging.

    Learn to follow code execution with your eyes, without running a debugger. One thing that separates good coders from not so good coders is the ability to follow code that isn't being executed.

    --
    Qxe4
    1. Re:Try to learn the structure by Trepidity · · Score: 2, Interesting

      Depending on the language and domain, one way to speed up learning the structure can be to see if you can match it to some set of programming idioms, and then read up on those idioms if it's not a style of programming you're familiar with. For example, if it's C++, can you figure out by looking at the code's layout whether it was written by someone big into C++ design patterns? If so, it might be easier to reverse-engineer what it's doing if you read a C++ design-patterns book, and then match large segments of the code to "oh it's just implementing [pattern]". In some languages there are 3-4 main styles of programming, and figuring out which of them the author adhered to, and then reading something up on that idiom, can really speed things up.

  19. Re:30 to 40 thousand lines isn't large by any meas by Garridan · · Score: 4, Informative

    Oh yeah, well I just inherited a code base of 2.8 trillion lines of assembly code, and I have to read it over a 12.734 baud VAX connection! Why, back in my day...

    Anyway... I've taken on a few large-scale software projects before, and my approach has always been "read twice, hack once". I agree with the the parent, and I'll add a note: for the love of everything sacred and unholy, use revision control, and don't trust it -- that is, back up incessantly. Document the hell out of your process. Once you've really learned the system, you might want to back out some of the newbie mistakes that you're making right now.

    And yes. Learning a big system takes a lot of time -- you should be reading much more than writing until you've learned it. I find it helpful to diagram dependencies / draw up finite state machines.

  20. Re:You are an idiot by binarylarry · · Score: 2, Funny

    yeah, the clown always creeped me out as well.

    --
    Mod me down, my New Earth Global Warmingist friends!
  21. Re:Use it by EvanED · · Score: 2, Interesting

    Am I off base here? What do you think about intermediate variables that are not strictly necessary?

    I can't say you're off base per se (I don't have nearly enough production dev experience to make statements like that, and even if I did, I couldn't speak for everyone), but my personal style is not quite the complete opposite of yours.

    I pretty heavily use intermediate variables. Why? A couple big reasons. One, if you give the temporary variables decent names, they serve as additional documentation. Two, if you're debugging, you can look at those intermediate values in a debugger (or log them) much easier than you could if they weren't explicitly stored somewhere. In most graphical debuggers you can just hover the mouse over a variable and see its value; if you didn't have that variable, you'd have to enter the expression in the immediate window or set up a watch or something like that.

  22. Done that.. by spasm · · Score: 2, Funny

    As someone who recently passed off a pile of code of about that size in poorly written and poorly documented php to someone.. All I can say is I'm very very sorry, and I had *no idea* my personal side project would work better than the original commercial offering and be declared 'mission critical' three months before I left for greener pastures..

  23. Divide and Conquer by Whomp-Ass · · Score: 4, Informative

    Identify each major portion of functionality. If you are working with a sales/billing system you would probably end up with : Orders, Invoices, Payments, Admin.

    Go through each of those portions and identify the major portions. Orders: Order headers, Order details, business logic, ui logic, reports, datalayer, etc. Repeat until reduced into easily consumable units.

    Pick and stick to an SDLC. Use whatever fits the situation and the resources. For a small project (under 100k lines of code) you should be good by yourself. Anything more and you'll have to involve at least 1 other person for testing. For medium (100k-500k lines) you'll need an additional dev...For large projects (500K-5M lines) you'll need a project manager, lead dev, 2 devs, 1 test, and a UAT team...For larger projects you'll have something unique and frightening to the specifics of the software project and corporation/agency making it...anyway, I digress...

    Go through each subdivision line-by-line and re-write it yourself (even if you aren't going to put your re-written version into production); the only way you're going to truly understand what is going on is if you do it yourself. Use whatever language you are most comfortable with or is most appropriate to the task (or languages), it does not need to be the same as the original.

    Verify that for a given input, your version produces an exact output.

    Take a deep breath. It's not a race. It's a one-to-one functional mapping of your software (your mindspace) and the original software (the other developer(s) mindspace(s)). The code probably will not be straight forward. It has also been battle-scarred and will be warty. Changes of initial requirements through time and feature enhancements (feature creep) will have taken it's toll on what may have originally been something simple or even elegant. It's something of a niche mindset and if it is not for you, there exist many other exciting things to be programming.

    Ultimately, if you do as outlined above, you'll solve many problems, be able to make whatever changes you like, and in so doing have a way to present your design as a replacement if you want...Or not, if you don't; for 30-40k lines parallel development makes sense, in a way, for one person.

  24. Re:30 to 40 thousand lines isn't large by any meas by QRDeNameland · · Score: 2, Interesting

    Just out of curiosity, what is your opinion of a "Large" codebase then?

    My first programming job was on an enterprise system that was over 7 million lines of just C++ code by the time I left, not including SQL stored procedures, web server code for the reporting system, and surely other code stuff that I can't recall. The entire development team for the system was something like 45 programmers. So to many of us, 30-40 klocs does not seem like a large codebase at all.

    That said, I've also inherited code in the 10-50 kloc area of magnitude that was far more of a challenge/nightmare to decipher and maintain than that 7 million line system was. Code maintainability has more to do with good system architecture and coding standards than it has to do with the size of the code base; without those you system will likely collapse under its own bloat long before it can grow to millions of lines.

    --
    Momentarily, the need for the construction of new light will no longer exist.
  25. Re:30 to 40 thousand lines isn't large by any meas by GryMor · · Score: 2, Insightful

    I currently maintain several million lines of perl. It's not hard, it mostly just works, and when it doesn't, it's not that hard to figure out where it's broken IFF there is a consistent repro case for the problem.

    If you have a proper development/production divide, there shouldn't be any weird production issues unless you or your predecessor missed some test cases. If you don't have test cases, that's a problem, if you don't have a properly firewalled and complete development environment, that's a problem, the code itself? Shouldn't be a problem.

    --
    Realities just a bunch of bits.
  26. That's small by ameline · · Score: 2, Interesting

    Medium size is 250 to 750 thousand lines of code (one person can still understand how it all works). Big is 1 to 10 million lines of code. Really big is >10 million.

    I have worked on code bases of all of those sizes, and I like the medium size the best -- it's big enough to be interesting, and small enough that you can understand it all.

    One that I've worked on (over 25 million lines) is just too big for my tastes -- over 3 hours to do a clean recompile is excessive.

    --
    Ian Ameline
    1. Re:That's small by Kagetsuki · · Score: 2, Informative

      25 Million lines compiled in 3 hours is actually pretty fast (unless you are talking about say assembing 25M lines of ASM).

      An associate of mine was working at a very high-tech electric (as in production and distribution of electricity) company. Apparently they had this very complex control system for a huge proprietary piece of hardware that was basically the core of the control rooms. It had to take in data from all sorts of different devices spread out across 100's of kilometers over a variety of proprietary protocols, make sense of all that data, try and figure out what the most likely scenarios for failures were and automatically implement control scenarios to mitigate damage or keep parts of the system running etc. So the story is the thing was written in a combination of C and assembler, and the file count alone was in the hundreds of thousands. They had two extremely beefy boxes set up to just do compiles, incremental compiles and re linking taking a few hours and clean compiles taking basically an entire work day (which is why they had two boxes, so they could start one compile after the other so different people could test their changes more often). The thing is to test their changes they actually had a small control room and a collection of devices on a grid they used to test, and to push the new binaries and data files and get a test set up would take hours as well. Needless to say most of the developers would basically just live in the office during the last month or so of development, but the facility was running 24 hours a day either way so they had a full service cafeteria, lounges, etc. all in the building. Anyway, THAT is the biggest code base I have ever heard of; and I'd bet there are quite a few similar situations around the world.

  27. Re:Use it by mosb1000 · · Score: 3, Informative

    Not without variables, but without unnecessary ones. For example, someone might write:

    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    int g;
    a = dropBox1.Value;
    b = dropBox2.Value;
    c = dropBox3.Value;
    d = dropBox4.Value;
    e = a + b;
    f = c + d;
    g = e * f;
    result.Value = g;

    While I would write:

    result.Value = ( dropBox1.Value + dropBox2.Value ) * ( dropBox3.Value + dropBox4.Value );

  28. I'm afraid the time may already have passed by Chris+Newton · · Score: 2, Interesting

    If both the original developers and the knowledge they had have been lost, then it is probably already too late to perform any major maintenance on this code base. The project has already entered its “servicing” stage.

    At that point, you basically have two possible approaches that actually work: you can restrict maintenance to small-scale changes, which may be sufficient if the goal is just to keep the project ticking over for a while, or you can accept The Big Rewrite (which isn’t so big in this case) in order to get a project that can be properly maintained.

    If you want to go down the tactical changes path, there are a couple of approaches to finding your way around the code.

    If you’re familiar with the general field of the software, just not this particular code, then you can work top-down. Start with the key, high-level concepts you know the program implements, and try to find the code that represents those:

    • Look at things like file names and directory structure (often a good starting point, because these tend to reflect the original design/intent behind the code).
    • Get a tool like Doxygen to draw some graphs of the relationships between functions/classes in the code, and chances are the big clusters of related code will match some of the concepts you’re trying to find.
    • Just search the code base for key words from the problem domain. Look for functions/modules/classes named after them, or that refer to them often.

    Hopefully, if the code has a reasonable modular design and you just don’t know what it is yet, this sort of approach will identify the organisation of the code at a very coarse level, but then you can try to break down each area in more detail the same way.

    Alternatively, you can work bottom-up. Find a significant starting point, such as:

    • somewhere that generates some output you’re interested in
    • somewhere that throws an exception or trips an assertion relevant to a bug you’re trying to fix
    • a busy spot when you run the program through a profiler.

    Examine the code near that point. Look at what kinds of data it works with. Look at what functions it calls, and what functions call it. Try to figure out the wider significance of the code you started with, and the other code to which it relates. Then move up a level: what is the purpose of all of that code collectively? Repeat until you’ve explored as far as you need to.

    After some other discussions about these topics, I recently wrote up a couple of articles with some more background information than I’ve given here — link in my sig if anyone’s interested (though be warned that they are pretty long).

  29. Design patterns are your friend by PerlPunk · · Score: 2, Interesting

    "A couple of times in my career, I've inherited a fairly large (30-40 thousand lines) collection of code. The original authors knew it because they wrote it; I didn't, and I don't."

    A couple of times in your career? You must be lucky. Most jobs you can get coding will always involve taking over someone else's code.

    In my experience, design patterns are your best friend, bearing in mind that most of the code base will always remain a black box to you.

    For example, when I was doing some health insurance work, I had inherited a code base that was substantially larger than 30 or 40 thousand lines of code. The objective was to make the code that used an older, fixed-length record format work with the newer X837 EDI format, which is basically XML but almost without any tags to help you figure out where the data begins and ends. Suffice it to say that the task was to figure out how to smoothly stick a square peg in a round hole.

    The task itself determined the design patterns, of which an adapter pattern was the most used. The type of pattern in turn dictated what in the code to look for in order to implement it, and (of course) how the new code would be built. For example, since we were using an adapter pattern, the first order of business was to find out how the data was represented in the code base, and then trick the "black box" into using your own spiffy, new representation of the data.

    For the most part I didn't have to care all that much how the application handled the data as long as I got the right data into a form the application would accept in my adapater.

  30. Re:30 to 40 thousand lines isn't large by any meas by benjamindees · · Score: 5, Funny

    Perl is like the matrix. At a certain point, after you've stared at it long enough, it all just makes sense.

    --
    "I assumed blithely that there were no elves out there in the darkness"
  31. As a maintenance programmer by npsimons · · Score: 5, Informative

    As someone who has done probably 90% of his work in maintenance programming, let me give you my tips:

    • Snapshot what you get - don't change it, don't even look at it. As soon as you get it, check it in, binaries and all, to a change tracking system (eg, CVS, SVN, etc).
    • Now that you know what they gave you, and you can get back to it at any time, your options are seemingly limitless, but for the quickest way to get up to speed, I would recommend writing unit tests for the software. This will be long and tedious, but by writing unit tests you will a) learn what to expect out of the software, b) be able to tell when you break something and c) truly learn the software.
    • Automate, automate, automate! It's a close call as to whether you should start right away on your first unit test, or get the build system automated, but let me just say that it will save you a ton of time to have a "one button push" way to build, run and test the software. From there, you should be having your machine build and run the unit tests automatically, preferably nightly, from a clean checkout of the repository, just in case you forget to run a test after you change something or you forget to check something in.
    • Run the software (including unit tests) through the gauntlet - valgrind's memcheck, electric fence, fuzz, bfbtester, rats, gcc's -fstack-protector-all flag, libc's MALLOC_CHECK_=3, gcc's _FORTIFY_SOURCE=2 define, gcc's -fmudflap flag, gcc's -Wall -Wextra and -pedantic flags; any way you can think to flush out bugs, do it, and start fixing them; you will learn much, not just about the code, but about the thought process of the original coder(s) this way. Change tools as appropriate for your programming language and environment (including compiler/interpreter, libs, OS, etc). As you can tell, I do a lot of C and C++ programming.

    BTW, the fact that you have a hard time understanding this code may be more a reflection on the original authors' coding skills than on your abilities; any idiot can write code that "just works"; it takes a lot of thought, time and effort to write code that is maintainable, and more often than not, the original coders were short on at least one of those (if not all three). Here's hoping you have the time to follow my above tips; they take a lot of time, but can be worth it if you really need to maintain the code. It's funny to note that apart from the first one, most of those tips apply equally well to developing software from scratch. If the code already has a change tracking system, unit tests, a build/run/test system, *and* automated testing, consider yourself lucky and just start picking apart the unit tests.

    1. Re:As a maintenance programmer by bill_mcgonigle · · Score: 2, Informative

      truly learn the software.

      And then if your unit tests work you'll know enough to comment the code correctly for the next time you or your successor comes back to it.

      --
      My God, it's Full of Source!
      OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  32. Re:Use it by phantomfive · · Score: 3, Insightful

    What do you think about intermediate variables that are not strictly necessary?

    Use them if they make things clearer for someone reading the code, otherwise don't. For example, you can write:

    screen.displayName = user.firstName + user.lastName;

    or you can write

    String fullName = user.FirstName + user.lastName;
    screen.displayName = fullName;


    Thus making it more clear to someone reading that you are trying to use the full name. That is probably not the best example because anyone would probably understand that user.firstName + user.lastName is the full name, but I think you can see the main point, that sometimes it can be easier to read a few meaningfully named intermediate variables than a long equation. If it isn't easier to read, don't do it. But really when I read code, or even write it, I am willing to conform to either way of doing it if someone else feels strongly about it, because that is far less important than things like flexibility of major structures in the code.

    --
    Qxe4
  33. Fix some bugs in the defect tracking database by mstockmyer · · Score: 2, Informative

    When I joined a group that had a 2 Million SLOC program, I learned the most by fixing defects. It gave me a good reason to go traipsing through the codebase. It's painful, but it gives you purpose while reading the code. Just plain reading it gets boring.

  34. You call *that* large? by K77 · · Score: 2, Insightful

    I call that a module. Large is anything over 1,000,000 LOC. Step up.

  35. It's just not the same. by tjstork · · Score: 2, Informative

    he ports of GNU utilities to Windows [sourceforge.net] or Cygwin [cygwin.com] or even your own company's Interix [wikipedia.org] and Services for UNIX [wikipedia.org] products?

    I had Win7 and Vista Ent with Services for Unix I downloaded, and it just did not feel right or work right. The command line utilities work, in part, because the whole OS in Unix is basically a tree of text files. windows isn't, and so, the utilities tend to be less effective. Plus, some gotchas like how Windows handles open files with applications, its all different.

    I thought interix would be the ultimate, but it instead it taught me the opposite. If you want unix, use unix. It's that simple.

    --
    This is my sig.
  36. My Dick is Bigger than Your 250,000 lines of code by BlueBoxSW.com · · Score: 5, Interesting

    Really. A guy asks a question for help and all of these people keep telling him 30-40,000 lines of code isn't much.

    That's a lot of code to get your arms around if you didn't write it. It's not the end of the world, but it is a sizeable task, and is the type of topic that few professional journals or books will ever be written about.

    Having been in similar situations, I my advice would be:

    1) Try to get an understanding of the history of the code. Who wrote it? Why? How many developers? How long has it been around? Do people love it or hate it? Is there a version control system in place you can use for information?

    2) Look at it from a technical viewpoint. Is is complete? Does it compile and run? How many languages are used? Are there interfaces with other systems you need to know about? What dependancies are there? How easy is it to setup a test server? What parts are well coded? What parts stink up the joint?

    3) Dig for functional documentation. What does it do? For whom does it do it? What business needs does it support? How mission critical is it?

    4) Meet with the business owners. Seriously. This helps you do two things: #1-- Define the real business need (which may be different than what was understood by the previous developers), and #2-- Set appropriate expectations about maintenance. You'll work hard to maintain and keep it working, but you are working from a disadvantaged position. It is important they know this and support you in your efforts, rather than complain loudly when something doesn't work.

    5) Plan to remove the dead weight. There's always a lot of dead weight in these near-abandonded projects. Get an idea how to simplify things and plan your work in phases.

    6) Setup real test and development servers. Yeah, you know that wasn't already done.

    7) Use version control. But you know this. It's 2010, and no developer worth his/her salt would code a paying project without version control. Right?

    8) All fixes will take much longer than if you wrote the code, so be careful with estimating time.

  37. Re:30 to 40 thousand lines isn't large by any meas by hobo+sapiens · · Score: 2, Insightful

    well that depends on how many developers we are talking about. The original question seems to indicate that the author has inherited the codebase. The need for this question wouldn't exist if the person were on some large team.

    For one or two or five people, 40K lines is a sizable codebase, especially if it has been poorly maintained / designed.

    --
    blah blah blah
  38. Re:Use it by ciggieposeur · · Score: 4, Informative

    What do you think about intermediate variables that are not strictly necessary?

    My general rules of thumb:

    1) I don't care how many variables are declared, so long as each makes sense on its own. Like another poster's example, 'fullName' is perfectly acceptable (especially for i18n/l10n aware code that may have different rules for generating a name).

    2) I ABSOLUTELY HATE clever arithmetic / pointer arithmetic / expressions all crunched into one line that can be split out. Example: in C-like languages that support pre- and post-increment, I expect the code to use only one or the other consistently, and never mix it with another expression. So this is fine:

    i++;
    j = i + 4; ...but this I can't stand:

    j = ++i + 4;

    #2 I picked up from a very experienced developer who pointed out that making the code harder to read is never worth it, the compiler produces the same code as the easy-to-read version. And that making code that looks 'too easy to be clever' is quite a bit harder than making code that looks 'too clever to always work'.

  39. Re:30 to 40 thousand lines isn't large by any meas by hobo+sapiens · · Score: 4, Insightful

    I am currently working with a mission-critical codebase, which is written in PHP and has absolutely no cohesive design to it. Well, unless you consider making everything static and unnecessarily inheriting other classes and overwriting static variables willy-nilly a cohesive design. There are business rules just everywhere and API requests everywhere and all kinds of calls that overwrite static variables. If you don't methodically trace logic it's really easy to get lost. What makes it worse is that there are many many variables that are named very similarly and you don't really know which one is right and which one is just going to get overwritten in some method call you are not looking at right now. And if this software fails, the worst case scenario is that my company makes no money. It really has made my life over the last few weeks pretty horrid. Fortunately I enjoy the job and the co-workers and am well respected there. Otherwise, it wouldn't be worth the aggravation.

    My advice: communicate your difficulties to everyone who will listen (refrain from complaining or bellyaching, just communicate). If you inherit something like this, and it is mission critical, then you need to take as long as it takes to get it right. That's right, AS LONG as it takes. Take the time to document everything. Bother the crap out of anyone who can help you. You are responsible for doing your job, and part of doing your job is figuring out how to maintain this beast. And in order to do that, you need to use every resource at your disposal. If anyone wants to rush you along, you need to communicate the difficulty and the importance of the task. If you have been working at a place for a while and have done a good job to date, then they should trust you. If you're brand new, then you'd better hope someone there values your opinion and doesn't merely think you are incompetent. If you are asked to make enhancements, don't refactor until you understand the code. So make enhancements, leaving the potentially crappy code in place, even copying it if necessary. Steadfastly resist the temptation to refactor until you understand the entire piece that you are trying ti refactor. Don't remove seemingly unnecessary variables, and don't reduce seemingly redundant database calls. That comes later when you actually know what you are doing in there. IOW, if you have to navigate a lion's den by touch, don't stop to groom the sleeping lion (unless of course, that is your given task.)

    The word inherit seems to imply that either the original maintainer no longer works there or has moved on to a different position. This means that it's you on the hook to figure it out. You've gotta dig in, buckle down, and get to it.

    --
    blah blah blah
  40. Re:30 to 40 thousand lines isn't large by any meas by jimrthy · · Score: 2, Insightful

    That *totally* depends on the code base and the way the OP thinks. Sometimes they're a complete waste of time. Others...not so much.

    I've worked with plenty of programmers who see pretty much every software problem in terms of FSMs. One size does not fit all.

  41. Re:30 to 40 thousand lines isn't large by any meas by Enleth · · Score: 2, Funny

    Seeing software problems in terms of Flying Spaghetti Monsters? Ah, so that's where the "spaghetti code" term comes from!

    --
    This is Slashdot. Common sense is futile. You will be modded down.
  42. Re:30 to 40 thousand lines isn't large by any meas by Z00L00K · · Score: 2, Insightful

    It somewhat depends on the language used - some languages are easier to penetrate than others. And some languages does more in 10 lines than other languages do in 100.

    But anyway - to learn the code you may have to find a starting point (there is usually at least one logical point to start) and then make a flowchart in PowerPoint or something for the general structure. It's no point trying to get into the finer details, just a general sense of flow. You will get things wrong in the beginning, but don't worry. And you may end up finding a lot of dead code too.

    When you have a satisfactory overview of the code it's time to really swim and drink the code. Many programmers have a tendency to accept that "it works" and stop there. By throwing the code into the compiler at maximum warning level and then try to fix all warnings you will be even more involved. And if you aren't satisfied you can take on the code with code analysis tools like Splint (for C) or FindBugs (for Java).

    And don't forget that the commands "find" and "grep" in *NIX are your friends. Other environments usually have other tools, and IDE:s have their own, so you don't have to install Cygwin or something to get a grip on things.

    And if you think that you don't understand the code well enough - try to port it to another operating system or other language.

    Of course - this takes a lot of time and consumption of your favorite hacking beverage.

    And yes - I'm involved as a single developer in a system with about 400k lines of code written in Java, and it was ported from an older system written in C, C++, Basic, Java, DCL...

    --
    If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
  43. Re:No "find" and "grep"? by chentiangemalc · · Score: 2, Informative

    you're using windows 7 and batch files? use powershell, more powerful than any of the unix based shells (that i've seen) and there must be something wrong with your system...or non-OS processed using up CPU & memory....because i've used windows 7 on below minimum spec machines ( 1 GHz CPU and 512 MB ram and the command prompt was still very responsive.)

  44. Re:30 to 40 thousand lines isn't large by any meas by Hal_Porter · · Score: 2, Informative

    Source Insight lets you browse source code - very useful for largish codebases. It's much quicker than findstr or grep because it has an index rather than having to search the whole thing. It's not free of course but I'd never go back to findstr having used it.

    --
    echo -e 'global _start\n _start:\n mov eax, 2\n int 80h\n jmp _start' > a.asm; nasm a.asm -f elf; ld a.o -o a;
  45. I just completed something similar... by mswhippingboy · · Score: 2, Interesting
    I inherited a 15+ year old application about two years ago of similar size written in C (actually Pro*C) that had a long history of crashes (invalid pointers), memory leaks and incorrect results. I was tasked to add additional functionality to the application. I was able to implement the additional functionality, but because of the requirements of the project, I did not address all the structural defects in the application.

    As a result, although the new functionality worked fine, the application still suffered for the "spaghetti" code of patches upon patches of years of various developers adding additional capabilities, but no one ever addressed the reliability of the application. The support group for this application was clearly frustrated with years of late night calls and hours and hours spent trying to correct errors.

    About 6 months ago I was tasked with essentially "cloning" the application for new business purposes. I proposed porting the application to a newer, more modern language (java). It took a lot of selling (i.e. convincing management and other developers that the end result would run just as fast, be easier to maintain and have more reliability), but I was able to get them to buy off on it.

    The rewrite was completed about 3 months ago and the results were better than i had hoped for. I was able to complete the rewrite in the same amount of time allocated for the original "enhancement" project. The application actually runs faster than the old one, has yet to crash (it runs 24x7), and the code is well structured and easy to maintain. We're now in the position that if/when another "enhancement" is requested to the old application, we can simply clone the new java version and completely replace the old app. Given the results of the last project, it won't be a hard sell (especially to the support group) to go the java route.

    I know this is a long post, but the bottom line is that sometimes (more often than many realize), recoding an old application in a modern language and bringing it into the 21st century rather than patching old code can pay off dividends beyond the basic added functionality.

    --
    Sometimes the light at the end of the tunnel is the headlight of an oncoming train.
  46. Have you tried Krugle? by ClosedLoop · · Score: 2, Interesting
    About a year ago, I took advantage of my employer's "Innovation" program to promote our internal use of a code-search tool called Krugle. I took point in contacting Krugle, arranged for a free demo period, and administered the demo on a machine in our network. Of course, I fell afoul of the "Innovation" program, because my version of "Innovation" was something to help us develop a better product. In fact, the program was intended to find a better color for the box, so my Krugle effort was lost on them, but hey I'm not bitter.... Ok, on to the point. I got a dozen developers to participate in the evaluation of a Krugle copy running inside our firewall. It indexed millions of lines of legacy code, organized across a dozen different projects. In my opinion, and I believe the majority of other evaluators as well, being able to search our code exhaustively was a major benefit in getting "arms around" the code base. It changes your outlook. You start asking questions like
    • Where are all the places that a different component calls this API?
    • What the heck does error code 4872339 mean, and who generates it?
    • How many derived classes override this virtual function?

    If you surf on over to Krugle.com, you will see that they now offer a free evaluation copy as a standard product. If you want to get a feeling for what can be done with the tool, just check out Krugle.org, where lots of open-source projects are indexed online. I would definitely recommend using the free evaluation tool as a way of speeding your high-level understanding of any new-to-you code base.