Wednesday, November 23, 2011
Exercise 26: Congratulations, Take A Test!: Learn Ruby the Hard Way: Practicum
I have mixed emotions about posting these entries. In part, I feel like I might be "cheating" others by giving a blow by blow of all this; they may just use my answers and say "Oh, cool, that's how that works", and miss the whole point of going through all of these steps and actually learning the material. Still, my point with the Practicum series is to show the techniques, critique the exercises, and give my own take on these materials as though I were teaching them to someone else. Thus, I guess I will need to leave it up to the reader as to how they want to work with this, and if they want to actually do things "The Hard Way" or cheat and do what they think is an "easy" approach to learning this stuff. "Thems will be that thems will be" (or something like that). Also, I try my best to put the code and my changes into pictures, not into text that can be copied and pasted, so I guess if they want my answer, they will have to type it out anyway :).
So for this section, we are asked to work through a quiz. the quiz is to fix someone else's code and make it work. It's common to deal with other programmers' code. It's also common to deal with their insularity and their belief that their code is "just fine".
Exercises 24 and 25 have been cobbled together and errors have been introduced. Our job is to find the errors, fix the mistakes, and get the program to run correctly... without looking at the previous exercises to do it.
The "broken" file is here.
My "fixes" are here.
What this shows us is that many of the errors we might put into our own code may seem blindingly obvious, but often they are subtle little misses, typos, or otherwise small things that can be infuriatingly difficult to find. There's still one area of the test I'm not sure I did right, and that has to do with the output of the "sorted sentence". I get that it's doing what it's supposed to do, but the repeated word and out of order with the pop is what has me scratching my head at the moment. If anyone else can tell me what I'm doing that's totally dumb, hey, I'll welcome the comments :).