debugger's block [closed] - debugging

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Do you ever run into a bug where you are just out of ideas and don't know what to try next, and you're getting really annoyed? Are there any general ideas on how to break out of this mode?

When I get blocked like that, the best advice I've found is leave for a while. Whether it's going for a long lunch or leave for the day. Come back fresh and take a new look. Most of the time the answer will be staring you in the face. So far a 10 minute coffee break hasn't been enough for me, but your mileage may vary.
Second, talk to your peers. Walk through everything you've tried. Just ask them to listen, and while you're talking it through, a lot of times, the answer will come to you.
Those are just the two that I use most often when I'm debugging blocked.

Five minute break
Utterly critical, lest you smash your keyboard.
Explain the problem in an email to your sister
Or your two year old son. Someone who wouldn't understand a word* unless you explained it very clearly. You don't need to send the email, you just need to be certain that you understand it inside out. You be surprised at how many times simply restating the problem suddenly makes it obvious to you where you went wrong. This is a good way of discovering what your assumptions were about the problem, and how they might not necessarily be correct.
*That link is to an excellent answer by JaredPar on a different SO question.
Talk to a colleague
By this point you've already 'emailed' the family pet, so you know that you've hopefully covered all the stupid aspects, it's time to talk to a real person. They may have experienced some obscure thing in the past that reminds them of this situation, and they'll definitly have a different perspective. Try to make sure you are clear about what the problem is, not what you think it is. You don't want to bias them. You can and should talk about what they've tried, and explain why you think the problem is in that area (you're probably right) but you don't want to close your mind to their suggestions, even if they don't seem right.
Look at the code again
By this time, you should hopefully be less violent, and you should be armed with new ideas. Start by re-verifying the bug. A simple step, but I've been frustrated for hours on a bug that was in our test script and not in our code. Once you've verified the bug again, start at the top. Verify EVERYTHING. Put a breakpoint at the last point you are 100% confident in, and then work your way forward until you find that the output is broken again. That's a huge success because you now have a hopefully smaller code block to investigate. Then, if necessary, pull in a colleague to look at the actual running code.

I usually take a break... if that doesn't work, I sleep on the problem. (Actually, to be honest, I should say that I spend a sleepless night mulling over the problem).
I almost always have a list of possible solutions ready by morning. :-)

I usually take a few steps:
look at the code that is involved in the functionality that has the bug and place logger messages in a way that they will help me narrow the problem (this allows you to look at the logger later on when you are not that annoyed anymore, and maybe find useful hints :P)
ask my senior collegues for hints
call the client to have a clear understanding of when the problem arises

I usually end up in that mood when I didn't take a structural approach from the beginning.
By iteratively narrowing the area where the problem can live and trying to write the smallest code base that can reproduce the error, I haven't failed yet.

Others have mentioned taking a break or "sleeping on it". This technique is known as (amongst other things) Incubation. Once you embrace the idea you can take it further too.
One important aspect as to really leave the problem behind, confident that you'll have answers later. The dangerous otherwise, especially if sleeping on it, is that you'll be worrying over it up to the last minute, then this becomes an endless cycle that your mind gets caught in overnight. You'll probably end up waking up not too well rested having dreamt many circular dreams. Do this too much and it's a path to depression.

I think if you run into that kind of problem it is time to do some serious refactoring...
Also it could indicate false assumptions. Try to assume programmatically all that you are 'just' assuming. See to it no method-invariants are broken of any methods that are in the stack.

Another good option is to bounce ideas off other developers/team members. Sometimes they will ask you questions you hadn't considered.
If you work alone, it's a good idea to have a few fellow developers who you can chat to to troubleshoot with some different approaches. You'd be amazed how often a fresh perspective can be the breakthrough you need.

Try David Ungars "Shower Methodology":
"If you know what to type, type. If you don't know what to type, take a shower and stay in the shower until you know what to type"
This kind of summons up what the majority likes to do. Take a break ! Doesn't matter what kind of break it is, as long as you are not thinking of the things you were doing before the break. Distraction in any form is good.
Cheers !

