Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdahl!oliveb!sun!pepper!cmcmanis From: cmcmanis%pepper@Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga Subject: Re: Struggling through the "C" Summary: Semi-Flame from Chuck Message-ID: <97160@sun.Eng.Sun.COM> Date: 3 Apr 89 05:38:06 GMT References: <12000@louie.udel.EDU> <97113@sun.Eng.Sun.COM> <13.6va2CVf1010TxC9.@amdahl.uts.amdahl.com> Sender: news@sun.Eng.Sun.COM Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Organization: Sun Microsystems, Mountain View Lines: 56 [Not at Kevin, just Kevin happened to post, everyone else just sent mail :-)] In article <13.6va2CVf1010TxC9.@amdahl.uts.amdahl.com> (Kevin Clague) writes: > or the less obvious, but more efficient (but Chuck knows this): > > char *b; > > b = a; > > while (*b) { > printf("%b",*b++); > fflush(stdout); > } > Several people sent me messages ranging from, "how could someone like you post such stupid C code?" to the more helpful "... didn't you know it would be _much_ more efficient if you did it like this ..." [insert Kevin's example here.] To keep from having to send everyone copies I've decided to post my thinking on this matter, fortunately this is not in c.s.a.t since it has very little technical content : This is a _BASIC_ programmer we are talking to. Not your everyday pro ok? He writes : 10 FOR I = 1 TO LEN$(A$) 20 PRINT MID$(A$, I, I) 30 NEXT I Now when one is teaching someone a new language, especially someone who's been damaged by learning BASIC first, one starts with direct equivalences. Token substitution and such. This trains the students eyes into seeing the new syntax but keeps some anchor points so that they don't loose sync. Once they understand the construction of for(;;){} loops one moves on to talk about pointers, while loops etc. The favorite example : char *foo = a; while(*foo) printf("%c",*foo++); Introduces no less than 5 totally radical ideas to the BASIC programmer. They are 1) String Pointers, 2) Non-Boolean loop conditions, 3) While loops, 4) Pointer arithmetic and implied assignment (++), and 5) NULL termination of C strings. That makes it a _lousy_ example. Your BASIC programmer is not only lost, he doesn't even know where to start asking questions! You've gone way over his head. So as an eventual programming goal to shoot for this if fine. In the mean time lets not make him feel totally stupid shall we? --Chuck McManis uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com These opinions are my own and no one elses, but you knew that didn't you. "A most excellent barbarian ... Genghis Kahn!"