- Relax, don't think about it, try next day: This is really simple and is risky, although has worked for me a lot of times. If you are coding late at night thinking that if I complete this today it will be good, but you seem to be just stuck in somewhere; Just leave it right there, and come back in the morning and start the work from where you left, I bet it will work instantly in the morning. I can't really say what's the reason behind this but probably it's because now the job is for a fresh and relieved mind.
- Talk with a colleague about it: Even if you are doing something which is far from anything which your friends are doing, their minute suggestions or corrections can reveal massive problems in your code. You can show the part of your code (even if it contains 10 header files, and 2000 lines code in each) to a friend assuring him that rest is all OK. The magic here is you may be ignoring something very small since you are into something big, but that friend of yours will think about it from scratch and can reveal silly mistakes.
- Talk with your professor: This also sounds odd because, you know that your prof is not coding with you and thus how can he solve your 'seg fault' problem? Also, isn't it lame to go to the prof with debugging problems.. won't he think that I don't even know this? The truth here is your prof is much much more experienced than you (even if they coded in fortran in their age and you are into c++) and when you talk with him/her about your stuck-in-code problem, you will notice that he will always have something to say about it. The suggestions given, even if are vague, when you work upon them, can really make you move forward. Their massive experience with various issues keeps them cool with whatever problem you have. And seriously, stop thinking about what your prof thinks about you, its totally unnecessary.
- Recode: Well last but not least, this is only recommended if you are writing something small. You will notice that the code you have written may be only 200-300 lines but probably you have spent 1 week debugging it. Just move it somewhere else and code those 200-300 bastard lines again. Your extra care while writing it this time will make sure that the problem has not even taken birth. When the new code works, delete the old code and also you can take a printout of the old code and burn it singing some traditional hymn, you will feel good.
Friday, November 30, 2007
What to do when stuck between lines?
This happens quite a lot of times when you get stuck in your code and no matter what you do, the stupid code will behave stubbornly. Not just coding, this includes other technical problems we face everyday as well, related to our projects or our personal g33kin. Somethings which have always worked for me to come out and move forward are these:
Subscribe to:
Post Comments (Atom)
nice one dude ! I usually follow 1/2/4 ... but never tried the 3rd one :D
ReplyDeletethe 'leaving at night and retying in morning' has always worked for me...
ReplyDeletetried and tested :)
'1' does the trick mostly .. not just for coding but also for algo development ... guess its got to do with the subconscious mind acting on it ;)
ReplyDeleteand how many times have u burnt ur code?? :P
apart from this, I also name the file as 'god.c' , 'god.py' , 'have_mercy_god.py' etc....seems to work for me :)
ReplyDelete@shadowfax :P
ReplyDelete@mythalz and Kunal: Good 2 hear that, i used to think i am the only one.
@tipo, omg that was the funniest thing i have heard after a long time, LOL!!!
I use '4' all the time while compiling apps from source. Sometime in frustration I even end up doing 'rm -rf *' in the wrong directory :P I like python the most and executing the code on interpreter helps a lot. I know c/c++ little less than python and avoid coding in them.
ReplyDeleteNice post dude ...
ReplyDelete1 and 2 rocks, atleast between us ...
and we had a very important 4 with geometry shader :D .......