I usually take a dry run through the offending method/function, step by step. And don't assume the bug is coming from there, it could be coming from anywhere before it.
Use a proper debugger, don't use a series of printfs.

Related

How to do your best when everybody is too busy? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Sometimes I have seen some code or part of the project which I could improve but is not related with my current team project.
Those times I have a conflict because despite wanting to help, many teams lack enough people and doing extra work seems like betrayal. Obviously any managers will appreciate much more if you focus your effort on their tasks
What do you do in in these cases?
I have two guiding principles in cases like this:
I am here to do what my boss wants. If it's sweep the floors I can either do it or find another job but as long as I'm here that's what I'm to do.
If the boss makes a bad decision and I know better and tell him and he decides it anyway, it's the boss's prerogative. If I don't tell him then it's my fault.
Unless there's overriding circumstances this dictates that in the case where the code is outside my assignment I tell my boss that the code can be made better, and give him an idea what that means to him in real world terms, and ask whether he wants me to do it or not.
Yes, it does come back to bite me sometimes when I don't just do it, but he's paying me to do X and if I'm tinkering with Y then I'm not doing what I'm paid to do. He just has to pay me to fix it when it does come back to bite me(us)!
I think the key part of your statement is this:
which I could improve but is not related with my current team project
This sounds harsh, but it is based on experience and should be read with an open mind - keep out of it. One thing you learn as you get more dev experience under your belt is that you stay in scope, don't go diving off to fix something that is not scheduled. Here are a couple of reasons why:
when someone is planning the project, they are working with a known set of problems. If you randomly decide to "fix" things you are changing that known set, it is like when you are navigating using a map and someone is changing the map on you
you may think your fix is good for the product but it introduces extra complexities, like who is going to test your fix?
no matter how good you think you are, you run the risk of introducing another bug or unintended side effects into the application
how do you communicate your change to the other team members who may be working in that area?
how do you know for sure the scope of your change, how do you know that you haven't suddenly changed the context of a piece of code elsewhere?
You have good intentions, but if you start doing things like this you may be seen as a cowboy, and others will dislike you pretty quickly.
It is a skill you have to learn - know when not to touch things. You will see ugly code - don't touch! Don't recode things simply because you think it can be done better.
I hope this helps :)
I worked for a small company in the past, and if I saw something that I knew would impact me or someone else down the road, I generally fixed it then and there if I could do so in a short time frame without breaking anything.
You know the kinds of problems I'm talking about. If I don't spend 10 minutes to fix it now, it's going to cost me 30 minutes (over and over) later.
Otherwise, it went on the whiteboard with the other things to do (which was always full) and someone got around to it eventually.
You either clean it up when you're in someone else's house, or you step around their mess. Both choices can cause trouble. Which to choose depends entirely on you and your situation.

