News for hackers. Stuff that matters.
Re:Why don't schools teach debugging? (2014) by tallanvor on Tuesday April 25, 2017 @03:49AM (#14191545)
In school, you're always told to show your work. I'm sure a lot of us here tended to be among the smartest in your class, at least before university, and we often thought having to show our work was silly. That's why a lot of us get tripped up when it comes to the type of debugging the author is talking about (it certainly still happens to me sometimes).

Showing our work reminds us that solving problems is an iterative work, and when we get the wrong answer, it lets us (with or without the help of the teacher) step through and figure out what we did wrong. For teachers and professors, it probably becomes second nature, and maybe they forget who explained this to them, or when they realized it themselves.

Even once we're out of school, I think we need to remind ourselves that this is the same reason we don't write a 1000 line function, rather we break it up into smaller parts, each designed to solve a specific part of the overall problem.

Now, what I really wish we had had in university was a CS course on using gdb and/or WinDbg - not just to understand how to analyze a core/dump file or step through running code, but also to help drill it into our head what compilers do to our code, and how processors really work. --It's amazing how often I have to remind people that debuggers will often lie to you, and you often have to look into the registers for the real data!

Re:Why don't schools teach debugging? (2014) by erikpukinskis on Tuesday April 25, 2017 @04:06AM (#14191613)
I just think debugging is art and parcel of programming. Debugging should come up in the first practical exercise in a Graphics 101. It should come up the first time you do an ML assignment in Programming Languages.

Its absence in any course is conspicuous.

But at the same time more than half of the professional web developers I know don't really use a debugger. Equally problematic.

Re:Why don't schools teach debugging? (2014) by tallanvor on Tuesday April 25, 2017 @06:15AM (#14192157)
Is an ML course now a common part of an undergraduate degree program, though? --I genuinely don't know, which is why I'm asking.

These days it would certainly be much easier to teach students how to use a debugger - most students probably aren't doing their work on mainframes anymore where resources might be limited (anyone else remember getting emails asking you to release your semaphores because the server is running low?), but professors still have to decide which topics are the most important to cover in a limited amount of time.

Re:Why don't schools teach debugging? (2014) by OJFord on Tuesday April 25, 2017 @07:24AM (#14192473)
Edit: skim-read GP, got the wrong ML.

I touched on the PL ML in a type systems course. I can't speak for how common it is though. It's certainly much more likely for someone who takes a course on type systems or PL theory though, presumably given that choice it's pretty common.

--

> Is an ML course now a common part of an undergraduate degree programme​, though?

There were several available to me. It's​ not really a particular interest of mine, but I took an introductory course anyway, since it would have seemed a bit remiss in today's world to have graduated without knowing an NN from an SVM.

Unfortunately for my grades, performance usually reflects interest... I still don't think I actually regret it though.

Re:Why don't schools teach debugging? (2014) by erikpukinskis on Tuesday April 25, 2017 @09:30PM (#14199793)
Yeah, I was referring to MetaLanguage, not Machine Learning.
Re:Why don't schools teach debugging? (2014) by pjmlp on Tuesday April 25, 2017 @09:19AM (#14193197)
It was to me, as a "Artificial Intelligence II" optional lectures, in the mid-90's.

I rather focused on compiler design and graphical programming options instead, but I remember that all the basis for neuron learning algorithms were already part of the content.

Re:Why don't schools teach debugging? (2014) by dagw on Tuesday April 25, 2017 @04:49AM (#14191799)
But at the same time more than half of the professional web developers I know don't really use a debugger. Equally problematic.

I wonder how much that has to do with tooling? When programming in python I run everything in a debugger basically all the time. When doing JavaScript front-end work it's back to print debugging.

Re:Why don't schools teach debugging? (2014) by ams6110 on Tuesday April 25, 2017 @09:03AM (#14193053)
I almost always start with thinking about where the bug is likely to be, then doing some print/log debugging to confirm or reject my suspicions. I find it pretty effective and simple to do.

