[squeak-dev] tim rants (was Re: The Trunk: ToolBuilder-Kernel-pre.122.mcz)

henry henry at callistohouse.club
Wed Apr 25 22:03:05 UTC 2018


Scala classes have implicit getter setters, just by defining the ivar. That seems related to class definitions inline using that syntax. Define the class and call the constructor then call the getter.

Sent from ProtonMail Mobile

On Wed, Apr 25, 2018 at 14:50, tim Rowledge <tim at rowledge.org> wrote:

>> On 25-04-2018, at 10:29 AM, Levente Uzonyi wrote: > > Why would you want to create private accessors when you can just access the variable directly? > Creating accessors for a variable that should not be accessed externally is bad practice IMHO. Exactly my point. The plausible reason for using a message to get an instvar is that there *might* be some testing for is nil, or empty etc that makes your code nicer - no seemingly random chunks of code referring to an ivar and having to test it , maybe incorrectly, scattered around. You can make an argument (not completely sure I'd agree with it) that using a message send as your normal style makes this cleaner - for plain instvars you just return them, for ones needing testing you do the testing etc. I guess it's true that having code where in some places you use the direct access and in others you have to use a message in order to make sure the ivar is set up correctly is messy and requires some detailed knowledge of the class. Hmm, yeah, maybe. The downside is the whole bad-C-programmer thing. We could probably do something terribly clever and make the compiler understand that if there is a method named appropriately (simplest choice is "the same as the variable name" but we could set any rule we want) then any place where the direct bytecode would normally be used is replaced by a magic bytecode that actually sends the message. It might even be something the Sista could do magic with. This likely-insane idea would make our code look the same but allow adding a "test and initialise etc" method that just gets used if needed. All this is just fluff though by comparison to not liking raw getter/setter methods being public. tim -- tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim A)bort, R)etry, I)nfluence with large hammer. @caesar.elte.hu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20180425/0d85a1aa/attachment.html>


More information about the Squeak-dev mailing list