How to make sure that momentum is kept after a major development milestone? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
My team (4 people) have just reached a major milestone in our development, putting us at about 2/3 finished, but I guess the stress has caught up to everyone and all the gears have ground to a near halt, progess is being made at 1/5 of the original speed. I wanted to ask the SO community how to best deal with this, I've identified the following problems.
Lack of clear focus and direction. We seem to be hitting small side improvements, but not working towards anything central to the project so I think that's causing a lack of enthusiasm.
Coming down off of a very strong development push. This seems to have made everyone want to really "relax" which is fine for a bit, but progress still needs to be made.
The remaining tasks are more tedious than glamorous. This is the nature of the beast but I have yet to tame it effectively.
Any help is appreciated.
Some downtime is necessary after reaching major milestones. People need to relax and decompress. Pushing on just carries the stress and fatigue forward and the team won't be working anywhere near their potential.
Give everyone a couple days to a week off and let them come back fully refreshed and ready to continue.
Tell them you only need 3 people to finish the project.
I think the key is when you say the remaining tasks are more tedious than glamorous. Yep life is like that but many developers don't want to work on tedious. None the less as the lead, it is your reponsibility to determine what tasks need to be done and assign them to people to do. Same as with the more interesting tasks, maybe even more important (someone will almost always step up to do the interesting stuff, not so much with the tedium).
So assign your tasks, give them their deadlines and follow-up on the progress they are making. If you have any of the more interesting tasks left, don't let anyone have one of those to do until he or she has completed his share of the tedium. In fact dangle the interesting tasks left as a reward for getting the tedium done faster or doing the most of it.
If you don't have any more interesting tasks left, thn maybe you can generate some competition to get the rest of the stuff done.
It's ok to be slack for a few days after a major push, but if it lasts more than a week, I think you need to get the team together and talk about what needs to done to fix the slacking.
Do something, other than work, as a team. Go to lunch, happy hour, laser tag, anything you can do as a group that is not work. A short break from stress can be a huge relief, and hopefully can reenergize your team for the final push.
I also strongly believe in "slackweek". If the deadline for the entire project isn't too close: just let everyone do what they want for a period of time. Could be write some tests here, align some stuff in the gui, read up on the latest in bla, whatever. Up to you if it has to be work on that specific project or just something useful overall.
THEN, you have a big "launch" meeting where you talk vision and goals for the remaining third - big picture stuff, and get everyone aligned again. I'm assuming the stuff left is really needed to give the customer a complete product so that it can be motivated for.
Good luck!
Add an easter egg! It doesn't improve the core project, but it helps give developers a sense of ownership.
Also, it can be helpful to set aside time for "pet peeve" cleanup. This gives developers a chance to fix nagging issues that are important to them. This helps improve the project, and at the same time allows the developer to make progress with something that is important to them. It helps keep the excitement level up.
Are there clear deadlines/milestones coming up soon? That would be something to consider as having a target date can help provide some focus.
The momentum being lost, does it tie back to people just being burned out, not as motivated as they were before or the work becoming much different, e.g. working out specifics on vague requirements rather than the cool parts that are done now?
One of the things Agile gets you is a finer focus on where you stand, what you've done, and what's left to do, within the next few weeks. There are concepts of "backlog" (what has to get done) and "velocity" (how fast are things getting done). Since each iteration is typically about a month, it's very clear to see when the team is not working at the projected/required rate, or working too hard. You might be able to borrow some concepts from Scrum for these purposes.
A more straightforward solution is to remind them that if they keep working at a reasonable pace, there's no end-of-milestone crunch time that makes everyone's life hell.