Debuggers are complicated and create dependency. How many developers do you see every day just sitting at their computer tapping "step" ... "step" ... "step" for hours.

I'll break out a debugger if all else fails, but it's not my first choice.

Re:Why don't schools teach debugging? (2014) by eropple on Tuesday April 25, 2017 @11:23AM (#14194321)
> How many developers do you see every day just sitting at their computer tapping "step" ... "step" ... "step" for hours.

Er...very few? A bad programmer will be a bad programmer with a debugger and that bad programmer will be a bad programmer who prints out state after every line of code.

Breakpoints and watches are strictly superior to print statements for understanding the system you're working with. You drop a breakpoint where, as you yourself put it, "the bug is likely to be," you look around, you kill the process and you make a change. It doesn't "create dependency", it's just better at solving the problem. Anyone can fall back to println debugging if necessary. It's not some difficult thing. But it's wasting your time.

Re:Why don't schools teach debugging? (2014) by JustSomeNobody on Tuesday April 25, 2017 @11:34AM (#14194438)
I find a good logging library will help me narrow down the issue before I enter the debugger to watch what the system is doing.

If I'm 90% sure I know what the bug is and it's a system where it's easier to add a print than to enter the debugger (yes, those types of systems exist), I'll do that first.

Re:Why don't schools teach debugging? (2014) by eropple on Tuesday April 25, 2017 @11:57AM (#14194706)
Systems where debuggers are difficult to access totally exist, of course! But, IME, they're pretty rare by comparison (unless you've footgunned elsewhere). Whether it's something like `pry` in Ruby where you can open a REPL on command or a JVM where you connect with an external debugger, most systems are flexible enough to work with you.

If you've written something in a language where you don't have a debugger...that's your own damned fault. :-P

Re:Why don't schools teach debugging? (2014) by dozzie on Wednesday April 26, 2017 @06:53AM (#14202011)
> Systems where debuggers are difficult to access totally exist, of course! But, IME, they're pretty rare by comparison

It's often hard to run a stepping debugger when you have an embedded hardware at hand. It's equally hard to run such a debugger when you have multi-threaded code. And the same stands for virtually any system that works with network directly, where timeouts are plentiful.

Also, good luck with a debugger in this modern architecture of microservices that happens to be hype nowadays.

Re:Why don't schools teach debugging? (2014) by eropple on Thursday April 27, 2017 @11:27AM (#14212193)
> It's often hard to run a stepping debugger when you have an embedded hardware at hand.

Totally true. But that's a pretty rare situation.

> It's equally hard to run such a debugger when you have multi-threaded code.

Maybe your experience is different, but Every piece of multi-threaded code I've ever written has fallen into one of two buckets: task-pooled parallelism or interlocking features that shouldn't block one another. The former is trivial; reduce the task pool size to a single thread. The latter is definitely harder, but modern tooling (I'm partial to VS2017's Threads window) makes this a much more achievable thing; you can break across all of them and step between them effectively.

> And the same stands for virtually any system that works with network directly, where timeouts are plentiful.

I find myself debugging in environments where I can control timeouts, but if you can't, yeah, this is totally a problem. Leaving a service paused for ~3-5 minutes while I poke at it doesn't drop connections with my dev configs, though.

> Also, good luck with a debugger in this modern architecture of microservices that happens to be hype nowadays.

"Doctor, it hurts when I do this..."

If you can't effectively stub out an environment around your microservice so that you can run it in a debugger-friendly environment, you don't have a microservice--you have a monolith that communicates over pipes rather than function calls, and that's strictly worse in the first place.

Re:Why don't schools teach debugging? (2014) by dozzie on Thursday April 27, 2017 @04:14PM (#14214313)
>> It's often hard to run a stepping debugger when you have an embedded hardware at hand.

> Totally true. But that's a pretty rare situation.

