home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / ada / 3692 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.8 KB  |  45 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!uw-beaver!pattis
  3. From: pattis@cs.washington.edu (Richard Pattis)
  4. Subject: Re: Language pitfalls (was Re: FORTRAN bug)
  5. Message-ID: <1992Dec15.180821.17817@beaver.cs.washington.edu>
  6. Summary: Here is one in Ada
  7. Sender: news@beaver.cs.washington.edu (USENET News System)
  8. Organization: Computer Science & Engineering, U. of Washington, Seattle
  9. References: <1992Dec14.165537.18275@mks <1992Dec15.135539.7245@lth.se> <EMERY.92Dec15095542@dr_no.mitre.org>
  10. Date: Tue, 15 Dec 92 18:08:21 GMT
  11. Lines: 32
  12.  
  13. Since Dave has volunteered to keep track....
  14.  
  15. When I introduce recursion in my CS1/CS2 class, this one never fails to show
  16. up. It is truly a C-like error (excuse the pejorative term) in that the
  17. distinction between a statement and value is clouded to reduce the number of
  18. reserved words.
  19.  
  20. Often the base case of a recursive function to manipulate a list looks like:
  21.  
  22.   IF mumble = NULL THEN
  23.     RETURN NULL;
  24.   ELSE ...
  25.  
  26. What my students sometimes write is
  27.  
  28.   IF mumble = NULL THEN
  29.     NULL;
  30.   ELSE ...
  31.  
  32. Here the statement NULL replaces the returning of a NULL value (which might be
  33. better to denote as NIL, at the expense of another reserved word). Of course,
  34. this is all syntactically legal and the error shows up only at execution time:
  35. often as a PROGRAM_ERROR (so at least Ada catches it at some time) if there
  36. are no other statements after the IF in the function. Of course, some compilers
  37. will give a warning based on the functions data flow information.
  38.  
  39. Rich Pattis
  40. -- 
  41. ------------------------------------------------------------------------------
  42.   Richard E. Pattis                     "Programming languages are like
  43.   Department of Computer Science         pizzas - they come in only "too"
  44.     and Engineering                      sizes: too big and too small."
  45.