How to convey bad news to clients? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
How to convey a bad news to the client?
When something has gone wrong the client needs to know three things:
precisely what is wrong
what the impact is on them
what you are going to do about it
If you are not completely honest and transparent you will get found out later and will compound the trouble.
If your relationship with them is good then you probably will survive - presuming this is not completely catastrophic - but you will have to provide a decent remedy.
If your relationship is bad, then prepare yourself for them to start playing hard-ball with you on the terms of your contract.
HTH
Addendum: A good comment below about telling them as soon as possible, which I am happy to surface in this answer as requested. It reminds me of a saying "the sooner and in more detail the bad news is known, the better for everyone". As in life, so in project management.
With an emphasis on the solutions you propose to address the bad news.
We will not be able to have a moon
controlling functionality in our
system (due to ...) but we can and
will deliver the weather changing
module which is almost just as good
for your world domination plans.
Be honest and try to offer effective and realistic solutions instead of things that'll end up being more bad news.
Managing your clients/bosses expectations is a great way to avoid this.
In an engineering discipline, the old adage remains true:
Under promise. Over deliver.
If you've already got the bad news, well:
be honest and upfront about it.
give them options about how they want you to solve it; be detailed about cost estimates.
don't make any further promises "to make up for it". If some of your proposed solutions offer advantages down the line, tell them; but don't say that you'll add a feature at the same time as fixing the problem.
"Give the bad news all at once, and the good news little by little. -- Machiavelli" :)
Seriously.. investigate damage control or remedial measures before hand. Set them up in place to make sure it doesn't happen again. Fall back to a contigency plan if needed and you have one ..
Be objective, sincere, apologetic and don't play the blame game.
Be truthful, since nothing is more distracting than lies.
post a tongue-in-cheek apology, preferably starting with Simpsons artwork
What type of bad news?
People in general like to break bad news by stating that the corrections / new timelines will be in place much earlier than we truely can accomplish. Be honest up front and dont give false hope. One instance of bad news is enough... no need to create new promises that you cant keep in the future.
Bottom Line: be honest to your client and yourself to control expectation management.
Here's a link to a short Harvard Business Review podcast entitled: Speaking Well in Tough Moments
In the podcast, they broach different scenarios in which you have to have difficult conversations.
What I usually do is:
Good news
Bad news
Good news
And, for how you execute Bad news, the already mentioned answers can suffice. So, you should have 2 good news in-hand everytime OR you break one into two :)
First, bad news should ideally be delivered as soon as possible, even more so if there might be some sort of financial impact. Also, when you deliver the bad news you should make sure you address all of the concerns as quickly as possible, namely:
What went wrong.
How they are being impacted.
How long a fix will take.
What is being done to make sure it doesn't happen again.
How you deliver the bad news is a big subjective, but the rule of thumb seems to be that you should deliver it in person (e.g. phone call). Also, even if you don't know what is going on yet, you should at least let people know that you are aware of an issue and that you are working on it.
In addition to being honest and straight-forward about it, equally important is how you convey the news. A simple statement of "you are doomed" may be honest but improper. It is important that the customer be told all the due deligence been done by you, what (if any) are the options or workarounds available to him and propose to get together with him to find a way forward. You are not misguiding the customer but you are trying to provide him some avenues to think and the realization that you are not just throwing it all in his plate.