I know it's rare to work with embedded systems if you don't work with embedded systems. Though when you do work with them, this "rare situation" suddenly becomes prevalent.

>> It's equally hard to run such a debugger when you have multi-threaded code.

> Maybe your experience is different, but Every piece of multi-threaded code I've ever written has fallen into one of two buckets: task-pooled parallelism or interlocking features that shouldn't block one another.

It all works well until it doesn't. That is, until you need two threads to communicate with each other (otherwise, why are they even running in the same process?).

>> And the same stands for virtually any system that works with network directly, where timeouts are plentiful.

> I find myself debugging in environments where I can control timeouts, [...]

All of them? My simplest cases have dozen timeouts one behind the other, at different levels of the stack. Even though I potentially can set them all, it's all very tedious. Not to mention that the timeouts can interact in non-trivial ways, so it's often hard to track all of them.

>> Also, good luck with a debugger in this modern architecture of microservices that happens to be hype nowadays.

> If you can't effectively stub out an environment around your microservice so that you can run it in a debugger-friendly environment, you don't have a microservice

https://en.wikipedia.org/wiki/No_true_Scotsman

Also, I haven't said that "you can't effectively stub out an environment". There are other difficulties around debugging microservices, like mentioned before controlling timeouts everywhere.

Re:Why don't schools teach debugging? (2014) by TheCoelacanth on Tuesday April 25, 2017 @12:46PM (#14195377)
With frontend JS, I usually find the friction of using a debugger lower than the friction of adding logging since I don't have to reload to add/remove it. You can even add a conditional breakpoint that logs and always returns false to capture the effect of adding a log statement.

I rarely use the step functionality, though, because it just takes too long. More frequently when I hit a breakpoint, I examine the current state, figure out the next place that I am interested in stopping and then add a breakpoint there before resuming.

Re:Why don't schools teach debugging? (2014) by majewsky on Tuesday April 25, 2017 @04:54AM (#14191819)
Exactly. Have fun debugging a microservice in production. All you can do is increase the log level, and even that is sometimes not possible because the program would spew out so many logs that it would bring down either some disk or the network.

In these cases, the Feynman method is sometimes all that you can apply. I have already spent plenty of hours with a stacktrace on one screen and the source code on the other screen, stepping through the source code in my mind (usually backwards from the end of the stacktrace).

Re:Why don't schools teach debugging? (2014) by rnabel on Tuesday April 25, 2017 @05:47AM (#14192024)
In many ways, the tooling around web development is far superior to other languages (e.g. golang with delve). Most browsers ship with excellent debug tools.

The caveat obviously being that debugging code written using some JS frameworks, like Polymer, is a nightmare.

Re:Why don't schools teach debugging? (2014) by erikpukinskis on Tuesday April 25, 2017 @06:38PM (#14198807)
That's it. Declarative asset compilers like Webpack break debugging. Transpiling breaks debugging. Convention-over-configuration frameworks and tools like Ember break debugging. Other declarative APIs like promises and and virtual DOMs break debugging.

PHP and JavaScripy are great for debugging. Even Node is awesome. Rails and mainstream JavaScript frameworks... not so much. Nothing about the languages.... The people who design the frameworks and build tools just don't seem to value it.

Re:Why don't schools teach debugging? (2014) by senorjazz on Tuesday April 25, 2017 @07:50AM (#14192598)
and in many ways the tooling around web development is absolutely terrible (eg not a brand new language eg go but an established language eg any of them)
Re:Why don't schools teach debugging? (2014) by Waterluvian on Tuesday April 25, 2017 @08:09AM (#14192688)
Which is so odd to me because the JavaScript debug tools are some of the most complete and easiest to use. They're right there!
Re:Why don't schools teach debugging? (2014) by dagw on Tuesday April 25, 2017 @08:30AM (#14192807)
But I can't get them to integrate well with my dev tools. If, for example, I'm using something like babel/webpack/Typescript there is no easy way that I've found to for example just set breakpoint on a line of code in my editor/IDE and have the web browser debugger break when it gets there.
Re:Why don't schools teach debugging? (2014) by eriknstr on Tuesday April 25, 2017 @08:57AM (#14193007)
True you probably can't set the breakpoint in your IDE but thanks to source maps you can still view the original source in the debugger.

