• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bugging the Debugger

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are testing code and it does what it is told to do but not what you want where do you start to look? I am enjoying the brandings education and was wondering if there is any obvious way of looking at code to see where the bug is going to pop up?
Also do you ever have a bug rear it's ugly head and decide you can use it for something else? I spent a L-O-N-G time on hundred 1b and kept having the code run at the correct length forever or just getting the first line at the correct length, what could I do with that, besides get cattle prodded?
 
author
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure that there's a simple answer to your question, I'm afraid, Harry.

There are certainly occasions where, once you see a bug the answer to where it probably exists just "pops into your head". But there will be other occasions where you just have to apply time, effort and sweat to dig it out. Nobody ever claimed that debugging was easy ;-)

Having said that, there are certainly some types of code that are "intrinsically buggy" (i.e. you can tell that there's a bug just by looking at the code without even running it). Here's an example in C++

The answer is that x could have any value whatsoever - the C++ standard simply doesn’t define what this code does. In practice, most compilers will do something “sensible” with it, and typically x will end up equal to either 1 or 2. But theoretically speaking, it could end up equal to 42, the program could crash, or anything else could happen. That, unfortunately, is what undefined means.

Interestingly, if you compile the same code in Java, then its behavior is defined - x will always end up with the value 1. But don’t feel too smug if you’re a Java developer - the behavior may be defined, but it’s still almost certainly a bug. Presumably whoever wrote this code intended it to do something, where in fact it’s a no-op. So, whatever it was they intended it to do, it’s not doing it.

The great thing about this kind of bug is that you can detect many of them automatically by using static analysis (tools that crawl over your code looking for this kind of thing).

As for using buggy code for something else, I fear that you're out of luck. There are far more ways to write incorrect code than correct code, and the chances of a bug happening to solve some other problem for you is very slim indeed, I'm afraid :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic