github twitter linkedin hackernews goodreads angellist keybase email pgp rss

Try, Then Add

It is very important to write your computer program piece by piece. I am writing this post as I have seen many people sit down and type in a whole program based on their ‘knowledge’ (=assumptions) and then ask “hey, can you tell me whats wrong?” when the program does mysterious things. At this point, if time is also against us (as is usually the case), little can be done.

Try it bit by bit in isolation and see for yourself that it works. Don’t assume anything. Test everything. THEN incorporate it into your code.

A big program will have so many moving parts. If it is also doing mysterious things, there will definitely be lots of flying monkeys and clowns on crack. If you try to make sense of such a freak show, you will experience a pain that could have easily been avoided.

If you have already clumped together all the square pegs, round holes and chewing gum, the best bet would be to take your code apart, try (copy-paste) it piece by piece and put it together into a new program.

Personally, though I’ve inherited some hairballs at my day job, I’ve had the good fortune of at least being able (=time,budget) to rewrite them altogether.

Good programming languages make ‘trial & error’ approach painless. I love playing in Python and Lisp primarily because they make this experimentation easier and natural. However, “Try, Then Add” is a good habit while programming in any language - even if it is in COBOL. Doing it in COBOL will be a pain in the neck, of course - but I double dare you to not do it.

Imagine my joy in finding something that makes “Try, Then Add” easier for JavaScript! [Learning JS from the Command Line]

Further Reading: What is REPL? Programming Bottom Up

3 comments
Jagan wrote on Jul 24, 2007:
not related to the post -
dei long time da. can you mail me your number ..i need to talk to u machi ...
Mike wrote on Jul 25, 2007:
"A big program will have so many moving parts. If it is also doing mysterious things, there will definitely be lots of flying monkeys and clowns on crack. If you try to make sense of such a freak show, you will experience a pain that could have easily been avoided."

This best describes trying to figure out what a woman is thinking when on paper everything should technically work which isn't the case.
protonfish wrote on Jul 26, 2007:
Another nice command-line utility is the JavaScript Shell 1.4