Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

The problem is that I am not that experienced programmer and I am doing silly mistakes on coding. But the even bigger problem is that I may spend unexpectably much time to find them.

Lets say I comment a piece of code to test something, I forget it and when I want to continue on the normal flow it takes me 10 minutes to remember to un-comment it. Until then, I get strange errors that make me feel "terrified" about a bug I may have introduced.

Is there any advice on that part or is it just experience issues? And will I get level up my experience as soon as possible?

share|improve this question

marked as duplicate by gnat, MichaelT, Jim G., Kilian Foth, GlenH7 Apr 28 '13 at 13:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Depending on what language/environment you're using, you might be able to add a semi-harmless #pragma or #warning line with text of your choice. The code will still work, but you'll get warnings when you compile. Since you always resolve ALL compiler warnings before delivering, you'll be assured of returning to that section. –  Dan Pichelman Apr 27 '13 at 22:01

2 Answers 2

It's largely just par for the course for experience programming, and is one of the key reasons why programmers need quiet space and uninterrupted time to work. Simply put, you need to learn to keep quite a few different things in "working memory" in your mind.

There are aids you can use, though.

  1. Task comments. Any editor or IDE can parse (or has a plugin to do so) comments that start with TODO, FIXME, XXX, and other such notations, providing you with a todo list. Many will also let you customize the keywords to look for, allowing you to create a sort of "filter" for these "I did something to see what would happen" changes. So all you need to do is add a line like // TODO: Commented this to see what would happen. Uncomment when finished. Or whatever your choice of wording. You'll be able to then see them all in a particular pane in your editor.
  2. Leverage Version Control Commit often, and always commit before you experiment. Even better (especially if you're using Git or Mercurial), create a branch for such experimentation. That way, if you muck up what you're doing, you can always roll back to the clean version. Creating a separate branch also allows you to switch tasks without cross-polluting your code bases.
  3. Take good old fashioned notes. If nothing else, just jot down the file name and line number of the code you tweaked. That way, you have a running list of the changes you made for the sole purpose of "what does this do?" that you can reference later, once you figure it out.
share|improve this answer
+1 for mentioning leveraging version control. I just type "git diff" (or use my own alias "gd") to see what I've changed, and there I immediately see that commented block of code and remember to uncomment it. And if you find that you've got some 27 modified files and you cannot find things like this from your diff listing, it's a sign that you are not committing often enough. I usually shudder if I have to commit more than three changed files at once. –  ZeroOne Apr 27 '13 at 21:50
Really hlepful, thanks :) –  py_script Apr 28 '13 at 20:33

Do you have decent working conditions?

If you're working in open space, with a person nearby who constantly talks on the phone, people are walking all around, you receive new e-mails every five minutes and you can't ignore them, because they come from your boss, you're working on a slow PC where the compile time is about two minutes, etc., I'm not surprised that you forget those things, and it's totally not your fault.

The problem comes from the fact that you can't stay concentrated enough. This may be due to poor working conditions (see above), or some other personal issue like a depression, lack of sleep or exhaustion. You have to address directly those issues, not their consequences.

Aside that, remember two rules:

  1. Unit test your code; regression testing will help you to determine what did you break and when,

  2. Commit regularly. If you have frequent commits, you simply roll the solution back to a revision where the specific feature was not broken, and see what you did in the revision which could have broken it.

share|improve this answer
It is totally concentration issues. But how can I fix them? Shauna above gave a good list of hints. Is there anything you could add? :) –  py_script Apr 28 '13 at 20:34
@win_script: Shauna's hints deal with the consequences. As I said, you have to address the root causes, not the consequences. When an African child is sick because he's starving for months, you may give him drugs which will temporary mask the illness, or you can feed him with nutritional food. In your precise case, if the cause is poor working conditions, convince your management to improve them. If the cause is depression, consult a shrink. If the cause is exhaustion, take a weekend at the seashore. –  MainMa Apr 28 '13 at 20:51
If it is lack of concentration? –  py_script Apr 28 '13 at 20:52
@win_script: again, the lack of concentration is the consequence. You don't lack concentration without a reason, like you don't have temperature without an illness. As I mentioned in the second and third paragraph in my answer, the loss of concentration may have multiple causes: either poor working conditions or a bunch of personal issues. –  MainMa Apr 28 '13 at 20:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.