RE: [Newbies] A Question of Style
I like the second one; it explains your intention much better. Ron From: Tim Johnson Hi, I know the rules for naming accessor and setter methods. But what do I do when the accessor method needs a parameter? I'll try to provide an example. A vendor sells an item called #apple. If I want to get the vendor's price for that #apple, I use a method such as the following: VendorpriceOf: aSymbol Now, to make the setter method, I have followed this pattern: VendorpriceOf: aSymbol is: newPrice Does this follow traditional patterns? I'll admit I have read the first half of Smalltalk with Style but not the second. Should I instead make the setter method look like this: VendorsetPriceOf: aSymbol to: newPrice ? Thanks, Tim [PS - Thanks to everyone who has been helping me on here lately, I have been lax in responding. You all bring up some good ideas and tips.] ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Re: [Newbies] A Question of Style
El 3/30/07 2:58 PM, Ralph Johnson [EMAIL PROTECTED] escribió: Setting accessor methods are a time-honored exception. Could expand ? Are you saying what if we have foo should have setfoo: and getfoo: ? Is that is the case is a simple implementation... Edgar ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Re: [Newbies] A Question of Style
On Fri, 30 Mar 2007 10:12:15 -0800, Edgar J. De Cleene [EMAIL PROTECTED] wrote: El 3/30/07 2:58 PM, Ralph Johnson [EMAIL PROTECTED] escribió: Setting accessor methods are a time-honored exception. Could expand ? Are you saying what if we have foo should have setfoo: and getfoo: ? Is that is the case is a simple implementation... I believe he's saying: By the logic of using set to indicate setting a value, you should have setFoo: but when its an accessor method, using just foo: is the time-honored exception. ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
[Newbies] Re: A Question of Style
On Fri, 30 Mar 2007 18:22:22 +0200, Tim Johnson wrote: Hi, I know the rules for naming accessor and setter methods. But what do I do when the accessor method needs a parameter? I'll try to provide an example. A vendor sells an item called #apple. If I want to get the vendor's price for that #apple, I use a method such as the following: VendorpriceOf: aSymbol Now, to make the setter method, I have followed this pattern: VendorpriceOf: aSymbol is: newPrice I've seen the suggestions in other responses to this and I don't like them. Calling everything a setter/getter seems to be J-zeitgeist but, what you have here is a collection of prices, indexed by a symbolic key, rooted at instances of Vendor. Translated to Smalltalk language this is a variant of #at:put: VendorpriceAt: aSymbol put: newPrice Even more Smalltalk-ish, you'd have aVendor pricebook at: aSymbol put: newPrice People with an education in Smalltalk will immediately understand what's happening when seeing a piece of your code which sends #priceAt:put:, even in the absence of class comments :) /Klaus Does this follow traditional patterns? I'll admit I have read the first half of Smalltalk with Style but not the second. Should I instead make the setter method look like this: VendorsetPriceOf: aSymbol to: newPrice ? Thanks, Tim [PS - Thanks to everyone who has been helping me on here lately, I have been lax in responding. You all bring up some good ideas and tips.] ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners