[Newbies] Spaghetti code

Todd Blanchard tblanchard at mac.com
Sun Feb 18 19:51:55 UTC 2007

You're building an expert system.  There are well known patterns/ 
algorithms/architectures for that.

I developed ObjectiveCLIPS http://objectiveclips.com  which is an  
open source framework for building this kind of thing in ObjectiveC  
on the Macintosh.  A great book on the topic is http://www.amazon.com/ 

Basically you want a rules based production system based on the rete  
algorithm.  This is important because decision trees are fragile and  
difficult to maintain.

CLIPS is a good free system to play around with.  I've often wished  
we had a rete algorithm implementation in Squeak.  http://www.ghg.net/ 

Todd Blanchard

On Feb 17, 2007, at 4:11 PM, Blake wrote:

> I'm half thinking-out-loud here and soliciting thoughts on a  
> programming lesson. If this sort of thing bugs you, feel free to  
> ignore.
> ---
> My son is coding this flow-chart as a Q&A type application:
> http://media.www.gamespy.com/articles/633/633817/img_2913464.html
> So, it says, "You found something!" then asks "Is it alive?" and  
> then branches out accordingly. I'm letting him muddle through with  
> the idea of using his code as a platform to teaching him a better  
> approach (or approaches).
> Looking at the chart, it looks like spaghetti code, and reminds me  
> of some of the stuff I did in BASIC. And that's sort of what he's  
> doing within Smalltalk. I'm actually tempted to show him how it  
> would look in BASIC using GOTOs and line numbers. It would have the  
> advantage of being easy to see all in one glance.
> But I want to, of course, show him a better approach and explain  
> why it's better. My first thought was to make a state machine, but  
> I don't think that'd be much better, in fact.
> Then I thought of what I would do, professionally, in a similar  
> context: The problem with the spaghetti code and even a state  
> machine is that it's static, and adding bits and pieces tends to  
> require everything to be massaged around the new parts. In the real  
> world, I know that the chart's not going to be static.
> I'd probably end up create a linked list of one-exit nodes and two- 
> exit nodes.
> So, that's what I'll probably show him.
> The other thing I'd do, though, is put this all in an editable text  
> file, like:
> 1,foundsomething,"You found something",alive
> 2,alive,"Is it alive?",friend,smash
> 2,friend,"Is it a friend?",lately,scary
> 1,smash,"Smash it with a stick!",shiny
> But I'm wondering if this last wouldn't be too much.
> Thoughts?
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

More information about the Beginners mailing list