Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site bu-cs.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!mhuxt!mhuxr!ulysses!allegra!mit-eddie!think!harvard!bu-cs!root From: root@bu-cs.UUCP (Barry Shein) Newsgroups: net.cse Subject: Re: students editing output Message-ID: <685@bu-cs.UUCP> Date: Wed, 25-Sep-85 16:29:41 EDT Article-I.D.: bu-cs.685 Posted: Wed Sep 25 16:29:41 1985 Date-Received: Sun, 29-Sep-85 04:44:28 EDT References: <433@uvm-cs.UUCP> <1500@brl-tgr.ARPA> <647@bu-cs.UUCP>, <150@l5.uucp> Organization: Boston Univ Comp. Sci. Lines: 88 >From: laura@l5.uucp (Laura Creighton) > >I had a thought. You send students through 4 years of a cs program >and threaten them with everything under the sun if they cheat. Then you >ship them out into the real world and I wonder why every third c program >I see is written by someone who thought that he had to reinvent the >strcmp, strncmp and related functions. Good point, but *I* claim the problem is the insistence on teaching with Pascal. Your example provides an excellent example of why: In Pascal the length of an array is part of it's type. Strings are generally stored in 'packed array of char' (or array of char, no difference for this point.) Now, consider the strlen function in Pascal: constant maxstring = 256 ; type string: packed array [1..maxstring] of char ; var buf : string ; function strlen(str : string) : integer ; begin strlen = maxstring end ; { strlen } Kinda stupid, huh!? But you just can't pass different length arrays to a Pascal routine, pointers don't help (as a C programmer might have guessed) as they are typed according to the object they point to and you just end up back to where you started. There are no casts or some such to help. This then holds true for strcmp() et al as they all have the same problem (!) Ok, now to throw some Halon on the potential flames: 1. Yes, you could declare all arrays for strings to be the same length and use a null (chr(0)) or some such to terminate within the array, much like C does (tho C does not restrict your array declaration, just asks that somewhere there be a null to terminate.) This is not very good, everyone will want to change it (if they could even be comfortable with every string in their program using up the largest amount *any* string will *ever* need.) 2. You could use some other representation of string, when I brought this up with a faculty member her solution was 'you should just represent strings as linked lists of chars' [no comment] 3. Some Pascals have strings built in as a 'natural' data type: a) that is not pascal, that is a pascal-like language, unfortunately, to be at all useable, every pascal has extensions and no two are alike...forget portability. We move students just from our IBM [AAEC Pascal/8000 I believe] to 4.2 and they are astounded at how confused they are, lotsa fun (wotta waste.) b) More importantly, this is just an example, solving the special case of strings still doesn't let me write C's qsort() routine (try it, it *cannot* be written in Pascal in any useful way...sad, huh, ya gotta write a different sort routine for every data type, array size you use!) Further, most Pascal systems tend to discourage external linkage, tho it usually can be done the severe limits and pains they make you go through (only a pascal fanatic or one that only used a very non-standard pascal would argue with this) makes it impractical to use seriously. The result: Everything ends up to be ad hoc one-shots, forget building generic libraries, write your own everything. And completely forget portability, it doesn't exist in the pascal world. The problem may be worse than you think. I teach a C course which follows after a year of Pascal (typically taken freshman year.) I spend most of the term undoing the pascal brain-damage (I haven't even mentioned the real effects of not having a return(val) statement and other weirdnesses.) Sigh. -Barry Shein, Boston University P.S. On second thought, I would even argue with your original hypothesis, using a library function is not cheating as far as I know anywhere. Brought to you by Super Global Mega Corp .com