From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,de7c66b71e353e40 X-Google-Attributes: gid103376,public From: adam@irvine.com Subject: Re: Valued procedures Date: 1999/01/22 Message-ID: <78ad96$64u$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 435672914 References: <786pfu$1vb$1@nnrp1.dejanews.com> <7888jd$bln$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x9.dejanews.com:80 (Squid/1.1.22) for client 192.160.8.21 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Jan 22 17:41:59 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/3.0 (X11; I; Linux 2.0.34 i686) Date: 1999-01-22T00:00:00+00:00 List-Id: In article stt@houdini.camb.inmet.com (Tucker Taft) writes: > > adam@irvine.com wrote: > > : > function SideEffect (X: in out State) return Boolean; -- Invalid To be precise, the feature in the early drafts was *procedures* that returned values. (But of course we have a religious war every now and then about IN OUT parameters to functions.) > : To answer your question: yes, it was considered. In fact, I > : recall seeing essentially your proposal in early drafts of the Ada > : language (around 1980 or 1981), before the standard was finalized. > : I don't know why this feature was removed in the final > : version---perhaps someone can enlighten us? (I'm not saying I > : miss this feature; I prefer not to have variables buried in the > : middle of an expression changing their values, but that's just my > : personal preference.) > > You answered your own question. Many people "prefer not to have > variables buried in the middle of an expression change their values." > > Ada has consistently favored readability/understandability over saving > a few keystrokes. That characteristic certainly can be annoying at > times, though, but it tends to be pretty pleasant a week or two after > you write the code, and you are trying to remember how it works ;-) There's another factor that I just remembered this morning. In the early version that I recall, Ada had both functions and value-returning procedures; but functions were not allowed to have any side effects at all. I don't remember all the details, but I assume this means that, among other things, a function couldn't modify a global variable, nor could it call a procedure that could modify a global variable. I suppose this was part of the reason for providing value-returning procedures---to have something that behaves like a function but is allowed to have side effects. Fortunately, people realized that the no-side-effect rule for functions would be way too difficult to enforce, and was a bad idea besides. (Even if a function call appears "pure" to the outside world, it's useful for a function to be able to change the internal state for efficiency. If you have a function that searches a large binary tree for a key and returns a value, it might make sense in some applications for the function to store the key and value in a global variable, so that if the next search uses the same key, the tree doesn't have to be searched again. This principle was discussed in Meyer's _Object-oriented Software Construction_.) Anyway, if the no-side-effect rule for functions had to be dropped, then probably there was a lot less need for value-returning procedures. Just my guess as to one of the reasons why this feature was eliminated. -- Adam -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own