https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_...

Re:Why don't schools teach debugging? (2014) by Tistron on Tuesday April 25, 2017 @09:13AM (#14193149)
Not as convenient, but you can write the statement `debugger;` and the debugger will stop there.
Re:Why don't schools teach debugging? (2014) by bostonvaulter2 on Wednesday April 26, 2017 @12:10AM (#14200372)
I find it incredibly convenient because I don't need to go through the browser trying to find the same spot in the code.
Re:Why don't schools teach debugging? (2014) by Sacho on Tuesday April 25, 2017 @11:08AM (#14194173)
VSCode provides this functionality(https://code.visualstudio.com/docs/editor/debugging).
Re:Why don't schools teach debugging? (2014) by nradov on Tuesday April 25, 2017 @10:55AM (#14194058)
When I was attending Harvey Mudd College I worked on an engineering clinic team with a significant software component and was shocked to find that none of my teammates knew how to use an interactive debugger. This really slowed the team down and made the work far harder than it needed to be. At the end of the project I wrote a letter to the department head suggesting that they add a unit on debugging to the core curriculum. But I don't know if they ever acted on it.
Re:Why don't schools teach debugging? (2014) by jnordwick on Tuesday April 25, 2017 @06:09AM (#14192123)
> debuggers will often lie to you, and you often have to look into the registers for the real data

What do you mean by this?

Re:Why don't schools teach debugging? (2014) by gambiting on Tuesday April 25, 2017 @06:46AM (#14192310)
Well I don't know what OP meant, but I work in games programming, and the PS4 debugger will frequently lie to you in visual studio. You hover over a variable and it's just giving you a completely wrong value, which is correct if you look directly into memory window or assembly view.

I wouldn't consider this to be a very common use case though, it's a niche within niche.

Re:Why don't schools teach debugging? (2014) by SticksAndBreaks on Tuesday April 25, 2017 @06:50AM (#14192329)
Its that way in all the niches, which makes it a set of all niches ==> mainstream thing.
Re:Why don't schools teach debugging? (2014) by duncanawoods on Tuesday April 25, 2017 @07:08AM (#14192405)
Optimised C++ sure but you don't see this issue with C#. If you are using a high-level language that does not have a reliable debugger, time to change language.
Re:Why don't schools teach debugging? (2014) by ska on Tuesday April 25, 2017 @09:07AM (#14193090)
One of the things that happens here is the more static and optimized a compiler output is, the harder it is to do source level debugging. Conversely, more dynamic, less optimized languages are easier to write and verify debuggers for. This isn't a strict ordering, of course, but a general trend. Unfortunately, the very aspect that make some languages easier to debug make them poor at some of the applications you might want the former for (cf C# and c++ as you bring up).

Luckily debugging is not merely the act of using a debugger !

Re:Why don't schools teach debugging? (2014) by pjmlp on Tuesday April 25, 2017 @09:26AM (#14193270)
I imagine this situation might surface when looking at optimized native code, either from JIT or AOT, for example via WinDbg sos plugin for .NET.

Still not a reason enough to avoid using a debugger.

Re:Why don't schools teach debugging? (2014) by SticksAndBreaks on Tuesday April 25, 2017 @06:49AM (#14192321)
Debuggers sometimes simply write wrong values into those nice gui-windows- do not update the values they show, or just dont inform the reader that the value ceased to exist- at all.
Re:Why don't schools teach debugging? (2014) by jnordwick on Wednesday April 26, 2017 @02:03AM (#14200812)
Oh, so a bug in the debugger basically. Speaking of the registers it sounded like he was talking about some weird cache incoherency issue that shouldn't conceivably exist (on x86 at least).