home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / misc / 3547 < prev    next >
Encoding:
Text File  |  1992-11-09  |  6.7 KB  |  129 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!munnari.oz.au!metro!usage!syacus!ian
  3. From: ian@syacus.acus.oz.au (Ian Joyner)
  4. Subject: Re: Pointers
  5. Message-ID: <1992Nov7.115620.29967@syacus.acus.oz.au>
  6. Organization: ACUS Australian Centre for Unisys Software, Sydney
  7. References: <1992Nov2.083810.1652@syacus.acus.oz.au> <Bx3BsH.I0J@mentor.cc.purdue.edu> <1992Nov3.130634.26112@rdg.dec.com> <1992Nov4.031026.23624@linus.mitre.org>
  8. Date: Sat, 7 Nov 1992 11:56:20 GMT
  9. Lines: 118
  10.  
  11. crawford@boole.mitre.org (Randy Crawford) writes:
  12.  
  13. >In article <1992Nov3.130634.26112@rdg.dec.com> jch@rdg.dec.com (John Haxby) writes:
  14. >>|> In article <1992Nov2.083810.1652@syacus.acus.oz.au> ian@syacus.acus.oz.au (Ian Joyner) writes:
  15. >>|> >jch@rdg.dec.com (John Haxby) writes:
  16. >>|> 
  17. >>|> >>C's pointers are a pain in the neck sometimes.
  18. >>|> 
  19. >>|> >Great understatement :-) You simply don't need C style pointers in decent
  20. >>|> >programming languages.
  21. >>
  22. >>C's pointers don't actually provide anything useful, apart from,
  23. >>perhaps, an ability to duplicate Lindsay's `triple ref' code.
  24.  
  25. >Sure they do.  Pointers are not just variables, they're polymorphic 
  26. >placeholders.  When you want an identifier that can be an integer, 
  27. >a function, or a port, you use a pointer.  You want to return a 
  28. >function from a function?  You can do it in C -- you return a pointer.  
  29. >You want to define your own objects (or packages) with member functions, 
  30. >you can do it with structures and pointers.
  31.  
  32. OK, saying pointers don't provide anything useful was taking it a little
  33. too far. What you are describing, however, is situations where you want
  34. to crack a peanut with a sledge hammer. The use as polymorphic place
  35. holders is definately sledge hammer technology. It grinds type safety into
  36. a fine paste on the concrete which is not suitable for consumption. Somebody,
  37. somewhere said that when you have a hammer, every problem looks like a nail.
  38.  
  39. >>If one thinks in terms of references to objects and elements of arrays
  40. >>rather than pointers to both, things become somewhat clearer.  C's
  41. >>pointers-as-references are not all that different from Algol68's except
  42. >>in syntax and an explicit `address-of' operator.  Where you do get
  43. >>some significant differences is in arrays and storage management.
  44.  
  45. >Simple enough.  C has arrays.  Use _them_ rather than pointers when they
  46. >make your code easier to understand.  Pointers make poor arrays.  Don't
  47. >misuse them simply because you can.  
  48.  
  49. The point (sorry for the pun) being made is that pointers are a low level
  50. implementation for references. C lacks references, by-reference parameters,
  51. procedure references, etc. Thus in C everything looks like a nail, and the
  52. one solution is to use the pointer hammer. To make the distinction a little
  53. clearer, references bind to entities. You do not care how they bind to an
  54. entity. C pointers, however, make it clear that the binding is accomplished
  55. by a low level machine address. This is a very architecture dependent
  56. thing.
  57.  
  58. >The nice thing about C's low level programming support is that you 
  59. >don't have to tolerate the imposition and girth of a garbage collector 
  60. >(something that belongs in a library anyway).  If you really want one, 
  61. >once again, C will let you roll your own.  But you're not stuck with one.
  62.  
  63. Now that's the idea, let's all reinvent the wheel from scratch. This
  64. comment on garbage collectors is wrong and ill informed. A garbage 
  65. collector certainly doesn't belong in a library. It is a run time
  66. environment concept. Garbage collection is 'how' things are done, so
  67. the programmer should not be burdened with this level. The correct
  68. concession is to allow garbage collection to be disabled.
  69.  
  70. >If you want run-time error checking, then C is the wrong choice of
  71. >programming language for a lot of better reasons than array bounds 
  72. >checking.
  73.  
  74. Now we are getting somewhere. What you have just said makes C a wrong
  75. choice full stop. If an error occurs in a computation, then there is
  76. no point in the computation continuing. Once an error occurs, there are
  77. only two valid courses of action. Firstly, to fail and terminate. Secondly,
  78. to recover from the error. To continue with the computation is just
  79. nonsensical.
  80.  
  81. >>Yes, I know about the various tools for checking for this sort of thing, 
  82.  
  83. >Yes.  Like lint.  
  84.  
  85. Lint is an inappropriate tool for modern software development. Lint style
  86. checks should be built into the language and compilers. If they are built
  87. into the language from scratch, then you will find that many potential
  88. warnings will be avoided. Ignoring potential errors and generating an
  89. executable (I use the term loosely) program, is also nonsensical. This style
  90. of software tool should be abandoned for serious software development.
  91.  
  92. >>but if I learn to swim with armbands, does that mean I can forsake 
  93. >>them and swim to France? (to paraphrase Dijkstra, I think).
  94.  
  95. >Isn't this a bit like saying "once you've learned language X you should
  96. >continue to program in it exclusively" even if the language is inefficient, 
  97. >its features wasteful and often unnecessary?  Sure, Lisp is great for
  98. >rapid prototyping, but why choose it to write an operating system?  
  99. >Likewise, C is great for low to mid-level programming tasks.  It doesn't
  100. >excel at those which require fault tolerance or rapid prototyping.
  101.  
  102. Hang on, low level systems programming requires fault tolerance and error
  103. recovery, as much if not more that higher level programming. I think there
  104. is general confusion here, that if you are doing low level systems programming,
  105. then it must be done in a low level language. This is not true. Low level
  106. systems programming can be done in high level languages, with all their
  107. benefits.
  108.  
  109. >However, due to its utility and ubiquity, its popularity and wide-spread
  110. >use cannot be discounted either.  Sometimes C is used just because it
  111. >_can_ do the job and serve more than one master.
  112.  
  113. >As always, choose the tool that does the job best.
  114.  
  115. Do people really choose C because it does the job best? I think not. C is
  116. a lowest common denominator tool. Many C programmers will not even consider
  117. any other language (please don't reply to this one, I know you are the
  118. exception ;-)). If C is popular and widespread, it is because it has now
  119. achieved a great age, and is old and tired, and is based on 25 year old
  120. assumptions about how machines worked in those days, and the limited
  121. power and available memory that were common. If we want the tool that does
  122. the job best then it is overdue that C was retired in favour of young, more
  123. spritely languages that serve the needs of today.
  124. -- 
  125. Ian Joyner  ACUS (Australian Centre for Unisys Software)    ian@syacus.acus.oz
  126. "Where is the man with all the great directions?...You can't imagine it,
  127.  how hard it is to grow, Can you imagine the order of the universe?" ABWH
  128. Disclaimer:Opinions and comments are personal.
  129.