Lurker News
My question is pretty straightforward: how do you, hacker news enthusiast, familiarize yourself with a new codebase? Obviously your answer is going to be contingent on the kind of work that you do.

Some background: What's motivating me to ask is that I am flirting with the idea of trying to add a couple of features to SlickGrid (https://github.com/mleibman/SlickGrid), Michael Leibman's phenomenal javascript grid widget. Unfortunately Leibman got busy and isn't actively supporting it anymore.
The codebase is something like 8k lines of javascript, so it's not ludicrously big, but I'm kind of intimidated thinking about trying to make sense of it. My first strategy is just to open up important-looking javascript files (slick.core.js, slick.grid.js) and read through for comprehension. This seems like a pretty slow way to build a mental model of the code, though. Some features I want to implement are 1. an ajax data source that doesn't require paging, and 2. frozen columns. Someone else has implemented a buggy version of frozen columns (and since abandoned the project), and I might like to use it, but I can't tell if it's buggy because it's a hard problem, or because their implementation strategy was poor (or both!). So at the moment I can't evaluate if I should implement my own, or try to fix the issues with theirs.
Picking up other people's code seems to be one of the harder tasks developers face, as evidenced by how much code gets abandoned, so I wondered if the voices of experience on here could point me in the right direction, either by talking about this problem in particular, or more generally, how you build knowledge about a new codebase.
Thanks!

Comments (238) 122 threads

Show all comments

Showing thread 4 of 122

monk_e_boy4 replies#
Debugger! 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.

shogun218 replies#
What debugger do you use for PHP? I've yet to find one I really like.
cstuder#
xdebug and Eclipse is good enough.

Configuration got a lot easier since the installation wizard has been introduced: http://xdebug.org/wizard.php

jh3#
xdebug and phpstorm is great.
spdionis#
Xdebug is de facto the only debugger AFAIK. The integration in Phpstorm is great.
kieranajp#
http://codebugapp.com is a fantastic front-end for Xdebug. I get a lot of mileage out of this, not least because I only had to set it up once and now it works with whichever editor I'm trying out this week.
__oz#
Xdebug and Netbeans, tons of tutorials on how to set it up on google/youtube.
monk_e_boy#
NuSphere is better than xdebug. It allows more actions and is generally better.

But I use xdebug and phpstorm. I find it better than netbeans. Search in netbeans is good, but the whole thing has a weird GUI and is slow.
Best bet is to try a bunch.

noir_lord#
Xdebug and with phpstorm 9 you have inline display of the values held in that variable which you can expand with a click.

That is incredibly powerful (PyCharm has it as well).

girvo#
Codebug. Phenomenal Xdebug client.
collyw4 replies#
I am surprised how few younger programmers use a debugger these days.
neverminder2 replies#
I'm not a younger programmer and I don't use a debugger. Tried it several times and found it counterproductive.
candu1 reply#
Like with most useful tools, you have to use it more than "several times" to gain fluency.

Continue this thread — 1 reply

kelvin010 replies#
How is it counterproductive exactly? The setup of the debugger itself? Or trying to figure out how it works?

Continue this thread — 10 replies

gbersac3 replies#
I just use printf and other stuff to dump critical variable. I also use unit test a lot.
kelvin04 replies#
Ah yes, the good ol' printf-debug-polluting-codebase method. What's fun after that, is when programmers all start competing to have their printf's be more visible in the sea of prints ... I find this method primitive at best. How do you manage it?
weavie3 replies#
You remove the printfs when you have fixed the problem.

Continue this thread — 3 replies

casta#
I think he meant to add print statements locally. You remove them before committing the code.
Chris_Newton#
I find this method primitive at best. How do you manage it?

Don’t be primitive about it. :-)
The serious answer is: use a good logging framework. In particular, I’d suggest something that can log at selective levels of information for different parts of your system.
If your project’s culture is to instrument your code like this routinely, it can be a very useful asset, and it’s no more disruptive in practice than say adding comments or writing tests. In each case, with experience you get better at judging where to focus your efforts and how much detail is worth including by default, and if that turns out not to be enough you can always add more while you’re working in that area.
With modern tools for recording and analysing logs, there is relatively little useful information that you can easily find using a debugger but can’t easily find from good log output. On the other hand, logging has some big advantages: you can capture how your system changes over time, you can record and review concurrent behaviour cleanly, you can capture information from different parts of distributed systems that might be written in different programming languages or running on different devices.

ninkendo3 replies#
In my case, aggressively reject any printf statements in code review. Get that shit out of my repo.

Continue this thread — 3 replies

jeremiep#
I tend to do that mostly for concurrent programs, as I want to see what happens without blocking the entire system like a debugger would.

For medium/large programs I'll often prefer a debugger because I can easily and quickly try to diagnose the problem without having to wait for a new build to complete with the added traces.

barrkel2 replies#
printf = breakpoint expression evaluation (but without the flexibility)

You're using a primitive debugger, you just don't know it.

Continue this thread — 2 replies

neves#
Debuggers and profilers are essential tools, but I was surprised when I read the book "Coders at Work: Reflections on the Craft of Programming" that a lot of the greatest programmers debugged just with a printf.
archagon1 reply#
Maybe this is just my lack of experience speaking, but I find debuggers incredibly difficult to use when dealing with interactive software (which is most software I work on). Hitting a breakpoint freezes my interaction unless I configure it to print something, and configuring it to break conditionally requires knowing some obscure incantations that I can never remember off the top of my head (and that in turn require their own debugging). So it boils down to: should I spend 5 minutes figuring out how to set this conditional, print-only breakpoint? Or should I just put in a printf? The solution, at least to me, is obvious.

(With that said, when I have a nasty bug that requires squishing around in the guts of my program, breakpoints are invaluable. But it's a pretty huge hammer that only comes out on occasion.)
EDIT: I wonder how useful an editor that allows inline debugging code would be? Instead of setting breakpoints in your IDE and then configuring them in an individual window, you'd enter a "debugging editor" mode that would allow you to add debugger-only code for things like conditional breakpoints and printf statements right alongside your normal code. The original source files would not be edited, but while in this mode, it would appear as if they were. (Maybe the debugging code would show up in red.) That way, you could easily access all your local state and implement complicated queries without ever leaving the context of your code. In other words, it would be just like printf debugging, but once you no longer need to debug you'd just collapse those statements out by leaving the debugging editor mode and your original code would be unchanged. Perhaps this debugging code would not compile along with the rest of the code but would instead use the debugging hooks that normal breakpoints use, unless the conditions are particularly complex or something. Just a thought.

bostonvaulter21 reply#
Not sure if you know this but if you're in javascript you can just drop a 'debugger;' statement anywhere in your code and it will function as a breakpoint.

Continue this thread — 1 reply

__oz#
Debugger++

Without a debugger you're a sitting duck!

parshimers#
Debugging through the test cases in particular is a good way to decipher/dissect things, at least that I have found. Usually you can find a test case that is only for a specific component that you are interested in, and then the test case should only exercise those pieces, so there is not an overwhelming amount of information all at once.