home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!UB.com!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: GOTO, was: Tiny proposal for named loops.
- Message-ID: <rmartin.715618743@thor>
- Date: 4 Sep 92 14:59:03 GMT
- References: <2318@devnull.mpd.tandem.com> <rmartin.715001372@thor> <4192@papaya.bbn.com> <1992Sep2.131733.20676@terminator.cc.umich.edu> <r <KERS.92Sep4082931@cdollin.hpl.hp.com>
- Sender: news@Rational.COM
- Lines: 64
-
- kers@hplb.hpl.hp.com (Chris Dollin) writes:
-
- |In article ... rmartin@thor.Rational.COM (Bob Martin) writes:
-
- | You don't have to make up your own rules. Some other guys, who have
- | thought about it alot, have put together a pretty well thought through
- | set of rules. Moreover, the industry has, for the most part, accepted
- | those rules as valid. Moreover, it has been proven that those rules
- | are always workable, and it has been shown that they help to make code
- | more readable and maintainable.
-
- |In what sense do you claim that ``these rules'' (by which I understand you to
- |mean the usual rules of structured programming) have been ``proven'' to be
- |``workable''?
-
- Only that it has been proven that gotos are unecessary. That any
- algorithm can be written in terms of sequence, selection and
- repetition.
-
- |It's certainly true that any procedure can be rewritten in structured style
- |(ie, using only while, if, and sequencing as control structures). But the
- |easiest proof of this -- turn it into a loop wrapped round a case (chained ifs,
- |if you want to be picky) -- also shows that it's not necessarily a good idea,
- |if what you want is *clear* code.
-
- |And clearness is as much a matter of psychology as of mathematics.
-
- Yes, so lets forget the psychological part and focus on the
- mathematical part. Constructiong your algorithms based on SP causes
- you to separate paths that you might otherwise combine (with gotos).
- This separation decouples the paths from each other, so that changes
- made in one path do not affect the other paths.
-
- We don't use SP because it makes the code "prettier" or
- psychologically more gratifying. We use it because it separates the
- code fragments and reduces coupling. This makes the code easier to
- maintain.
-
- |There's a
- |lot of empirical evidence to suggest that traditional SP ``works'', ie, that
- |for very many programming problems, they are an effective solution. [The
- |evidence is the large number of programs written effectively in that style.]
- |But there's also evidence that they're not *enough* -- that other control
- |structures are needed for clarity -- consider
-
- | * procedures
- | * FOR-loops (of various kinds)
- | * N+1/2 times loops
- | * Scheme-style use of tail-call
- | * Co-routines
- | * Higher-order functions
-
- |for example.
-
- Agreed.
- The last thing I advocate is a reduction of all code to one linear
- stream of sequence, selection and repetition.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-