[OCLUG-devel] ICFP Contest 2004

Stephen Crane scrane at cornerkitchenpeddler.com
Mon Jun 7 10:56:21 PDT 2004


On Monday, June 07, 2004 10:31 am, you wrote:
> 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.

Couldn't figure out how to do that. Plus the description, in the task, of the 
simulator was in a pseudo-language and used switch, so to make things wuick 
and easy I used the same for the most part.


> 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.

Yeah, they were getting pretty long....
I'll have to look at that again.

> 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.

Well, I started Teach Yourself c++ in 24 hours on monday, but only got to 
chapter 15 out of 24 ;-) I'll learn about those in the near future.

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

Simple answer: the function Ant::Turn
I needed to manipulate the direction mathematically and the c++ strict typing 
wouldn't let me.

> 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.

I'll look into that. I couldn't think that hard after about 15 hours of 
work ;-)

Thanks for the input.

Stephen



More information about the OCLUG-devel mailing list