Focusing on wrong lines!

Focusing on wrong lines and keep focusing and then focus some more for NOTHING!

I was trying to learn how to work with bits. Of course code compiled but it didn't do what i intended. I did everything about bits perfectly fine, the problem was
instead of :
void setBitToOne(uint32_t& bitStack, unsigned int whichBit);
i wrote this by mistake
void setBitToOne(uint32_t bitStack, unsigned int whichBit);

You see, i forgot referencing the number i intended to change. But for hours(!!!), i searched my mistake at lines contains bits and i only searched at those lines.

I wonder how can i overcome this problem. Does that happen to you? How one avoids this mistake?
But for hours(!!!) [snip] I wonder how can i overcome this problem.


Use a debugger.

Seriously. This is one of the first things people should learn how to do is use a debugger.

If code is not doing what you expect, you use a debugger to walk though each line of code to see what it's actually doing.

This problem would have been solved in 5 minutes or less with a debugger.
Use a debugger


I use that! Problem is i blindly dont check anywhere else.

Maybe because i am under too much stress and i dont have much self-confidence. But i always doubt myself, like "certainly i got something wrong"

EDIT: The problem i am talking about is being too focused on one thing. How can i overcome this problem?
Last edited on
I found the reason.

Not something related to programming though.

I was telling this problem that i experienced to my friends and one of them(a psychologist) told me the reason.

It is called "Hidden Stress", the person who experiences this is unable to realize actually he is under stress and only able to see its outcomes after it becomes too much, like i was experiencing. Resulting in disorder even for basic daily stuffs.

He mentioned a few cases. Like, people who travels a lot tends to forget which country or city they are or some people experiencing ulcer or gastritis or some people doing something than forgetting they did it over and over again because of hidden stress.

If anyone experiences same problem like me, go see a psychologist or a doctor.
It is called "Hidden Stress", the person who experiences this is unable to realize actually he is under stress and only able to see its outcomes after it becomes too much, like i was experiencing. Resulting in disorder even for basic daily stuffs.


To be honest I don't see how "The problem i am talking about is being too focused on one thing. How can i overcome this problem?" turned into "Hidden Stress" and am really doubting your friends assessment of the problem you are having. Though then again I am not a Psychologist so take my opinion with a large gain of salt.

Though for your specific example and how to overcome doing this again I would definitely agree with Disch about using a debugger to find the problem.

Also worth noting is trying to keep your code as modular as possible. This will help greatly with debugging the code when errors happen, since when something goes wrong with X functionality you know exactly where to start debugging because most if not all of X's functionality is all grouped together nicely.

Another good habit to get into is testing frequently. Implement some new functionality? Go create a test for that functionality right away to make sure it is working right. Try to do this as often as possible. It is up to you to find your preference, I like to do it after every new function I write, or any group of code that needs to preform a certain task. This might seem a bit tedious at first but in the long run it really helps eliminate a lot of the errors right when they are introduced instead of finding out about them days, weeks or even months down the road (Or even worse not finding them at all). I also find it more fun to program this way since I can see the results of my work much sooner.

If you find you like this kind of workflow I would recommend doing some research into "Test Driven Development" and some unit testing frameworks. It is a different take on development but definitely does help with eliminating errors more effectively.

And lastly I wouldn't get to hung up about this problem, I am sure all of us have done this more times then we can count. It just is a matter of experience in my opinion, after you keep programming for awhile you will run into the same types of errors over and over again, which will allow you better judgement from past experiences on where to look to fix it.
Last edited on
closed account (2LzbRXSz)
I've studied some psychology, but I'm not a psychologist.

That being said, don't label yourself and your problems.

This isn't some sort of mental disorder, it's pretty much being narrow minded, and not identifying the symptoms of the error. It happens. Everyone makes minor mistakes without realizing until countless Google Searches! It's really not even being narrow minded, it can depend on experience too, and knowing what to look for (example: if you've had this problem before, you would know to test for it).

If you find yourself really stumped, even after going through every possibility in your head, ask for help from a fellow programmer:)

Z e r e o wrote:
Another good habit to get into is testing frequently.

100% agree.
Don't forget to save frequently too, in case your IDE/Compiler doesn't auto save.
Last edited on
@ OP: The term for what you are trying to describe here is essentially "cognitive bias". You don't get rid of it and in fact for most people it's likely to get worse as you get older. It something you have to be consciously aware of so that you can focus on objective facts about a problem instead of the subjective ones. In the case of programming you do this with a Debugger as Disch suggested. Although I'm not sure how you learn to use a debugger other then forcing yourself to use it. The texts and tutorials that I find accompanying them are usually next to useless.
I waited one day just to give a long thought rational answer.

Thank you for all the tips first of all. I am going to create a list on what to do if something goes wrong when programming.

Secondly, my friend told me about hidden stress when i told him i am having "itching on my hands, ulcer, forgetting some of the obvious daily stuff which all them were happening lately" and he also noted that stress is not the cause of illnesses rather is a trigger. I didn't tell him especially this programming one. So my mistake is i subconciously connected every bad thing that happened lately with stress. So thinking that this programming mistake is because of stress was my doing not my friend. Sorry for that.

@Computergeek01 i believe you are right about cognitive bias. I am going to try to be more aware of it in my life.

Thanks for the help. I will try to have a fresh view to things at my life and programming.

By the way i use qt creator - gcc - gdb trio on linux at windows i use VS2013.
In some cases, a debugger won't catch everything.

For instance, memory corruption is a complete bitch to use a debugger for and makes you itch your head enough to lose hair. Picture stepping through a debugger when a variable you're monitoring suddenly changes value while an assignment for that variable is nowhere in sight and even disassembly doesn't show anything concerning the related register currently holding that value.

Sometimes, it's a design issue. In very large programs, it's not always viable with the allotted time you have to work on the problem to step through the entire program up to that point of issue. Sometimes, it's not possible at all. For instance, try debugging OpenGL memory allocation issues. One of the worst things about OpenGL is they provide no standard method of tracking memory allocated by OpenGL both within GPU and within process context. You're stuck guessing at what could possibly be the issue. This is probably one of those points where people throw their hands up and say, "OpenGL sucks" as well.
I learned some situations where debugger may not be use from Scott Meyers' book "Effective Modern C++" and by the way i still am reading it.

But hearing such a thing about openGL makes me fear, especially for a person who is planning to start learning it in 1-2 months time.
Last edited on
Well then OpenGL is nothing like Vulkan, memory handling is usually taken care of by the drivers.
OpenGL should be made as easy as:
Create objects
Send data
Call draw functions
-Delete objects on shutdown

If you edit your buffer data often, then I can say you need to keep an eye out (especially your buffered data SIZE).
Otherwise you don't need to worry.

Do not fear, and use modern OpenGL, my friend.
It's not bad. When it's bad is when you have a AAA engine that tacks on OpenGL as a third-party that is sluggish. Trying to figure out the bottlenecks and any memory issues associated with those bottlenecks is stupid hard.
I said it made me fear, but it doesn't make me step back. I will indeed learn openGL. If others have done it, i can do it.
I don't see how your programming issue is related to psychological effects, we all get little bugs that might take a while to figure out. In fact sometimes VS just breaks and stops debugging the code properly... And I have to clear the program, delete the contents of the bin directory for that project, reopen the solution, rebuild and debug again.

But to check for reference mistakes you need to look at your value before it goes into the function, follow the function and firstly make sure the function is working correctly, then when the function ends if your variables haven't changed then they can't have been passed by reference.
I very rarely spot reverence errors in my own code but when something doesn't work as it should I follow the variables through the program.
Topic archived. No new replies allowed.