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

  1. Path: sparky!uunet!cs.utexas.edu!torn!newsserver.cs.uwindsor.ca!preney
  2. From: preney@cs.uwindsor.ca (Paul Preney)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Tiny proposal for named loops.
  5. Message-ID: <1437@newsserver.cs.uwindsor.ca>
  6. Date: 26 Aug 1992 17:18:38 GMT
  7. References: <rmartin.714670566@thor> <2301@devnull.mpd.tandem.com> <rmartin.714753208@thor>
  8. Sender: news@server.uwindsor.ca
  9. Organization: University of Windsor, Ontario, Canada
  10. Lines: 30
  11.  
  12.  
  13. I have noticed this discussion about the use of break, continue, goto, etc. in C/C++ programming. I must say that I actually *prefer* to use structured programming techniques, especially in complicated code. My reasons for this are simple... Whenever I write a program for someone else or myself, I, of course, wrote it to do the desired task. Once, I finished it, I archived it and left it sit somewhere on some floppy disk until it was needed again. Now, if I did not adhere to structured programming conventi
  14.  
  15.  
  16.  
  17. ons, I would not even remember how exactly I used my returns, breaks, continues, and gotos and therefore, I could get myself into some trouble adding code to a program; i.e. a function with more than 1 return statement and adding code to it after the first return statement which should have been added also before every return statement. Surely, a function such as:
  18.  
  19. int g(int a, int b) {
  20.     if (a < b)
  21.         return 1;
  22.     else
  23.         return 0;
  24. }
  25.  
  26. is trivial but I think it is a much better practice to use:
  27.  
  28. int g(int a, int b) {
  29.     return (a < b) ? 1 : 0;
  30. }
  31.  
  32. since, you now are treating the function g as a function that has a place of entry and a place of exit. This makes code very clean especially in complicated functions and in simple/complicated long functions. If I did not adhere to such practices then I would have difficulty adding new code or modifying old code in my *own* program, let alone anyone else's.
  33.  
  34. I feel that people should be consistent in programming... very consistent especially if the program is going to sit for a period of time when nobody is going to be modifying it. Conforming to structured practices allows one to more conclusively *prove* his/her program correct since there is ONLY 1 RETURN statement in the function and ALL of the code leads to that *CONCLUSION* or return statement. Thus, I could much more easily say that the second function of g() is correct than that of the first one where 
  35.  
  36.  
  37.  
  38. I would have to check each and every return statement and all paths that lead to it. God help you if you have nested loops, if/else's and switch's in one function! :-)
  39.  
  40. Now, I have not been programming too long, since grade 9 and now I am in 2nd year university, BUT that does not mean in any way that I do not know what I am doing in C, C++, PostScript, NeWS, FORTRAN, BASIC, 80x86 Assembler, etc. BUT I HATE messy programming (for even which I am at fault) because it is very hard to "come bcak to" after a long time and it is also hard to catch those small weenie-little bugs that cause your program to not work properly.
  41.  
  42. Paul Preney
  43. "The Machine"
  44. University Of Windsor
  45. preney@server.uwindsor.ca
  46.