Y! has an interesting article in which a space.com astromoner explains how to detect planets by their phases (like phases from the moon). Its called the 'fade-in fade-out' technique. Calculations are in the article, but its been "dummed down" into laymans terms. Still an interesting read.
Do not underestimate the value of print statements for debugging.