[Newbies] Spaghetti code
blake at kingdomrpg.com
Sun Feb 18 09:11:31 UTC 2007
Thanks for the feedback. It is a fun question.
> Welcome to the list.
Heh. I've been on this list since it started and on the general list for
years, but I guess I don't make much of an impression.
> ...it may be better to let your son solve the problem on his own and
> then go back and build something else using some new techniques that you
> can show him.
Sorry if I hadn't made that clear: That's precisely what I am doing.
> Second there are a lot of possible designs for this problem. The
> implementation of the design should be kept separate from the design
> itself. Whether or not you use a text file or how you store the data is
> a detail.
> The details come easy once you have a good design. So focus on design
Right. I meant to draw contrast to a traditional state machine where
things are fixed, and went to a specific detail.
> That aside this is a fun question. (Although I really don't like the
> actual flow chart, killing and kids don't mix well in my mind. I know
> there are
> lots of killing video games but not that I let my child play)
Not to get sidetracked on the issue, but I introduced my son to computers
and gaming at the age of...oh...15 months by having him sit on my lap and
fire the weapons in Doom 2. I can't really explain in brief the extent of
the positive changes this wrought. He's had an abiding love of
games--including "violent" games--ever since. (I put "violent" in quotes
for a lot of reasons that are also not on topic.<s>) Completely
coincidentally, he's by far the most compassionate persion I've ever met.
I've never met anyone so completely devoid of cruelty and so quick to help
others in distress.
(Of course, results not typical, your mileage may vary. I filter out
plenty of other things I think are bad for him; it's just that his list is
different from other kids'.)
By the way, in case it's not obvious, this is a flow chart for the
pen-and-paper RPG "Dungeons and Dragons", and is meant as a jokey
simplification of that game.
> System: Enter Property Name:
> You: Scary
> System: Enter Question for Property Scary:
> You: Is it Scary?
> System: Answer to question Is it Scary?:
> You: yes
Ah. Yes. This is "Animals", in essence. That's an excellent segue to a
> Notice there is no branching code any more. To follow a flow you start
> from the root tree.
Yes, that's what I was going for. Your design is deeper than mine, though.
> Ok so why did we build thingys? Well because things can now answer
> questions for themselves and we can build costumes on thingies and get
> them to run around on screen. Now we don't have to ask the user
> questions we can just send messages.
I'm not sure what that--doesn't the game go away at that point?<s>
> (Like KILL! Ugh).
All things that live, kill. Or, minimally, all organisms compete for
resources that other organisms could use to survive.
> So to summarize my suggestion: you use a tree construct to represent
> branching instead of using hard coded flows.
Good. That's the ball-park I was in.
> (It is not really a linked list) You build objects that represent
> properties that have questions and
> answers. You can then build things that have these properties.
Yeah, I hesitated to use the term "linked list" but it's (non-technically)
a list of linked items. I suppose, technically, it's an n-tree.
More information about the Beginners