Understanding these stages and using them will make your code much better. Never stop with the prototype, it's experimental. Never stop with the second (simple) solution, you wrote it while you didn't understand the problem yet.
Control-R(interactive backwards search). Learn it, love it. Press it and start typing; the last command you typed with that string will show up. Hit it again, and the one before will show up. For example, imagine a SQL shell with Readline support (yes, there are many):
Control-R
sel
select count(*) from users;(the last command you typed with sel in it).
Control-R
select name,address from users;(the select you ran before the one above)
This works at the shell prompt, too. Learn this and you'll fly through any interactions with Readline-enabled command-line applications.