Techniques to follow when you are stuck programming [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
When I am stuck with a problem:
I search Google for code snippets.
I look at isolating the problem, so that I can better explain it to others in order to get answers.
What search techniques do you use to find the solution to your problem?
I started asking questions in Stack Overflow.
What other techniques or methods do you follow, to fix the problem more quickly?
Go and do something else. No, really. I've found that putting the problem away in the back of my mind helps. I can't count the number of times I thought of a great solution to something I've been working on when I was working on something else, or watching TV, or eating. It seems your brain is still working on the problem in the background.
If that fails to solve your problem, try talking to someone. You'd be surprised how often others can give solutions to your problem that are so simple you'd facepalm.
Well there's:
Google
Google
Google
Stack Overflow
Google
Google
Maybe a book if I have one.
Seriously, I started (hobby) programming in the 1980s and even into the mid 90s you had to know things and have a technical library. Then Google came along and it's easier to Google something than it is to look up (bookmarked!) API documentation (Google "java stringbuilder" will get me there faster than navigating will) let alone an actual book (electronic or paper).
Most problems you're trying to solve have been solved before. Many times.
The rest of debugging comes down to decomposition, possibly unit testing (which is related to decomposition) and verifying your assumptions.
By "decomposition", I mean that your solution is structured in such a way that small pieces can be individually tested and readily understood. If you have a 7000 line method you're (probably) doing something wrong.
Understanding what assumptions you've made is key too so you can verify them. For example, when I started with PHP I wrote a piece of code like this:
$fields = $_SESSION["fields"]; // $fields is an associative array
$fields["blah"] = "foo";
and I was scratching my head trying to figure out why it didn't work (the array wasn't being updated next time I queried $_SESSION). I came from a Java background where you might do this:
Map fields = (Map)httpSession.get("fields");
fields.put("blah", "foo");
and that would most definitely work. PHP however copies the array. A working solution is to use references:
$fields =& $_SESSION["fields"]; // $fields is an associative array
$fields["blah"] = "foo";
or simply:
$_SESSION["fields"]["blah"] = "foo";
The last thing I'll say about debugging and writing robust code in general is to understand the boundaries of your solution. By this I mean if you're implementing a linked list then the boundary conditions will revolve around when the list is empty.
Explain the problem to a colleague, or write it down to describe it. That will makes you think a different way, from a different perspective. In order to be more accurate, and to describe the context of the problem, you'll step back, get a higher level view of the problem, you may find out think you overlooked something that is actually important.
Sometimes, you even find the explanation before ending your description.
My best friend for many years has been to jump on my bike and go home. Just getting away from the keyboard has solved many problems over the years for me.
If the problem lasts to the end of the day, I try and consciously lock the problem away for solving before I go to sleep.
I realise this sounds a bit out there, but it has been very common in my experience that I'll wake up with at least an alternate approach to the problem, if not the full-on solution. The idea is not to stress about it - but actively decide to solve it over night. That way you can go to sleep without worry.
I think eating well, regular exercise and good sleep are huge contributors to the problem-solving process.
Usually I'll try nut out the problem for a few hours or so, trying different things writing it on paper, making diagrams. If none of that works I'll usually work through the following options.
Put a sticky note on my monitor and keep going with something else
Glance at the note through out the next few hours to keep the problem in the back of my mind
Google for similar problems and the methods used
Consult a co-worker or a friend
Ask on a forum such as stackoverflow
Give up and design the problem away or design a way around the problem so it can be dealt with some other time and stick a TODO note at the site of said workaround
Don't forget Google Code Search
It's often best to clear your head by doing something other than programming for a little while. See this answer for an example - I did it while struggling with a particularly thorny bug, and when I came back to the problem I solved it in about a minute.
Usually I try to solve it until I go to sleep.. Sometimes I write on paper what the code is doing and then I divide it in pieces; I try to know how the variables of the program change when it's running.
Try solving a much smaller version of the problem first and see how you get on with that.
Once you've done that the bigger problem won't look so scary.
Ask yourself: is solving this particular tricky problem really important to what you doing?
For the purposes of your application (or whatever the big picture is) is there a similar but easier problem that you could address to accomplish broadly the same thing.
Normally, I would get pen and paper and try to work out the details of the problem there. If that doesn't help, Google. Failing that, I'd do something else for a while, or ask online. Worked for me so far.
The fact you are stuck might be a 'code-smell'. Suggesting that their is something wrong with the design or approach somewhere else. Try to put your finger on what's causing this and fix this instead.
When you come back to your problem it might no longer exist.
One more time, browse thru what I think might be relevant, then take nap.
There are two other answers which mention sleeping or napping, but this deserves more emphasis. It is now known that there's SERIOUS machinery in there which goes to work when you sleep. Google (( CBS SCIENCE SLEEP )) will get you to a great free video.
If I can't figure out how to solve the real problem, I try to consider a simplified version of the problem. To take a simple example: I recently had the problem of finding a set of shipping routes to get an item from point A to point B, when there is not necessarily a direct route from A to B, but there might be an A to C and then C to B, or A to C, C to D, and then D to B. (I'm sure the airlines and railroads do this all the time.) That was fairly complex, so I tried looking first at the simple case: a direct A to B. That was easy. Then consider how I'd handle it with one stop along the way. Then consider two stops. At that point I was able to see the pattern to a solution.
Solutions to a simplified version of the problem may end up being a part of the bigger solution, with some additional complexity wrapped around them. But even if not, the exercise of solving the easier problem often gives you ideas on how to solve the real problem.
The main techniques I use (should be followed in order so that you can reuse what you have done in previous steps to be more efficient):
Define your issue: Try to clearly define what's the problem, and what's expected. See 2 to help you.
Collect data about the bug: Log everything: your attempts, the expected result, the observed result. This will avoid the need to redo several times the same tests (because your mind cannot memorize it all), and probably help you see the bigger picture.
Reduce your problem. This is true in general for any abstract modelling of natural phenomenons, but it's even more true of programming, because programs are very complex entities. You should try to reduce your code to a minimal program that reproduces your issue. Automated tools exist.
Talk to someone: several anecdotes affirm than about 2/3 of the bugs are resolved just by talking about it. See the Helpful Teddy Bear anecdote. If you have previously reduced your program to a minimal program, and have a clear definition of your issue, both will be useful to your explanation.
Reach for collaborative help: search on Google and on StackOverflow, and post if you can't find anything that answers your problem (but first see 1, you must have a clear definition of your problem).
As you can see, I put the collaborative help as the last step, because you should only ask for help after you have clearly defined your issue and tried to reduce the problem and fix it by yourself. If you reach for collaborative help before having tried the previous steps, you will either end up with a poor help or figure it out by yourself as soon as you have posted.
Also you can be interested in the Coursera Software Debugging course, which also describes several automated debugging methods.
Go to the toilet.
You move, so your brain gets oxygen.
You relax, so you focus on other things.
Peeing for innovation! :)

