Week 2_HW01

Week 2 : 

Prompt: Think about what was hard, what went well, and how those lessons will influence your work in the future weeks

This week, the main assignment to work on was Homework 1, Markov. I had a smooth time reading through the assignment prompt and completing each function. I recognized that this was functional programming as some functions utilize other functions to run properly, so I made sure to test the base functions so that my larger ones didn't have any structural problems. Things were going well, but the addLine tests in "markovTest.java" were the only ones not passing, but the logic seemed fine to me initially, until I realized that my getSentence function had an infinite loop after using some print statements to debug:

while(!endsWithPunctuation(currentWord)){ /// / hello      .
newSentence += currentWord + " ";
currentWord = randomWord(BEGINS_SENTENCE);
}
newSentence += currentWord;
return newSentence;

I was setting my currentWord to BEGINS_SENTENCE ("_ _$"). Whereas the correct syntax should be: currentWord = randomWord(currentWord)

 "__$" gives entry into the hashMap and then current word lets us traverse the rest of the keys in the map to build sentences. This bug was eating at me for so long, that I was going to go to office hours to ask what was wrong because I was letting the infinite loop run, and it was giving me some weird file error that I didn't know how to diagnose when it finished running.

Lesson: I learned that I should do more thorough incremental testing, instead of trusting my intuition of the code being correct. Also, I could've committed to git more often to create links between changes, instead of one large push of code.



Comments

Popular Posts