Linked by Thom Holwerda on Tue 28th Aug 2012 19:20 UTC, submitted by MOS6510
General Development "Coming from a background in higher-level languages like Ruby, Scheme, or Haskell, learning C can be challenging. In addition to having to wrestle with C's lower-level features like manual memory management and pointers, you have to make do without a REPL. Once you get used to exploratory programming in a REPL, having to deal with the write-compile-run loop is a bit of a bummer. It occurred to me recently that I could use gdb as a pseudo-REPL for C. I've been experimenting with using gdb as a tool for learning C, rather than merely debugging C, and it's a lot of fun. My goal in this post is to show you that gdb is a great tool for learning C. I'll introduce you to a few of my favorite gdb commands, and then I'll demonstrate how you can use gdb to understand a notoriously tricky part of C: the difference between arrays and pointers."
Thread beginning with comment 532871
To read all comments associated with this story, please click here.
Debuggers
by kwan_e on Wed 29th Aug 2012 02:21 UTC
kwan_e
Member since:
2007-02-18

I've always found well targeted print statements more helpful than debuggers, even for complex software, and not just for the purposes of debugging, but for learning a new language as the article is suggesting.

Reply Score: 2

RE: Debuggers
by wigry on Wed 29th Aug 2012 07:42 in reply to "Debuggers"
wigry Member since:
2008-10-09

Indeed, with print statements you can see how the program at particular point behaves, how the over all picture looks and then easily figure out the issue how to fix it, because bugs are rarely on a single line, instead they are often broken logic and with debuggers you will not see the big picture.

Reply Parent Score: 2

RE: Debuggers
by bouhko on Wed 29th Aug 2012 08:24 in reply to "Debuggers"
bouhko Member since:
2010-06-24

I'm using logging and print to "debug" stuff 95% of the time. Yet, sometimes debuggers are useful, especially if you're dealing with segfault or memory allocation issues which are pretty damn hard to find with print.

Also, valgrind is a very good tool.

Reply Parent Score: 2

RE[2]: Debuggers
by kwan_e on Wed 29th Aug 2012 08:45 in reply to "RE: Debuggers"
kwan_e Member since:
2007-02-18

especially if you're dealing with segfault or memory allocation issues which are pretty damn hard to find with print.


Of course.

Importantly for me though is debugging by printing does the important thing of making you review design in the process. You're actively testing your own assumptions of how the design is working. I find that people who use debuggers most of the time tend to fix problems locally rather than wondering if a slight alteration to a design would eliminate whole classes of defects. This makes it even better for learning a new language.

Reply Parent Score: 2

RE: Debuggers
by ephracis on Wed 29th Aug 2012 20:19 in reply to "Debuggers"
ephracis Member since:
2007-09-23

I like using breakpoints which let me inspect variables by just hovering my mouse over the variable's name anywhere in the code. Then I can jump up and down the call stack and see how my execution has been moving around the code.

A really nice complement to log output.

Reply Parent Score: 2