Mental state whilst coding, debugging.

Status
Not open for further replies.

QuadDamaged

Ars Praefectus
3,983
Subscriptor++
Hello,

I am going through some changes in my life which made me re-evaluate every aspect of my behavior. Something that struck me is how I approached coding, particularly my approach on debugging.

Back in '99, I discovered this comic, and it struck a chord in me, so I've always kept it around, as this was exactly 'me'



If you feel this way, please accept this humble piece of advice: maybe you might want to look into you. Why are you anger-powered?

I have since then changed the way I approach this, and debugging is now a net positive experience, where I bring TLC to my 'children'

I am interested to know how you guys approach coding / designing.
 
I'm kind of weird. I like nothing more than hunting down and fixing bugs in code that someone else wrote. The more obscure, the better. This is probably why I like working on terrible legacy code bases - it's easy to be a hero.

Debugging my own code generally just leaves me pissed off because 1) I'm forced to confront all the less-than-perfect decisions I've made in the past and 2) the fact that there are bugs in my code in the first place :D
 

wallinbl

Ars Legatus Legionis
14,319
Subscriptor
[url=http:/civis/viewtopic.php?p=27820015#p27820015:2fqxsald said:
jxl[/url]":2fqxsald]I fall asleep and when I wake up, either I realize that I must have been tossing and turning in my sleep and knocked over a bunch of stuff or someone snuck in and kindly put everything in its place for me.

Revert if the former, commit if the latter.
Most clarity comes to me first thing in the morning. Usually, what I've done the day before is refactored the following morning when I wake up with much better clarity on how to do it.
 

wallinbl

Ars Legatus Legionis
14,319
Subscriptor
[url=http:/civis/viewtopic.php?p=27821389#p27821389:a0vuvboo said:
jxl[/url]":a0vuvboo]I was speaking figuratively about how debugging feels, but I'm with you on often getting my best work done early in the day, when I can come in with a quiet mind, precise focus and a basic list of tasks in my head and just knock it out.
I literally wake up with it, sometimes immediately, sometimes a few minutes later in the shower. Sometimes, I'm so excited with the idea that I never make the drive into work because I go immediately to the computer to try it and end up working from home.
 
[url=http:/civis/viewtopic.php?p=27821875#p27821875:ir28i8bh said:
Horatio[/url]":ir28i8bh]I feel badly when I'm debugging, especially something that's in production code. It usually means I fucked something up badly, and didn't do due diligence - my tests were insufficient, or I didn't cover a condition. My debugging (in the debugger) skills are starting to atrophy though, and I think that's actually a good thing.

Hey at least it exploded on your watch :)
 

Horatio

Ars Legatus Legionis
24,430
Moderator
[url=http:/civis/viewtopic.php?p=27822727#p27822727:lodfovpg said:
Bastard[/url]":lodfovpg]
[url=http:/civis/viewtopic.php?p=27821875#p27821875:lodfovpg said:
Horatio[/url]":lodfovpg]I feel badly when I'm debugging, especially something that's in production code. It usually means I fucked something up badly, and didn't do due diligence - my tests were insufficient, or I didn't cover a condition. My debugging (in the debugger) skills are starting to atrophy though, and I think that's actually a good thing.

Hey at least it exploded on your watch :)
Yeah, it's worse when it doesn't. Then people get awoken at 3am... It hasn't happened to me yet though. < knock wood >
 

Azzcat

Ars Tribunus Militum
2,146
I get the most enjoyment out of going through everyone else's code. Hunting down bugs is interesting and feeds my natural curiosity. Finding the pieces, figuring out intent, and having moments of discovery and illumination - awesome stuff.


Building it from scratch - eh, I'm not all that great with that. Give me other people's frameworks, other people's code, any day over coming up with my own stuff. I get stuck trying to come up with New and Improved and Fixed ways of doing the same old stuff.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
The feeling of satisfaction when you get the "Aha" moment is a joyous thing. I get frustrated when I can't work out what's wrong, but more often than not when I'm frustrated it's because the tools are getting I. My way rather than the code.

I tend, like most of us I expect, to submerge myself in the task, unaware of time passing, until it works.
 
Since were talking about debugging: How can i debug a stream dispose error? I have a file that needs to delete itself after closing but it doesn't. FileOption.DeleteOnClose is set and I close it explicitly ( at least I think i do ) but my application keeps it open.

I'm not that versed in .Net/VS to know were to start. This is in F# and it concerns a stream that is part of a Record Type.

If I close my application the files delete themselves like they should. I just want them to delete themselves when they go out of scope.
 

dragonlord

Ars Scholae Palatinae
1,123
The first thing I'd do is put some sort of indicator at the point that you think it should be closed (whether that's a break point or a message box). And then check to see if the file exists after you've closed it. If you never reach that indicator then you know what the problem is. If you do, and the file still exists then you know where to start looking.
 
[url=http:/civis/viewtopic.php?p=27835783#p27835783:z6g9fi00 said:
dragonlord[/url]":z6g9fi00]The first thing I'd do is put some sort of indicator at the point that you think it should be closed (whether that's a break point or a message box). And then check to see if the file exists after you've closed it. If you never reach that indicator then you know what the problem is. If you do, and the file still exists then you know where to start looking.

Thanks, i figured it out. The object also had another stream within it which I did not close in the Closing statement. Thanks :) Putting a console writeline in the Close method helped me find it :)
 

Ben_H

Ars Scholae Palatinae
1,059
[url=http:/civis/viewtopic.php?p=27819171#p27819171:2npa1pvx said:
SurfaceTension[/url]":2npa1pvx]It's a game for me, much like a crossword puzzle, or chess.
This is 100% my mindset. I find it fun. I never get mad. Maybe a bit annoyed if it's for an assignment and the deadline is fairly soon, but outside of that, I like it a lot. Though I don't get paid to do this stuff yet. I imagine once I'm under a lot more pressure and there's a crippling bug, I could probably get rather annoyed, but right now it's all fun for me.
 

dragonlord

Ars Scholae Palatinae
1,123
[url=http:/civis/viewtopic.php?p=27835837#p27835837:11m4n90o said:
Bastard[/url]":11m4n90o]
[url=http:/civis/viewtopic.php?p=27835783#p27835783:11m4n90o said:
dragonlord[/url]":11m4n90o]The first thing I'd do is put some sort of indicator at the point that you think it should be closed (whether that's a break point or a message box). And then check to see if the file exists after you've closed it. If you never reach that indicator then you know what the problem is. If you do, and the file still exists then you know where to start looking.

Thanks, i figured it out. The object also had another stream within it which I did not close in the Closing statement. Thanks :) Putting a console writeline in the Close method helped me find it :)
It's just debugging tools 101 :) now you've had to use it for this you'll know you can use it in future.

You may want to add a setting to your program to "enable logging" and change the console.writeline to a logfile.writeline. Then when you get similar problems in the future you can just switch on logging and see if the problem is occurring where it shouldn't be.

Also in all of my dotnet programs, I always log exceptions at an appropriate level as not doing so only means that when you get a problem in production you need to reproduce the problem and hunt down where it's occurring rather than just looking at the stack trace from the log and seeing if the problem is obvious from what's happening in the code :)
Code:
Imports System.IO.File

Public Shared Sub logException(ByVal ex As Exception, ByVal modulename As String, ByVal Title As String)
        SyncLock LogLock
            Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Logs\" + modulename + "ErrorLog.log"
            If Not IO.Directory.Exists(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Logs\") Then
                IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Logs\")
            End If
            If Not Title Is Nothing Then
                AppendAllText(path, "--------------------------------------------------------------" + CrLf)
                AppendAllText(path, "--------------------------------------------------------------" + CrLf)
                AppendAllText(path, Title + CrLf)
            End If
            AppendAllText(path, Now.ToString() + " " + ex.Message + CrLf)
            AppendAllText(path, "--------------------------------------------------------------" + CrLf)
            AppendAllText(path, ex.StackTrace + CrLf)
            AppendAllText(path, "--------------------------------------------------------------" + CrLf)
            If Not ex.InnerException Is Nothing Then
                AppendAllText(path, "Inner exception")
                AppendAllText(path, "--------------------------------------------------------------" + CrLf)
                logException(ex.InnerException)
            End If
        End SyncLock
    End Sub
 

QuadDamaged

Ars Praefectus
3,983
Subscriptor++
Just a remark, you are obviously American from the use of Date.ToString - get in the habit of future-proofing your date to string conversions just in case you end-up with a server in a different timezone.

DateTime.UTCNow.ToString(CultureInfo.InvariantCulture) (or use another format with the timezone specifier. Think Z is what you need)
 

dragonlord

Ars Scholae Palatinae
1,123
[url=http:/civis/viewtopic.php?p=27836487#p27836487:1fx5oixs said:
QuadDamaged[/url]":1fx5oixs]Just a remark, you are obviously American from the use of Date.ToString - get in the habit of future-proofing your date to string conversions just in case you end-up with a server in a different timezone.

DateTime.UTCNow.ToString(CultureInfo.InvariantCulture) (or use another format with the timezone specifier. Think Z is what you need)
Actually I'm British but I wrote this back in 2003 and have never needed to update it.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
[url=http:/civis/viewtopic.php?p=27836861#p27836861:o753x1vh said:
dragonlord[/url]":eek:753x1vh]
[url=http:/civis/viewtopic.php?p=27836487#p27836487:o753x1vh said:
QuadDamaged[/url]":eek:753x1vh]Just a remark, you are obviously American from the use of Date.ToString - get in the habit of future-proofing your date to string conversions just in case you end-up with a server in a different timezone.

DateTime.UTCNow.ToString(CultureInfo.InvariantCulture) (or use another format with the timezone specifier. Think Z is what you need)
Actually I'm British

It's okay, we're all the same to the French ;)
 

dragonlord

Ars Scholae Palatinae
1,123
for us, the time format doesn't actually matter in the error logs as long as they are consistent across all of the error logs on a particular machine. If we start having machines and database that cross time zones we may have to think about how the logs work if the time zones stop us from correlating events between verbose logs and error logs.
 

fitten

Ars Legatus Legionis
55,633
Subscriptor++
[url=http:/civis/viewtopic.php?p=27836465#p27836465:35l5u272 said:
dragonlord[/url]":35l5u272]
[url=http:/civis/viewtopic.php?p=27835837#p27835837:35l5u272 said:
Bastard[/url]":35l5u272]
[url=http:/civis/viewtopic.php?p=27835783#p27835783:35l5u272 said:
dragonlord[/url]":35l5u272]The first thing I'd do is put some sort of indicator at the point that you think it should be closed (whether that's a break point or a message box). And then check to see if the file exists after you've closed it. If you never reach that indicator then you know what the problem is. If you do, and the file still exists then you know where to start looking.

Thanks, i figured it out. The object also had another stream within it which I did not close in the Closing statement. Thanks :) Putting a console writeline in the Close method helped me find it :)
It's just debugging tools 101 :) now you've had to use it for this you'll know you can use it in future.

You may want to add a setting to your program to "enable logging" and change the console.writeline to a logfile.writeline. Then when you get similar problems in the future you can just switch on logging and see if the problem is occurring where it shouldn't be.

Also in all of my dotnet programs, I always log exceptions at an appropriate level as not doing so only means that when you get a problem in production you need to reproduce the problem and hunt down where it's occurring rather than just looking at the stack trace from the log and seeing if the problem is obvious from what's happening in the code :)

Logging is very important, especially in production systems that you can't simply restart whenever you feel like it. I've worked on systems that had fairly sophisticated logging... you could turn on/off logging to different parts of the system, the 'depth' of logging, etc. all during runtime. It would also buffer the last (configurable) amount of logging without writing anything in case there was an exception, then it would dump the exception and all of the buffered logging. You could also configure multiple logging sinks... each one with different configuration so multiple people could log different things (or even the same thing, maybe at different depth/level settings) at the same time. The exception sink was one that was always 'on'.

And then the output of that logging is important. We dumped to a CSV file so you could load it into Excel or dump it into a database and filter however you wanted. If a customer reported an issue, the odds were that we had the logs of the actual instance that we could use to investigate.

Of course, all that depended on the developers putting logging in all over the place to record anything that might be important/interesting during runtime. And of course, the logging needed to be low overhead because it was always present, even if configured to not be recording.

Having all that in place, most issues were fairly straightforward to figure out.
 
Status
Not open for further replies.