Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!bbn!rochester!cornell!batcomputer!itsgw!steinmetz!uunet!pdn!alan From: alan@pdn.UUCP (Alan Lovejoy) Newsgroups: comp.lang.smalltalk Subject: Re: Is SELF a naughty OOP construct? Message-ID: <3313@pdn.UUCP> Date: 30 May 88 15:54:16 GMT References: <1620001@hplb29a.HPL.HP.COM> Reply-To: alan@pdn.UUCP (0000-Alan Lovejoy) Organization: Paradyne Corporation, Largo, Florida Lines: 54 In article <1620001@hplb29a.HPL.HP.COM> weeks@hplb29a.HPL.HP.COM (Gregory Weeks) writes: >I have a suspicion that the SELF construct may turn out to be the GOTO of >object-oriented programming. That is, it will be viewed as promoting >unsound code structure. However, I have no arguments to back up this >suspicion. > >Does anyone? SELF is necessary in ST80 because methods always have one unnamed argument: the receiver of the message. Because this argument is unnamed, it is always called self. This is an irregularity which makes abstracting over code that references SELF more difficult. For example, consider the following method: op: rightArg | temp | temp := rightArg foo. temp := temp bar: self. ^temp crunch To invoke this method, one must code: leftArg op: rightArg. Of course, leftArg must be an object of the class in which the method op: is defined. If rightArg is or is supposed to be of this same class, then one might expect to be able to code: rightArg op: leftArg. That is, it may be that op: is commutative (although the method as coded probably is not commutative). However, if rightArg is or is supposed to be of a different class, then you cannot code rightArg op: leftArg unless you define a method "op:" in rightArg's class. It would be nice if we could simply take a copy of the "op:" method we have already coded and add it to the instance methods of rightArg's class. Unfortunately, that won't work, becase of the SELF construct. Instead we must recode "op:" as follows: op: rightArg | temp | temp := self foo. temp := temp bar: rightArg. ^temp crunch Now we can code "a op: b" or "b op: a" with full commutivity in cases where a and b are not the same class. To summarize: SELF inappropriately forces algorithms to be dependant on which method argument is the special case otherwise known as the receiver of the message. -- Alan Lovejoy; alan@pdn; 813-530-8241; Paradyne Corporation: Largo, Florida. Disclaimer: Do not confuse my views with the official views of Paradyne Corporation (regardless of how confusing those views may be). Motto: Never put off to run-time what you can do at compile-time!