Like my experience in Japanese, programming languages benefit from practice. My last problem statement was to implement a text editor using a linked list. Welcome to practice with pointers.
The problem statement included this information:
If the letter I is entered with a number n following it, display a prompt along with the line number n, after user types a line of text, then insert the text at line n, and the original text at line n becomes line n+1. If n is larger than the total number of the current lines displayed from the editor, then you need insert a few lines of empty text in order to insert the user input text at line n.
Now, don’t ask me how I managed to flub a simple reading assignment, but I took this to mean that I needed to implement two different style insert functions where the base case was that someone just typed a line and pressed enter and the text should be inserted at the end. The second case was the case listed above: the user entered I and a line number and the text was inserted at an appropriate spot in the code. It is here where more practice would have helped.
I implemented this by prompting the user to select their command, which then initiated the subroutine (so press I and enter and get prompted for a line number). It took until a lab session about 2 weeks ago when I realized that I could have just tested the string and not forced my users to be quite so explicit. It means more error handling for me possibly, but a better experience for the user.
So, I’ll be rewriting the code sometime this week to change how I’m implementing my solution. Anyone else have an aha moment that results in rewriting the entire program?
Should I do the rewrite before or after I do the test cases?