From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11390f,4c42ac518eba0bbe X-Google-Attributes: gid11390f,public X-Google-Thread: 103376,4c42ac518eba0bbe X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,4c42ac518eba0bbe X-Google-Attributes: gid1014db,public From: fred@genesis.demon.co.uk (Lawrence Kirby) Subject: Re: Programming language vote - results Date: 1997/11/26 Message-ID: <880510760snz@genesis.demon.co.uk>#1/1 X-Deja-AN: 292721030 Distribution: world References: <343fbb5a.0@news.iprolink.ch> <34466EB4.3381@dynamite.com.au> <$2oaKBAp0xe0EwNL@dowie-cs.demon.co.uk> X-Mail2News-User: fred@genesis.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: genesis.demon.co.uk X-Trace: mail2news.demon.co.uk 880513463 25739 fred genesis.demon.co.uk Organization: none Reply-To: fred@genesis.demon.co.uk Newsgroups: comp.lang.ada,comp.lang.apl,comp.lang.c Date: 1997-11-26T00:00:00+00:00 List-Id: In article <$2oaKBAp0xe0EwNL@dowie-cs.demon.co.uk> martin@dowie-cs.demon.co.uk "Martin M Dowie" writes: >In article <347B17AC.5A53@mWilden.com>, Mark Wilden >writes >>Martin M Dowie wrote: >>> >>> i've heard many people use this "where it is simply the best approach" >>> 'reason' - care to given an example? [of goto] A good example is breaking out of nested loops, say for code that is searching for a value in a 2 dimensional array datastructure. Possibly a more flexible form of the break statement would have been the answer here but since we don't have that goto is the best solution. The Pascal solution would probably be to create some sort of flag variable but that just obscures the algorithm which is not a good idea if it can be avoided. >>I've found goto the best way to branch in a simple state machine. > >in what why is this 'the best'? surely an enumeration type containing >each possible state together with a local static variable used in an >infinite loop would produce more readable safer and _provable_ code? You would need to demonstrate that it is any of these things. Most of the state machines I've written have taken the form you suggest but that is for a specific reason that I've tended to want to preserve the state between calls to the function containing the FSM, therefore the state needs to be held in a variable. Where that isn't the case a goto based implementation is quite natural. A FSM has structure but it is not of the same form as that supported by structured languages. So trying to implement it using structured language concepts isn't an automatic win. In fact by doing so you're adding an extra layer of complexity. >or >is that loop up to the top of a case/guarded select statement too >much?.. We're comparing two approaches, not asking in an absolute sense whether one approach is acceptable or not. -- ----------------------------------------- Lawrence Kirby | fred@genesis.demon.co.uk Wilts, England | 70734.126@compuserve.com -----------------------------------------