How do you get through the inevitable motivational "slump" near the end of projects? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
When working on a project, after the interesting parts are coded, my motivation is severely diminished. What do you do to get over this problem?
Don't leave all the "boring" bits to the end - make sure that each component works, with regression tests and documentation, as early as possible in the project.
That said, the last few weeks are still going to involve chasing down the really elusive bugs, dealing with last-second requirements changes, finalising the documentation, and generally getting the damn thing out of the door. My approach is just to suck it up: put your head down and know that the sooner it's done, the sooner you can start on all the lower-priority, more interesting things that have been queued behind the current release.
You can't completely avoid last-minute requirements/docs changes other than by arranging for your customers to all be on holiday just before release. Or get yourself in a dominating position like Apple and Google, so that customers have no prior knowledge of releases.
You "should" chase elusive bugs (by which I mean the ones so hard to reproduce that you don't have a consistent test case) early, because you cannot estimate how long they will take to fix. But in practice some proportion of them will become less elusive as the project goes on, or turn out to be side-effects of another known issue, so you save time on average by giving them a limited chance to do so. The downside of this is that towards the end there will be a few left. If there are more than about two, though, you've done it wrong.
Taking a short "break" after a major deadline to do whatever you find most fun is a good way to avoid burn-out in the long run. Even if you end up throwing most of it away because you skipped some difficult planning, you'll have made yourself more productive.
Use test-driven development. A failing test is always a strong motivation.
Let some testers loose on it. Nothing is more motivating than seeing people use your interesting bits and finding obvious improvements.
Repeat to myself: My code doesn't exist until it is checked in.
Or if you're not using version control, 'until it is published' or 'until it is launched.'
You could also use fear and say that if YOU don't finish and launch it, someone else will.
Usually I try to tell myself that getting things to work in the real world is just as interesting, because there is where your code will get credits or will be improved by discovered bugs and feature requests.
Don't do all the interesting parts first.
I motivate myself to do the boring code by always leaving a decent bit until last and being strict about completing the boring section first.
"if YOU don't finish and launch it, someone else will."
Told myself that one before. Sometimes however its good to take a break for a couple hours then come back to it. Then you are not as burned out on it as you were.
I try to push the concept of bug days / evenings. Set a target of bugs/issues to address and when you hit that number everyone gets to go out for (paid for!) pizza/beers. Keeps the morale of the team up and acts as a focus in an otherwise boring period.
Also you can add into this concept prizes/cudos for the best piece of refactoring or performance improvement etc
I agree it is tough. The only thing that keeps me going is to keep in mind the feeling I would have after seeing it complete / shipped / in the hands of customers.
My motivation is just to Get It Done. Like onebyone said, you just have to hunker down and do it. It's all a matter of priorities. The quicker the priorities are out of the way, the sooner you can get back to the interesting stuff.
Try to see if you can take a very short break for a day or two and come back more refreshed.
Don't leave boring bits to the end
Test it yourself
Ensure that your diet/exercise/sleep/etc level don't get lower
Tell the others that you are feeling a bit down, can you swap areas of work for a day?
In general, when you've done 90% of the work, it's almost ended, you just have to do the last 90% :-)
Always think about that, and you'll see that's a long way until it's working.
I'm happy doing the creative fun bits of programming.
But after that I think about making the user happy.

Resources