Skip to content
loading...

How do YOU debug

twitter logo github logo Updated on ・1 min read  

career questions for data folks (5 Part Series)

1) What is YOUR advice to NEW Data Scientists. 2) How did YOU enter Data Science 3) Why do YOU Data Science 4) What is Your Advice for a new Team Lead 5) How do YOU debug

How do YOU debug?

  • debugger?
  • print statements?
  • log files?
  • sending messages to your phone?
  • super simple setup?
  • super complicated setup?
twitter logo DISCUSS (19)
markdown guide
 

Hi,

PHP => xdebug, custom logs
js => chrome tools, breakpoints, inspect, I don't use console.logor stuffs like that in file

I try to keep it as simple as possible so easy setup. However, I do think "complicated" setups can be useful sometimes especially if you need some profiling.

 

honestly in js, I always console.log, if I want to go deeper, I right-click store as variable and inspect it from the console. I've wanted to setup a debugger before, but it seems like a lot of setup. Am I wrong in thinking that?

 

Same here.
I also love to use console.log ))

 

I am with the others so far, print statements cover 95% of my debugging. Most of the time I can trim it down to a very small quick running chunk and a couple of print statements, gives me enough insight.

I would also say that I heavily use the ipython repl which gives me a lot of power to inspect things as I am running things.

I also recently learned about the built in python debugger. I had something buried deep into a pipeline that would only error after running for 10 minutes. Python gives you a very convenient breakpoint() in 3.7+ or import pdb; pdb.set_trace() for python 3.7-. ipython also gives you an incredible magic command to run %debug after an error occurs, to allow you to jump into a debugger right where your last error occurred. Again I am still heavily in the print statement debugging camp.

 

Front end here so we don't tend to keep logs.

95% of the times I debug the scope is fairly small.

  1. I start with a print statement here and there, which is enough most of the time.
  2. If I need to debug properly, I use the debugger with a breakpoint, where I can trace through the code at particular points and see what's happening and what values are.

Other options:

  • If serious debugging is needed I kind of do detective work. I think "what could be wrong?" and go on from there using the debugger on things that could be going wrong.
  • I don't use "binary debugging" but I imagine it would be useful if the scope was quite large.
  • Git bisect (or manually checking out commits) to find the commit where the bug originated. This is very useful because (with a good commit history) it drastically reduces the scope you have to debug.
 

Good one with git bisect. I didn't even think to categorize that as a debugging technique.

Do you fully setup dev tools in your editor to get a debugger running on the front end? I have never done it, so I wonder what the different levels of setup look like. I imagine there is a quick and dirty use browser dev tools up through setting up everything into your editor.

 

Yeah I use git bisect rarely, it can be quite good :).

Ah I haven't really done that in a while because the browser (I do web development) has really good debugging tools. I have used an editor debugger before that "latches on" to the browser debugger, but I haven't used that since my last job because I didn't need to. To use the browser debugger you can write debugger in the JavaScript code where the debugger should start, or just use the browser debugger directly which is fully functional.

Other than that I do use debuggers that don't run in the browser, such as for Node.

 

I'm all about the print statements. Can't quite wrap my head around debug tools when I want to work fast.

When totally lost, deleting code until the problem shows up is my process of elimination technique.... Thank god for modern version control.

 

Thank god for modern version control.

Heck yes. Version control is so valuable for a good debug session. Slice away all you want then figure out what you actually changed once its all said and done.

 

Mostly with print statements and log files.

  • Find out which function is causing a problem with log files
  • Copy&paste the function and rename the original function old. e.g. problematic_function_old
  • Add print statements to the copied one.
  • Usually I add print statements one by one. And throw an error immediately after the print statement. In this way, I can do some "unit test" inside a function. Reproduce the error but step by step, figuring out from where it goes wrong.
  • If I'm convinced that the error has been fixed, remove the old function.

OMG, I've been simulating a debugger with print statements. xD
In most cases, I don't use debuggers because they suck!

 

OMG, I've been simulating a debugger with print statements.

🤣

I like the idea of copying the function. For some reason I only do this when developing cli tools, but sometimes I will make a verbose flag, then make a separate print function that does an if versbose fro me and i just call vprint for example.

 

Print statements all the way.

Debuggers are, to me, very slow and painful when I can often achieve better/faster results just by logging my app's data.

 

I only recently started using a debugger at all. I am still with you for 90% of my use cases though!

 

Pry Rails is a must for me when working with Ruby. Debugger that allows me to stop the code and peek around and test variables. Plus it makes the console format better and with color!

github.com/rweng/pry-rails

 

Commonly in the browser, I debug using chrome inspect and a lot of breakpoints.

Working with React + Redux I use this redux-logger nice middleware to help debug or add my own middleware to Redux, like:

const actionLoggerMiddleware = store => next => action => {
  console.groupCollapsed(action.type);
  console.info('dispatching', action);
  const result = next(action);
  console.log('next state', store.getState());
  console.groupEnd();
  return result;
};

const middlewares = [networkMiddleware, thunk, actionLoggerMiddleware];
const middlewareEnhancer = applyMiddleware(...middlewares);

Note: networkMiddleware and thunk are the middleware that is enabled in the project I'm working at this moment.


When working with React Native I like to use Reactotron and in some cases, I use this simple package called logger.js for add simple logs with emojis with a more visible way :)

 
 

Interactive shell if possible.

I hate myself when I am using print. It is so graceless. 😂

 

Everyone here is a genius so far... print statements all the way :D

Classic DEV Post from Jul 2 '19

How to refill someone’s “cup?”

Sometimes we rely so much on our friends and coworkers that we often forget to ma...

Waylon Walker profile image
I am a self taught python developer, with a background in Mechanical Engineering. During the day I mostly do Data Engineering, with a bit of front end even though my official title is Data Scientist.

Hey there reader...

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️