News for hackers. Stuff that matters.
Re:Ask HN: How do you familiarize yourself with a new codebase? by kelvin0 on Friday June 26, 2015 @10:51AM (#9784781)
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?
Re:Ask HN: How do you familiarize yourself with a new codebase? by Chris_Newton on Friday June 26, 2015 @12:46PM (#9785945)
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.

Re:Ask HN: How do you familiarize yourself with a new codebase? by weavie on Friday June 26, 2015 @11:12AM (#9785016)
You remove the printfs when you have fixed the problem.
Re:Ask HN: How do you familiarize yourself with a new codebase? by thaumasiotes on Friday June 26, 2015 @05:57PM (#9787997)
It's so tempting to do this. Don't. Problems may occur again in the same area. Leave your logging statements around; configure your logging setup to skip them when you don't want them.

You're saying to delete commented-out code once the new code works. Put your code in version control instead. Logging is to once-off printfs as version control is to commented-out code.

Re:Ask HN: How do you familiarize yourself with a new codebase? by weavie on Saturday June 27, 2015 @03:50PM (#9791328)
Not so sure. Once I get to the stage where I have to stick printfs in the problem tends to be so localized and specific that once fixed I will never need to look at that area of code in that way again.
Re:Ask HN: How do you familiarize yourself with a new codebase? by collyw on Thursday July 02, 2015 @07:12AM (#9818112)
I do this far more than I should. The code ends up a mess after enough debugging like that.
Re:Ask HN: How do you familiarize yourself with a new codebase? by ninkendo on Friday June 26, 2015 @01:03PM (#9786093)
In my case, aggressively reject any printf statements in code review. Get that shit out of my repo.
Re:Ask HN: How do you familiarize yourself with a new codebase? by lberger on Friday June 26, 2015 @02:37PM (#9786798)
Without trace statements, how do you diagnose issues that don't occur locally and only appear in the production environment.
Re:Ask HN: How do you familiarize yourself with a new codebase? by ninkendo on Sunday June 28, 2015 @01:39PM (#9794291)
Traces are the kind of thing that should be automated anyway... You shouldn't have to write explicit trace statements in your source code, instead your language or framework should have an automated way of inserting these statements at function boundaries. Or even better, attach a debugger and reproduce the issue yourself on the prod server.

Just plain "debug log statements" I have yet to hear a good use case for. Every time people have put them in, it's because some bug called for their inclusion, then the bug got fixed, then the statements got left around after the bug was fixed. Or the bug didn't get fixed and it's a matter of "why don't you fix the bug?"

There's rare cases where there's an ongoing issue with a known bug that you don't know the fix for yet, so you drop debug statements in production code hoping to catch it. But this is supposed to be a rare, rare case.

Re:Ask HN: How do you familiarize yourself with a new codebase? by robertfw on Friday June 26, 2015 @05:04PM (#9787743)
That would be the difference between printing and logging
Re:Ask HN: How do you familiarize yourself with a new codebase? by casta on Friday June 26, 2015 @11:14AM (#9785035)
I think he meant to add print statements locally. You remove them before committing the code.