Article View: comp.lang.eiffel
Article #1206Re: Portability of code & skills (Beware of "C" Hackers etc)
From: Jay Martin
Date: Tue, 26 Mar 1996 21:10
Date: Tue, 26 Mar 1996 21:10
60 lines
2734 bytes
2734 bytes
RjB <onomoto@rahul.net> writes: >In article <4j8177$18ma@saba.info.ucla.edu>, >Jay Martin <jmartin@cs.ucla.edu> wrote: >> >>> function CountThem (l: List): integer; >>> var Count: integer >>> procedure CountOne (e: ListElement); >>> begin >>> if <some condition on e fulfilled> then begin >>> Count := Count + 1; >>> end; >>> end; >>> begin >>> ApplyOnList (l, CountOne); (* !!!! *) >>> CountThem := Count >>> end; >> >> >>This is what I call side-effects on a global variable (or variable of >>a larger scope). Its not what I call good programming practice. In >>fact, I see nested procedures as implemented in algol block languages >>(automatic importation of variables from larger scopes) as another >>stupid idea of CS. > Hardly: If CountThem is part of the published interface, then >how Count is used is immaterial. Excluding dinky cases like the above, it does matter how functions are constructed even if it is part of a "published interface". By looking at : ApplyOnList (l, CountOne); (* !!!! *) You have no idea that you have smashed variables in the local context. (Count). As code gets larger and more complex this trick becomes counter productive. > The point that you appear to be missing is that procedures and >functions are treated in a first-class manner, which is both powerful >and easy to understand. I am not convinced of either. >Compare this to how C/C++ uses pointers to >functions: it requires a great deal of work to get by the compiler, >and introduces a tremendous succeptibility to error. And when the >pointers do get munged, finding the bug isn't necessarily easy. Nonsense. In the cases like the above you would not use pointers but references to functions, which do not have the pointer problems. So what it really comes down to is allowing/promoting side-effects on the existing scope. The solution is in someway to pass the necessary variables making their use explicit to the interface of CountOne and the call of ApplyOnList. Like: ApplyOnList(l, CountOne, Count); Jay
Technical Details
Message-ID:
<4j9mfa$ibe@saba.info.ucla.edu>Path:
arc1-ca.pugleaf.net!nnrp.info.ucla.edu!jmartinReferences:
<31494D29.4D4B@dmu.ac.uk> <DooBwC.8C0@world.std.com> <65O34-3-3RB@herold.franken.de> <4j8177$18ma@saba.info.ucla.edu> <4j921v$b5q@bug.rahul.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nnrp.info.ucla.edu!jmartin From: jmartin@cs.ucla.edu (Jay Martin) Newsgroups: comp.lang.eiffel,comp.lang.c,comp.lang.c++,comp.object,comp.software-eng Subject: Re: Portability of code & skills (Beware of "C" Hackers etc) Date: 26 Mar 1996 21:10:02 GMT Organization: University of California, Los Angeles Message-ID: <4j9mfa$ibe@saba.info.ucla.edu> References: <31494D29.4D4B@dmu.ac.uk> <DooBwC.8C0@world.std.com> <65O34-3-3RB@herold.franken.de> <4j8177$18ma@saba.info.ucla.edu> <4j921v$b5q@bug.rahul.net> NNTP-Posting-Host: may.cs.ucla.edu X-Newsreader: NN version 6.5.0.b3.0 #9 (NOV)