DEBUGGING TIP! Read Me... Trust me.

Listen up, kids... pull up a chair.

I'm not the worlds best LUA programmer, but I have been doing software development and releases for a little while. I don't know everything, but here are some golden words that will save you from hours of pulling your hair out. (yes, I'm bald.. okay, I'm not but for the purpose of driving this point home, I'll pretend to be for dramatic purposes.)

OK, Corona doesn't have a state of the art IDE Debugger. It does have a terminal based debugger which can be a little "tedious" to use. But it is there. If you get good at it, nothing beats a good programmer who knows how to debug. (a great programmer doesn't write buggy code in the first place but... show me a programmer, I'll show you someone that writes bugs. Remember: All code has bugs; the good code simply hides them very well.)

HOWEVER, if you want to know a secret, your print( ) statement is your best friend. Well, maybe not your best friend... but he's a good buddy. Always there when you need him, ready to tattle-tale like my 3 yr old boy on his siblings. Use print( ). Trust me. If you have something weird going on and you cannot - to save your life! - figure out what's going on, throw in a bunch of print( ) statements and display what variables are doing. Give yourself little print("I'm in function foo") comments. Are EventListeners triggering differently than you expect; print( ) will tell you exactly what's going on. They study your terminal window! LOOK AT IT! LOOOOOK!!! :-) Once you stare at code for about 60 min., things go blurry and you start to see what you want to see, not what's really happening. It happens to EVERY programmer! Especially after 16 hours of coding straight. Funny bunny rabbits with sharp teeth start appearing above your monitor and you giggle to yourself and run out of your office chasing leprechauns.
NOTE: will clear your terminal window for a clean slate!

Now, lets say you have a bunch of print( ) statements throwing information your way. Your terminal window is chucking data at your eyes faster than the shuttle entering LEO. (17,500 mph by the way)

You ask, "Hey smarty pants, I got your thtupid print( ) statements but there's too much data... my loops are causing those puppies to fill up my terminal and the scroll bar is supersonic. What a big help THAT was!"

OK, I would say this... your next best friend after print( ) statements would be... wait for it... ScreenFlow. For years, in the videogame industry we would use VCRs. Even long after VHS was a dead dinosaur, you'd see software companies with testers putting in those VHS tapes every morning to record everything that was going on while they tested all day long. (Those tapes would wear out pretty quickly and the recordings would look like some fuzzy, color-faded, hodge-podge of information... but it would always help a programmer. You know, those guys that are quick to blame the hardware first, cause they don't write buggy code... until you show them the tape.) More advanced companies transitioned to digital recorders of some kind eventually.

AND that's why I'm telling you to run... don't walk... and go buy/download ScreenFlow. If you have no money, snag the TRIAL version - it has a watermark but is EXTREMELY USEFUL still. This video capture software on your Mac is A W E S O M E! Video capture catches EVERYTHING. And you can pause, free-frame, study, rewind, study some more... figure out what oddity... what little visual tidbit... what gold nugget of information is going to make Sherlock Programmer Holmes sit straight the ^@#%$ up and say, "Watson, I got it!" Especially if you have some rare bug that's just driving you BAZONKERS and you end up writing long Forum posts... like me... now.

That's my free $0.02 worth of advice for people new to this "game". Police use videotape in their patrol cars, court cases are won & lost by video, airlines have black boxes in the planes for a reason (although they're not really black..?), and PROGRAMMERS kill BUGS with video. That's how we do.

OK, best of luck! Have fun.

DISCLAIMER: This advertisement for ScreenFlow is done without compensation; it's done with pure love and appreciation of this wonderful tool. Now, where did I put that rogaine...?

thanks for the tip

That's really nice and I agree at least from my part, because when my code do something "odd" I fill functions with print()s and check what is happening. Or in some cases I sleep over night and everything is (hopefully) clear again.

@seppanen.sami: I agree, whenever you get stuck - I suggest two things:

1) Step away from the computer and take a break. Stretch your legs, get a drink, do jumping jacks... something!
2) My experience has shown me that whenever you want to debug something really hard, tell a friend what your code is doing... during your explanation, 95% of the time you'll uncover the problem by listening to yourself explain what's going on. I know that sounds silly, but I've had that work SO many times for me.

I agree about verbalizing your problem to another person. It seems like verbalizing it causes another part of your brain to analyze the situation.

views:1664 update:2011/10/11 15:24:38
corona forums © 2003-2011