Word Counter

Posted Wed, 19 Oct 2005

That's right... word counter. Jeanna's students will know what I'm talking about.

For those of you that don't, this word counter, for one whole semester, was my pride and joy. Jeanna used this toy example program to help demonstrate how even the simplest programs, if not properly thought out and designed, can cause you massive headaches in a world where software consumers can't make up their minds. Jeanna would change the definition of what constitutes a "word" weekly, and off we'd go to adjust our counters - keeping in mind the end goal of having the fastest and most correct counter.

I'm pleased to say that my counter -- fully object oriented and extremely well designed -- was the second fastest in the class; beat out only by a man who some know as a maniac, others as my then-nemesis (due to our massively conflicting approaches to this project). He wrote his counter as a state machine, driven by goto's, in C. While unbeatable in speed, the low-level implementation required a complete re-write with each iteration. Mine only required a single line change, perhaps two or three depending how drastic the definition change was. But at most, I spent minutes each week on this project after my initial implementation*.

This application was also the start of my years-long const correctness frenzy. Check out the source -- it's const correct to the extreme!

You can download it here: word counter

* not including the time spent doing optimizations.

Related Books

Code Complete: A Practical Handbook of Software Construction West's Business Law with Online Research Guide, 9th Edition More Effective C++: 35 New Ways to Improve Your Programs and Designs (Addison-Wesley Professional Computing Series) Beautiful Code: Leading Programmers Explain How They Think (Theory in Practice (O'Reilly)) Photoshop CS QuickSteps

About

My name is Tim Fanelli, I am a software engineer in Northern NY. I spend most of my time working, and when I can, I try to post interesting things here.

Cigar Dossiers