home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 137_01 / dec83col.ddj < prev    next >
Text File  |  1979-12-31  |  15KB  |  304 lines

  1. .pl 60
  2. .po 0
  3. ..
  4. .. "The C/Unix Programmer's Notebook"
  5. ..
  6. .. DDJ Column #2        as of 19-Sep-83
  7. .. (C) 1983 Anthony Skjellum.   All rights reserved.
  8. .. For publication in DDJ
  9. ..
  10. ..
  11. .. file (DDJCOL2.WS)        created:  19-Sep-83
  12. ..                updated:  24-Sep-83
  13. ..                updated:  
  14. ..
  15. ..                completed: 25-Sep-83
  16. ..
  17. .he "C/Unix Programmer's Notebook" by Anthony Skjellum. (C) 1983.  For December, 1983, DDJ.   
  18.  
  19.  
  20.                                A Correction
  21.  
  22.     In  the last column,  several references to the book The C Program-
  23. ming  Language  and  its  authors  were  made.   Through  my  error,  Brian 
  24. Kernighan's  name was misspelled consistently throughout the  column.   I'm 
  25. sure that many readers noticed this immediately.   Unfortunately,  I didn't 
  26. until I saw the column in DDJ.
  27.  
  28.                                Introduction
  29.  
  30.     In  this second Programmer's Notebook,  I'll discuss how  Unix-type 
  31. environments  can  lead to non-interactive,  and user-unfriendly  software.  
  32. This  is  based  on experiences I've had with several  Unix  and  Unix-like 
  33. systems running both standard and Berkeley Unix.  
  34.  
  35. ..       Last  time,  I discussed incompatible linkage formats  and  runtime 
  36. .. libraries  of  C compilers in both the eight and sixteen-bit  world.   This 
  37. .. time,  the  discussion will concentrate on problems and  difficulties  I've 
  38. .. encountered  through  in with linkers and C libraries in my work under  MS-
  39. .. DOS.
  40.  
  41.     Skimming through the ads in the October DDJ,  I noticed that nearly 
  42. twenty-five  percent of the ads concerned or mentioned C or Unix.   Most of 
  43. them concerned C.   This indicates strongly that C and to a lesser  extent, 
  44. Unix,  are  popular items with DDJ readers.   I also hope that reader input 
  45. will be significant as it has been with other DDJ columns.
  46.  
  47.     I  also saw an extremely interesting advertisement in  the  October 
  48. DDJ.  This was a Computer Innovations ad concerning the soon-to-be-released 
  49. version  of  their C compiler.   As an option,  this compiler will  produce 
  50. programs/data  exceeding the previous limit of 64K segments imposed by  all 
  51. 8086 compilers (C or otherwise) that I've seen.  Look for a review in  this 
  52. column early next year.  
  53.  
  54.                      Unix and non-interactive Software
  55.  
  56.     The  Unix  operating  system was designed to reduce  repetition  of 
  57. programming effort by permitting modular programs to be combined via  pipes 
  58. and  tees.   Since  input and output are redirectable  under  Unix,  simple 
  59. programs could use console input and output for one application and be used 
  60. as  part of a pipeline for another.   Thus,  unmodified programs  could  be 
  61. reharnessed  for  new applications to an extent not possible with  previous 
  62. operating systems.  
  63.  
  64.     Pipes  and input-output redirection are two of the best  and  well-
  65. known  features  of the Unix system.   Microcomputer users have  been  very 
  66. interested  in  adding these capabilities to their own  operating  environ-
  67. ments.   In the eight-bit world, this has been done chiefly through special 
  68. subroutine  libraries such as "The Unica," or in C runtime  packages.   For 
  69. MS-DOS 2.0 users, the features are built into the operating system.  
  70.  
  71.     Despite  the  undisputed usefulness of pipelines  and  input-output 
  72. redirection,  their  presence in Unix has lead to a serious drawback in the 
  73. system's environment.  This drawback is the proclivity to avoid interactive 
  74. programs   and  to  produce  user-unfriendly  software.   Furthermore,  the 
  75. standard  Unix  console  interface is weaker  than  under  other  operating 
  76. systems.   In  the remainder of this column I will discuss these weaknesses 
  77. as I perceive them.  
  78.  
  79.                          Non-interactive Software
  80.  
  81.     Because of the availability of pipes and input-output  redirection, 
  82. many  Unix programs are designed to act as filters.   Filters are  programs 
  83. which  require  a single sequential input data stream and produce a  single 
  84. output data stream.   Such programs are suitable as pipe-fittings.  Because 
  85. of  the  way  they  handle data,  they don't normally  expect  to  be  used 
  86. interactively.   In  most  cases  this doesn't pose a  problem  for  users.  
  87. However,  because such programs do not expect to deal directly with humans, 
  88. but only with input and output streams,  they can often be very  unfriendly 
  89. in the area of error handling.  
  90.  
  91. ..
  92.     The  problem in the Unix system is that the same  terse  philosophy 
  93. applied  to  filters also pervades most of the  software  available.   This 
  94. includes programs which are normally executed sequentially by the user from 
  95. the  console.     The  problems  come in several areas and  some  of  these 
  96. problem  areas  are  listed  in Table I.   The  following  paragraphs  will 
  97. elaborate each of the points listed in that table.
  98.  
  99. ---------------------------------TABLE I.---------------------------------
  100. -----------------------(Unix software Problem Areas)----------------------
  101.  
  102.         1.  terse (hard-to-remember) program names.
  103.         2.  lack of program sign-on and sign-off messages.
  104.         3.  lack of interactive mode to alleviate the need
  105.             to re-execute a program several times to complete
  106.             a set of operations.
  107.         4.  inconsistent use of switch (dash options) for
  108.             controlling the specifics of program execution.
  109.         5.  lack of descriptive error messages.
  110.         6.  cryptic, incomplete, and erroneous documentation
  111.         7.  software bugs: un-documented and documented.
  112.         8.  cryptic (or missing) internal help features.
  113.         9.  poor console interface provided by Unix.
  114.         10. lack of system for finding program names by the 
  115.             function required.
  116.         
  117. ------------------------------END OF TABLE I.------------------------------
  118.  
  119. .pa
  120.                                 Terse Names
  121.  
  122.     Unix  program names are usually two or three letters long and  tend 
  123. to  be  cryptic.   While  this saves  typing  for  experienced  users,  its 
  124. frustrating  for  new and occasional system users.   Also,  since the  Unix 
  125. system  lacks  an  on-line indexing system for  finding  program  names  by 
  126. function,  it's  not  easy to find the right program based on  the  desired 
  127. function alone.  
  128.  
  129.                           Sign-ons and Sign-offs
  130.  
  131.     Sign-on and Sign-off messages are a common courtesy in the computer 
  132. world.   Virtually  all  standard  Unix  programs  lack  these  two  simple 
  133. features.   While  this  is understandable for filters,  it  is  completely 
  134. unnecessary for other programs.   For example, if two versions of a program 
  135. exist on a system,  the only easy way to distinguish them is by their sign-
  136. on messages.  
  137.  
  138.     Besides sign-ons/offs, its also nice for a program to give progress 
  139. reports  during  execution.   This  lets  the  user  know  how  things  are 
  140. proceeding.   Standard  Unix  software  doesn't  normally  include  such  a 
  141. feature.
  142.  
  143.                           Internal Help Features
  144.  
  145.     Many  programs include a feature summary option to help  occasional 
  146. and new users remind themselves of program operation.   Many Unix  programs 
  147. also have this capability, but they are often extremely cryptic and include 
  148. few English words to supplement the sample command line which they display.  
  149. Figure I.  displays a sample session in which a ficticious program  (called 
  150. fct)  is executed from the shell with no arguments.   The program  responds 
  151. with  a cryptic help summary typical of actual Unix  commands.   In  Figure  
  152. II.  the  same fct program session is presented,  but this time the program 
  153. has  been  designed to provide a user-friendly help feature  (and  also  to 
  154. sign-on and off).  
  155.  
  156. ---------------------------------FIGURE I.--------------------------------
  157. ---------------------------(Cryptic fct Session)--------------------------
  158.  
  159.     $ fct <RETURN>        (activate the program with no arguments)
  160.     usage: fct -abcv file1..fileN    (help message)
  161.     $            (shell prompt)
  162.  
  163. -------------------------------END FIGURE I.------------------------------
  164. .pa
  165. --------------------------------FIGURE II.---------------------------------
  166. --------------------------(Friendly fct Session)---------------------------
  167.  
  168.     $ fct <RETURN>        (activate the program with no arguments)
  169.  
  170.     fct (version x.yz) as of dd-mmm-yy
  171.  
  172.     usage:
  173.         fct [dash options] file1...fileN
  174.  
  175.     dash options:
  176.  
  177.         -a    perform function 'a' on files specified
  178.         -b    perform function 'b' on files specified
  179.         -c    perform function 'c' on files specified
  180.         -v    verify each step before proceeding
  181.  
  182.     note: -a, -b are mutually exclusive; -c may be used in conjunction
  183.           with -b only.
  184.  
  185.     End of execution.
  186.     $            (shell prompt)
  187.  
  188. ------------------------------END FIGURE II.------------------------------
  189. .pa
  190.                              Interactive Modes
  191.  
  192.     Interactive  program modes provide a friendly environment  for  the 
  193. user.  When  a  program  is used often,  it may be executed  several  times 
  194. consecutively.   An  interactive mode eliminates the need  for  consecutive 
  195. execution  since  the  user can enter all the commands in  one  interactive 
  196. session.   This  avoids  unnecessary  user effort,  and  is  probably  more 
  197. efficient from a system standpoint.
  198.  
  199.     One  reason  that the interactive modes are missing is the lack  of 
  200. support  for expanding Unix wildcard filenames from within  a  program.   I 
  201. found  this  limitation  rather arbitrary and so I wrote  a  program  which 
  202. solves the problem (see "Expanding Unix Wildcards," DDJ,  November,  1982.)  
  203. The  lack  of direct support for such a function indicates that  the  whole 
  204. Unix philosophy is geared towards non-interactive software tools.
  205.  
  206.                            Command-line Switches
  207.  
  208.     Unix  program  use command-line switches (dash options) to  specify 
  209. the particulars of program execution. Switches are usually a dash character 
  210. ('-') followed by a single letter.   Unfortunately, Unix programs use these 
  211. switches inconsistently.  For example, the rm command only permits switches 
  212. before  file  names  on the command line.   Some  programs  permit  several 
  213. switches to be combined after a single dash character (eg -abcdef).  Others 
  214. use  the plus ('+') character to activate a program feature and a  dash  to 
  215. deactivate  it.   Generally,  it is difficult to remember all the different 
  216. possibilities, limitations, and defaults imposed by the various programs.
  217.  
  218.     The  difficulties with command-line switches under Unix lead me  to 
  219. write the ARGUM package published in the August,  1982,  issue of DDJ.   In 
  220. that  article,  I  proposed  a  program which would handle  switches  in  a 
  221. consistent way.   Existing Unix programs could be changed to use ARGUM  and 
  222. thus  eliminate one degree of inconsistency from the operating environment.  
  223. Alternatively, the less powerful Unix III getopts() facility could be used.
  224.  
  225.                     Lack of Descriptive Error Messages
  226.  
  227.     The   lack  of  descriptive  error  messages  is  a  real  problem, 
  228. especially for inexperienced users.   One offender is the eqn/troff  system 
  229. used for equation and text phototypesetting.   These programs report errors 
  230. as "Syntax Error" between two line numbers.   They don't echo the erroneous 
  231. text  or equation and the line numbers aren't always useful because  header 
  232. files change the length of the source text.
  233.  
  234.     Another problem stems from the way Unix reports failures.  Programs 
  235. which attempt to open a file and fail get an error code.  They subsequently 
  236. report  the  failure  as "Cannot open file."  While  this  is  correct,  it 
  237. doesn't  tell the user if the file is non-existent or if a file  protection 
  238. violation has occurred.  Similarly, when a user tries to change his current 
  239. directory  to  one for which he has no read privileges,  a "bad  directory" 
  240. message is displayed by the Unix shell.
  241.  
  242.                                Documentation
  243.  
  244.     Documentation is a real problem in the Unix system.   Most programs 
  245. are  documented  in a standard form which is  typically  very  terse.   The 
  246. examples provided are often very complicated,  and don't clearly illustrate 
  247. how  to  use  the  program for  simple  purposes.    Because  of  the  poor 
  248. documentation,  some casual users think of Unix systems as secret-societies 
  249. since  only  the  indoctrinated can tell them how the system  and  programs 
  250. work.
  251.  
  252.     Another  problem  with documentation is that it  sometimes  doesn't 
  253. reflect the current state of a program.   Most notable on the system I use, 
  254. are  undocumented  features of the standard Unix editor ed.   The  standard 
  255. form provides no line edit command ('x') while the installed version  does.  
  256. Yet, the documentation does not explain this.  
  257.  
  258.     Unix  documentation  is clearly the weak link in  the  system.   It 
  259. makes  some  of the mysterious concepts of the system  seem  impossible  to 
  260. grasp and reduces productivity through its terseness.
  261.  
  262.                                Software Bugs
  263.  
  264.     Another problem which makes a Unix system user-unfriendly (actually 
  265. user-hostile)  is  the presence of undocumented bugs in important  software 
  266. packages.   For example,  bugs exist in the eqn/troff system.  These can be 
  267. circumvented,  but  the  methods  are known only  to  a  few  experts.   No 
  268. generally available documentation exists for avoiding such problems.   
  269.  
  270.     Since the Unix system comes with source code, it should be feasible 
  271. for  individual  users to change system software to their  specific  needs.  
  272. Unfortunately,  the  source code which accompanies Unix is mostly  comment-
  273. free and is therefore difficult to understand without significant effort.
  274.  
  275.                           User Console Interface
  276.  
  277.     The  user console interface is not extremely good under Unix.   For 
  278. example,  when  a character is deleted,  Unix does not actually remove  the 
  279. character  typed  but just moves the cursor back one space.   There  is  no 
  280. standard mechanism for having a line retyped,  and backspacing after typing 
  281. a  tab doesn't produce the correct results.   Furthermore,  When a  control 
  282. character  is typed,  it is displayed in the form ^CHAR,  but when deleted, 
  283. the cursor moves back only one space (leaving the caret).
  284.  
  285.     The  weak user interface points again to the philosophy  that  most 
  286. software will not be interactive.   However, the standard Unix editor makes 
  287. no attempt to improve the interface for the purpose of interactive editing. 
  288. It is so unfriendly that most users resort to other editors (usually screen 
  289. editors).  
  290.  
  291.     Programmers  can  only  provide  their  programs  with  a  superior 
  292. console interface by using the raw terminal mode.  Unfortunately, this mode 
  293. is  more  expensive  in terms of  input-output  cost.   For  user-friendly, 
  294. screen-oriented software, its the only way to go.
  295.  
  296.                                 Conclusion
  297.  
  298.     Unix  is  a  powerful  operating  system.    However,   the  system 
  299. philosophy  has  lead to a predilection against interactive  software.   In 
  300. this  column,  I have discussed some of the aspects of Unix which  make  it 
  301. user-unfriendly.
  302.  
  303.     I  look forward to hearing from Unix users on how they perceive the 
  304. Unix environment.