From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: Fri, 6 Sep 91 12:48 EST From: Subject: Ada micro Style for Programs in Introductory Textbooks Message-ID: <9109061645.AA02727@ajpo.sei.cmu.edu> List-Id: Richard Pattis writes: >Date: 5 Sep 91 19:05:51 GMT >From: june.cs.washington.edu!pattis@beaver.cs.washington.edu (Richard Pattis) >Subject: Ada micro Style for Programs in Introductory Textbooks >Message-ID: <1991Sep5.190551.8272@beaver.cs.washington.edu> I recently received some reviews for a CS 1 (Introduction to Programming) in Ada textbook. I was criticized (to varying degrees) for not typesetting my Ada code according to the standard established in the LRM. ---stuff deleted--- > 1) Ada's words (whether reserved words or predefined identifiers - see >point 2) should be easily identified; they are the landmarks to navigating >through programs. The LRM uses bold-face, but that is not an option for >students who write programs using standard text editors. I want to present >code in the book using a style that the students can emulate in their >programs. Upper-case words stand out best. Reserved words provide the structure of the program and must stand out. Having taught and used both C and Modula-2 which are case-sensitive with differing requirements on the case for reserved words, I believe that either all caps (Modula-2) or all lc (C) are equally effective if used consistently and if they contrast with user-defined words. > 2) To beginners, there is little difference between Ada's reserved words >and the predefined identifiers. If I had to place reserved words, predefined >identifiers, and user defined identifiers into two categories, I would opt to >place the first two together (have a built-in meaning) rather than the second >two (the user can choose the meaning). Certainly this seems true for identifiers like INTEGER and CONSTRAINT_ERROR. Even for identifiers like POS >(where there is a good chance a beginner will declare a variable with this >name), writing POS when used as an attribute (something from Ada) and Pos when >used as a user declared identifier seems reasonable. Predefined types (integer, float, etc.) seem to be comfortable using the style of reserved words but I find myself using user-defined style when I program as it seems more comfortable to have all the types consistent rather than distinguishing between pre-defined and user-defined in a series of declarations. Text book writers have to worry about such problems but I tell my students to try to be consistent but that either is acceptable. C gives no helpful hints as I am convinced that K&R did not have a shift key when they developed it. I/O functions should be mixed case. Pre-defined library units are neither fully pre-defined nor fully user-defined. Text book writers need to face the fact that we now have a third category that, with the concept of re- usable code becoming an essential consideration, needs to be better handled. > 3) Mixed case identifiers (user defined) are easier to read than all upper- >case or all lower-case (even with underscores). Compare Student_Count and >StudentCount with STUDENT_COUNT and STUDENTCOUNT. So the problem specific >words (which are often plentiful, long, and descriptive) should be written in >mixed case. I prefer Mixed_Case with underscores. Long words without breaks (underscores) make a program look awkward. Are there still printers out there that only print CAPS? We used to have one. Made reading Modula-2 code difficult. A consistent style is essential for program clarity. We use a Language Sensitive Editor that forces tokens to adhere to our chosen style. For Modula-2, it forced CAPS and we adapted our Pascal LSE to produce CAPS. The LSE for Ada uses lc tokens and it was easier to go with that than to modify it. We did modify the Pascal LSE to produce lc tokens to match the Ada LSE better when we switched to Ada as our primary language. Both styles in Pascal were very effective. Consistency is really the point. Dennis S. Martin University of Scranton martin@jaguar.uofs.edu martin@scranton.bitnet