[OCLUG-devel] ICFP Contest 2004

Christopher Smith x at xman.org
Mon Jun 7 10:31:17 PDT 2004


On Mon, 2004-06-07 at 10:14, Stephen Crane wrote:
> Hi all - 
> 
> A while back there was a message on the main oclug list about the ICFP contest 
> (http://www.cis.upenn.edu/group/proj/plclub/contest/)
> Well I attempted to enter (ran out of time, though). Attached is my simulator. 
> It reads in a world file and two ant finite-state-machine files, runs them, 
> and dumps the board for each round to STDOUT (I would suggest using a > 
> pipe).
> 
> Wanted to know what you thought of my code. This is the first big project I've 
> ever done in C++. I just started learning C++ exactly one week ago (last 
> monday), so my code probably isn't the best.

Yeah, I'll give you credit just for getting things to compile given the
time frame you've been learning in.

I didn't have a chance to look at the code in detail, but having skimmed
it, I'll point out a few different areas for improvement:

1) Be suspicious of switch statements. Most of the time that one is
using a switch statement, one could instead use polymorphism or
overloading to address the problem, creating better separation between
the different bits of behavior.

2) Be suspicious of long methods, particularly constructors.
Constructors should have only one job: constructing an object. Other
behavior should either be done after construction or at least in
separate methods.

3) Think about using the containers and algorithms in the STL. I'm sure
you haven't had time to learn about how to use these suckers, but it is
definitely a good thing for you to do so.

4) Why didn't you stick with an ENUM for your directions?

5) I think in a number of cases their might have been benefits to making
some of your enums actually real objects/classes, and putting some of
the behavior in your switch statements inside those objects.

-- 
Christopher Smith <x at xman.org>


More information about the OCLUG-devel mailing list