The best way to familiarize yourself with an inherited codebase

后端 未结 14 1434
[愿得一人]
[愿得一人] 2021-01-30 02:54

Stacker Nobody asked about the most shocking thing new programmers find as they enter the field.

Very high on the list, is the impact of inheriting a codebase with which

14条回答
  •  走了就别回头了
    2021-01-30 03:11

    Another Procedure...

    After reading Andy Hunt's "Pragmatic Thinking and Learning - Refactor Your Wetware" (which doesn't address this directly), I picked up a few tips that may be worth mentioning:

    Observe Behavior:

    If there's a UI, all the better. Use the app and get a mental map of relationships (e.g. links, modals, etc). Look at HTTP request if it helps, but don't put too much emphasis on it -- you just want a light, friendly acquaintance with app.

    Acknowledge the Folder Structure:

    Once again, this is light. Just see what belongs where, and hope that the structure is semantic enough -- you can always get some top-level information from here.

    Analyze Call-Stacks, Top-Down:

    Go through and list on paper or some other medium, but try not to type it -- this gets different parts of your brain engaged (build it out of Legos if you have to) -- function-calls, Objects, and variables that are closest to top-level first. Look at constants and modules, make sure you don't dive into fine-grained features if you can help it.

    MindMap It!:

    Maybe the most important step. Create a very rough draft mapping of your current understanding of the code. Make sure you run through the mindmap quickly. This allows an even spread of different parts of your brain to (mostly R-Mode) to have a say in the map.

    1. Create clouds, boxes, etc. Wherever you initially think they should go on the paper. Feel free to denote boxes with syntactic symbols (e.g. 'F'-Function, 'f'-closure, 'C'-Constant, 'V'-Global Var, 'v'-low-level var, etc). Use arrows: Incoming array for arguments, Outgoing for returns, or what comes more naturally to you.
    2. Start drawing connections to denote relationships. Its ok if it looks messy - this is a first draft.
    3. Make a quick rough revision. Its its too hard to read, do another quick organization of it, but don't do more than one revision.

    Open the Debugger:

    1. Validate or invalidate any notions you had after the mapping. Track variables, arguments, returns, etc.
    2. Track HTTP requests etc to get an idea of where the data is coming from. Look at the headers themselves but don't dive into the details of the request body.

    MindMap Again!:

    Now you should have a decent idea of most of the top-level functionality.

    1. Create a new MindMap that has anything you missed in the first one. You can take more time with this one and even add some relatively small details -- but don't be afraid of what previous notions they may conflict with.
    2. Compare this map with your last one and eliminate any question you had before, jot down new questions, and jot down conflicting perspectives.
    3. Revise this map if its too hazy. Revise as much as you want, but keep revisions to a minimum.

    Pretend Its Not Code:

    If you can put it into mechanical terms, do so. The most important part of this is to come up with a metaphor for the app's behavior and/or smaller parts of the code. Think of ridiculous things, seriously. If it was an animal, a monster, a star, a robot. What kind would it be. If it was in Star Trek, what would they use it for. Think of many things to weigh it against.

    Synthesis over Analysis:

    Now you want to see not 'what' but 'how'. Any low-level parts that through you for a loop could be taken out and put into a sterile environment (you control its inputs). What sort of outputs are you getting. Is the system more complex than you originally thought? Simpler? Does it need improvements?

    Contribute Something, Dude!:

    Write a test, fix a bug, comment it, abstract it. You should have enough ability to start making minor contributions and FAILING IS OK :)! Note on any changes you made in commits, chat, email. If you did something dastardly, you guys can catch it before it goes to production -- if something is wrong, its a great way to get a teammate to clear things up for you. Usually listening to a teammate talk will clear a lot up that made your MindMaps clash.

    In a nutshell, the most important thing to do is use a top-down fashion of getting as many different parts of your brain engaged as possible. It may even help to close your laptop and face your seat out the window if possible. Studies have shown that enforcing a deadline creates a "Pressure Hangover" for ~2.5 days after the deadline, which is why deadlines are often best to have on a Friday. So, BE RELAXED, THERE'S NO TIMECRUNCH, AND NOW PROVIDE YOURSELF WITH AN ENVIRONMENT THAT'S SAFE TO FAIL IN. Most of this can be fairly rushed through until you get down to details. Make sure that you don't bypass understanding of high-level topics.

    Hope this helps you as well :)

提交回复
热议问题