Ask HN: How do you familiarize yourself with a new codebase?
11–20 of 246 posts
Re: Ask HN: How do you familiarize yourself with a new codebase?
#12Set a breakpoint, burn through the code. Chrome has some really nice features - you can tell it to skip over files (like jQuery) you can open the console and poke around, set variables to see what happens.
Stepping though the code line by line for a few hours will soon show you the basics.
Re: Ask HN: How do you familiarize yourself with a new codebase?
#13Re: Ask HN: How do you familiarize yourself with a new codebase?
#14Sure, this is not the best practice, and unsuitable for many, but it's what works for me.
Re: Ask HN: How do you familiarize yourself with a new codebase?
#15* Read the README.
* Install it and start using it with a couple of sample cases. That will give you an idea of what it does.
* Read the test suite. This will give you a better idea of what the library does.
* Look at the directory structure. This should tell you where things are.
* Start reading the core files.
* Start looking at open issues. Try to solve one by adding a test and changing the code.
* Submit a pull request.
Re: Ask HN: How do you familiarize yourself with a new codebase?
#16For the ajax data source thing, I would try to modify or extend the existing data source code to add the behavior you are looking for. As you mess around with it trying to figure out what you need to change, you will encounter the areas of the code that you need to understand.
With this sort of strategy you can avoid having to fully understand all the code while still being able to modify it. You might end up implementing stuff in a way which is not the best, but you will probably be able to implement it faster. It's the classic technical debt dilemma: understanding the complete codebase will allow you to design features that fit in better and are easier to maintain and enhance, but it will take a lot longer than just hacking something together that works.
Re: Ask HN: How do you familiarize yourself with a new codebase?
#17Debugger! Surprised no one has mentioned it yet. I work in js and php, both of which I use the debugger a lot . Set a breakpoint, burn through the code. Chrome has some really nice features - you can tell it to skip over files (like jQuery) you can open the console and poke around, set variables to see what happens. Stepping though the code line by line for a few hours will soon show you the basics.
Re: Ask HN: How do you familiarize yourself with a new codebase?
#18Once I've found and fixed a few things, or if the code base is particularly small or clean that I can't find bugs to fix, I'll set about hacking in the feature I'd like.
I usually start by doing it in the most hacky way possible. That sounds like a bad approach but it narrows the search of how to implement it and means I'm not constraining myself to fit the code base that I don't yet appreciate.
In hacking that feature I'll often break a few things through my carelessness. In then trying to alter my hacked approach so it no longer breaks stuff I'll become more aware of the wider code base from the point of view of my initial narrow focus. This lets me build up the mental model.
Eventually I'll be comfortable enough I can re-write the feature in a way more consistent with the wider code base.
I don't normally start by trying to "read all the code" because that guarentees I won't understand much of it (I'm not quick at picking up function from code). I might have a skim if it is well organised, but I find the "better" written a lot of stuff is, the harder it is to grok what it is actually doing from reading it. to me, reading good code is often like trying to read the FizzBuzz Enterprise Edition[1].
I've worked on many legacy systems: I was last year implementing new features into a VB6 code base, this year (at a different job) I am helping migrate from asp webforms to a more modern system. I've found that starting with trying to fix an issue to be the best way to dive into the code base.
Use good source control so you're never "worried" about changing anything or worrying that you might lose your current state. Commit early, commit often, even when "playing around".
[1] https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...