Monday, March 7, 2011

Oh I'll test your case, you rogue

I think test cases were designed specifically to give me a headache. This chatbot program I'm developing is going pretty well. I always take it as a good sign that my Ruby studies are progressing when I get a headache afterwards. Or during. Whatever!

Either way, it feels good to be building something that functions. Even though that functionality is limited. Even though the code for that functionality was handed to me. I'm glad the source code was available to download, because after throwing multiple errors I found out I had an extra | in my source code. And I was missing a parenthesis before that. What a slob!

Here's a question: what's the advantage of writing test code rather than simply running the source code and checking for errors that way? My guess is by writing a test code, Ruby is checking that the underlying logic makes sense and works, but if that's the case, wouldn't simply running the source code do the same thing? Is it faster to run tests? More economical for larger programs?

I get the feeling writing test code doesn't make much sense to me now, but it's something more vital for bigger projects where more things can go horribly awry.

Sunday, March 6, 2011

Building Loud Mouth

So this weekend I've been working through chapter 12 in Beginning Ruby, which is about building a larger program using the techniques learned so far. The program is building a basic chat bot, and so far I've coded functionality for getting information from a user, switching pronouns and returning the original sentence so that it appears the chat bot is asking a question. I also named the chatbot Loud Mouth.

My understanding is this is similar to how a lot of chat bots work, at a very basic level.

But here's something that's been bothering me. I can't run this kind of program straight from TextMate. I have to run it through IRB in order to collect information the program can manipulate. Is there a way to make it so I can just run it from TextMate, or is there a text editor others use that allows you to do that? I'd prefer just to deal with one open program and I like to run it periodically to see how the changes I've made to the code affect functionality. Or if they break it!

Also, when a user inputs information that is collected with the gets command, where is that information stored? Is it stored at all, or just used immediately by the program and then discarded?