home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12975 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  1.6 KB

  1. Path: sparky!uunet!iphasew!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: GOTO, was: Tiny proposal for na
  5. Message-ID: <rmartin.714929724@thor>
  6. Date: 27 Aug 92 15:35:24 GMT
  7. References: <714668024@thor> <6800007@tisdec.tis.tandy.com>     <1992Aug26.130335.26725@hemlock.cray.com> <MATT.92Aug26122422@physics16.berkeley.edu>
  8. Sender: news@Rational.COM
  9. Lines: 31
  10.  
  11. matt@physics16.berkeley.edu (Matt Austern) writes:
  12.  
  13. >The classic situation where gotos are generally believed to be useful
  14. >is writing a finite-state machine.
  15.  
  16. >It seems to me that you could probably do better, though, by defining
  17. >some abstract class State, and then deriving the actual states of the
  18. >finite-state machine from it; this seems like it might be a more
  19. >elegant technique.  (I haven't tried this, though; I'm just
  20. >speculating.)
  21.  
  22. Get the C++ report, Vol 3, Number 1, January 1991.  The banner article
  23. provides a detailed description of your speculation.
  24.  
  25. I have since used that techinque in dozens of applications, and have
  26. even written a yacc/lex parser which takes a traditional State
  27. transition table and converts it into the necessary C++ code.  (I'll
  28. send it to you if you like).
  29.  
  30. ------
  31.  
  32. Goto has never been a "good" way to implement FSMs.  Nested
  33. switch/case statements which use a State variable and transition codes
  34. are more traditional, easier to maintain, and do not use goto.
  35.  
  36.  
  37. --
  38. Robert Martin                        Training courses offered in:
  39. R. C. M. Consulting                       Object Oriented Analysis
  40. 2080 Cranbrook Rd.                        Object Oriented Design
  41. Green Oaks, Il 60048 (708) 918-1004       C++
  42.