farzad.shbfn's blog

By farzad.shbfn, 9 years ago, In English

Hello everyone,

I was wondering what are the best ways to debug a code? I'm training for world-finals, sometimes simple printing values takes a lot of time and even worse, I end up changing the code and the final output gets messed up so it gets even more time to take it back to how it was. I mostly code in C++, and use Eclipse IDE and Geany editor.

any suggestions?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it +8 Vote: I do not like it

gdb is cool :P

»
9 years ago, # |
  Vote: I like it +28 Vote: I do not like it

Computer time is extremely valuable in the ICPC, and you don't want to use it for debugging. If you can't find the mistake in less than 5 minutes of printing values, print the code on paper and start reading it line by line very attentively while someone uses the computer for something else.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    You are absolutely right, that's how we used to code last year at regionals, but this year i changed my team, they're great problem solvers and also good coders, but they never coded with this kind of pressure and speed, so technically i ended up being the only coder in the team. and there is not enough time for them to train and increase their abilities in coding.

    considering these conditions, what do you suggest? 1. i debug the code myself? (for 5 mins in terminal) 2. print the code, and read it myself? (or give it to them for reading — which it takes more time, because i need to explain them the code (and sometimes it's inevitable because i CAN NOT find the bug and need for their vision) 3. or if it didn't worked out in less than 10-15 minutes, skip it.

    we are actually practicing virtual contests of past world-finals, we tired them all, but still, we are not efficient.

    I'd really appreciate it.