Sign in to follow this  
ouraqt

Unity Debugging? What???

Recommended Posts

Hey folks. I've been programming for about five years now (just as a hobby - no formal schooling). But because I've taught myself everything, I seem to have missed out on one big topic: debugging. I never bothered to learn how to use a debugger. Now, I have VS 2005, so I definitely HAVE a good debugger (or so I'm told), I just have no idea how to use it. But I've been fine for five years without it, so I'm reluctant to learn now. I've done some cool things, like this graphing calculator. Not using a debugger has made me good at predicting what my code will do before I run it, so if I ever do learn how to properly debug (instead of using cout<<... or MessageBox(...)) I think I will be a great programmer (because I focus more on writing code that works the first time). So, is it worth it to learn proper debugging? I always just set my projects to "release mode" and never bother with "debug" mode. I seem to be fine with the way things are now, but will debugging prowess make me a much more efficient programmer? PS: Another one of my bad habits is cramming everything into one .cpp file (I don't always do this, but it happens too often). If the project starts out small (like the graphing calculator I linked to above), then I never bother to encapsulate parts of it and compartmentalize the program.

Share this post


Link to post
Share on other sites
Well let's put it like this, all of my colleagues know how to use a debugger. It's not because they're lazy, in fact quite the opposite. We use debuggers because it allows us to fix the problems you *dont* see from the outside looking in. When you start developing more complex software it just isn't enough to be able to write code which compiles and runs without defect - sometimes you will encounter a crash bug and to figure out why it happened you will need to peek around the heap and the stack, cpu registers, disassembly, the call stack, what other threads were running at the time, what other processes were doing .. If you've got this far without learning to use a debugger then well done for sticking with it, but your life is about to get a whole lot easier.

Share this post


Link to post
Share on other sites
A good programmer (or any professional, really) knows how to use all tools available to him or her. A debugger is a very powerful, important tool to know how to use. And besides, you certainly won't be any worse off for learning how to use a debugger.

Quote:
Original post by ouraqt
PS: Another one of my bad habits is cramming everything into one .cpp file (I don't always do this, but it happens too often). If the project starts out small (like the graphing calculator I linked to above), then I never bother to encapsulate parts of it and compartmentalize the program.


If you ever want to work with other people on reasonably sized projects, please don't do this.

Share this post


Link to post
Share on other sites
Quote:
Original post by ouraqt
I've been programming for about five years now (just as a hobby - no formal schooling). But because I've taught myself everything, I seem to have missed out on one big topic: debugging. I never bothered to learn how to use a debugger.

You programmed for 5 years, and you never used a debugger ? You have no idea what you missed. Learn to use it, right now. Seriously, you'll be looking back and wondering how you could ever work without one.

I had to briefly work on a (very small) project without a debugger (kernel mode, fun), and I almost killed myself... I felt like I was developping on a C64 again.

Share this post


Link to post
Share on other sites
I've been just the same like you: developing personal projects without a debugger for 5 years while at university. My way of debugging was to print text messages on screen and see how far it got (the crash would be after the last message it printen). This simply because there didn't come any debugger with DevC++ and later in linux gdb never really seemed interesting to me because it was text based. My only experience with debugging came from long ago in QBasic, which is a scripting language that has debugger built in its IDE in MS DOS.

However at work I started using the debugger in visual studio at the first day already and it's really simply, (breakpoints, step into, step over, step out, all very straightforward). It's really an advantage that if your program crashes, you automatically go to the code where the crash happened, and that you can place breakpoints to see intermediate values of variables :)

Becoming dependent on that (once you start using a debugger it's hard to go back) quickly made me learn gdb in Linux too for my personal projects, it's all really the same as te debugger in Visual Studio, except you have to manually go to the C++ file and the line number instead of it automatically going to it and placing breakpoints is more clumsy (no simple mouse click like in VS).

5 years I've been working with printing strings from inside the code to sort of debug, but really, using a debugger is much handier and really worth it.

Other tools to consider are a profiler or an advanced debugger/memory leak detector like valgrind (though that one's only for linux though afaik).

[Edited by - Lode on March 3, 2008 7:13:39 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by ouraqtSo, is it worth it to learn proper debugging?


Absolutely! The amount of time and headaches a debugger will save you will pay back 1000 fold the time you invest in learning it. Do it now! [wink]

Share this post


Link to post
Share on other sites
I once worked on a project with a manager that was very against the use of a debugger. Yes, there are crazy people out there. The short of it is that his influence alone made the project more difficult and there were some bugs that were found by some of the developers much later in the project than usual (there's only so much you can do with couts/cerrs). I have no doubt that with the use of a debugger, that things would've ran much more smoothly. Of course, knowing what I know now, I would've disobeyed that order and used a debugger anyway, but at the time I was newer in the industry and didn't know better.

The moral of the story is that it's hard enough to write quality software with a debugger. Without a debugger it's almost infeasible.

Also, as mentioned above, please don't write massive source files. One class per source file, that should be your general rule. If your classes are large, you need to split up things into more smaller classes.

Share this post


Link to post
Share on other sites
Dang. I guess I better get started.

This whole time I've been using cout for console programs and MessageBox flr\\or GUI programs (another thing that came in handy for real-time output was the title bar text of a window).

Another thing I think would make programming faster would be a GUI editor (I think one comes wiht VC++ 2005? I've used it to make dialogs before).

Usually I only write code that is seen by myself, and although I try to keep it as neat as possible, I never realized how much it piqued people to have it all lumped together. Thanks for the advice, buddies!

Share this post


Link to post
Share on other sites
When writing code, you will make mistakes, and a huge part of how efficient you are at producing code that works for both you and for others is how efficiently you're able to find and correct your mistakes (and often the mistakes of others).

This means writing code in such a way that errors are caught before you even get to a debugger. So... use asserts liberally (in "debug" modes, normally), and check as much at compile time as you can get away with.

But also learn how to use a debugger. When something isn't working, you usually don't understand why it isn't working right off the bat. There are a couple methods of figuring it out. A common one is adding extra prints to show the values of variables and state, but often it's superior to just step through the offending code in a debugger and see what's going on.

Debuggers are just an efficiency tool. In a way debugging is a lot like coding in that they're both sorts of puzzles. But debugging is the more frustrating one and you want to avoid it if you can by designing and coding as carefully, simply, and cleanly as you know how.

Oh, and a story: last week I spent around 2 days debugging a problem. The code fix turned out to be changing 3 lines. You'll want to learn to debug... there's a good chance you'll be doing it more than coding in a professional environment.

Share this post


Link to post
Share on other sites
I think learning to debug code without the aid of a debugger is a useful and valuable skill. As you say, it forces you to focus a bit more on code correctness rather than a trial-and-error approach. And it is more educational to learn to spot the logical error in your code, than for a debugger to find it for you. But there are many times when something goes subtly wrong and a debugger is far and away the most efficient and effective way of resolving the problem. For those times, you owe it to yourself - and to any future colleagues, if you end up working as a programmer - to learn how to use this valuable tool.

Share this post


Link to post
Share on other sites
Working without a debugger makes you more cautious, IMO (well, makes -me- more cautious). If you ever get stuck working on embedded systems, sometimes the stuff you work on can't be remotely debugged (you write the code, stick it on device, hope it works). This is not always the case, but I have had to do it a few times and it ...well, it is unpleasant, shall we say? It's never nice to see that a simple mistake (overwriting something that you meant to keep protected in memory) can cause your entire system to crash irrecoverably :(

I vote for debugger in all circumstances where you can use one! When that fails, formal logical reasoning is your best bet (but only if you really care what happens when you start things up).

~Shiny

[edit] Reasons why people still care about formal methods :P

Share this post


Link to post
Share on other sites
hm... my two cents:

Reasons for using a debugger:
Faster to find bug,
Multithreading, call stacks, memory windows, dynamic value changes,
Enables to understand easilly what is the bug and why,
Allows you to step through your program easilly seing how its being run
No changes to the release code (ie: you are sticking it full of message boxes)

Reasons for knowing how to debug without a debugger:
Not always possible to debug (on client site for example)
some languages just dont have debuggers or arent easy to get them (javascript, Java for example, though now there are debuggers for it as well).
Not dependent on a debugger or worst a particular debugger.
Requires knowledge of the application's logic and working.

Reasons for Not using a debugger:
Debugger not available.

Conclusion:
Make sure you can debug without a debugger but dont do it unless you have to.

just my thoughts but they since ok.

Yours Truly
K

Share this post


Link to post
Share on other sites
ok. a lot of people already comment and pretty much all of them agree that yes it's a good thing... and so do I.

A programmer that can't debug isn't really a programmer!

Using breakpoints, watches, stacks, context and so on are all your friends... learn them.

also debugging is great when you want to know what is going on in other peoples code and 99% of the time programmers will be working on other peoples code in a company.

debug debug debug (gods gift to programmers)

Share this post


Link to post
Share on other sites
Quote:
Original post by BloodWarrior
Reasons for knowing how to debug without a debugger:
Not always possible to debug (on client site for example)

Remote debugging over the internet. That saved our asses quite a few times in the past... :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this