4 ms·
By “setter”, I mean a mechanism by which code that is external to an object can gain unmediated access to one or more of the object’s mutable instance variables
by noblethrasher 9y ago
By “setter”, I mean a mechanism by which code that is external to an object can gain unmediated access to one or more of the object’s mutable instance variables.
The big idea is that the sender should not be able to assume that the message, `setFoo`, will have any particular effect with respect to the reciever’s state.
- probablybroken 9y agoIt sounds like you are referring to public properties.
- justincormack 9y agoIn languages like Lua you can always mediate what look syntactically like setters.
- DougBTX 9y agoAt least in C# terminology, a "setter" for a public property is mediated access, unmediated access would be a public field that can be set without invoking a setter method. Getters and setters in C# are method calls, like `setFoo` in Java, so can't be assumed to be simple, they can do anything any other method can do.
- noblethrasher 9y agoAs it turns out, C# is a language that I know extremely well; I'm aware that setters can have arbitrary code. But, here's the problem: A programming a language is medium for thought, which means that it promotes or prevents the occurrence of certain ideas. So, even though the compiler will accept any legal void-returning code within the inner braces of public Foo Bar { set { //Do stuff } } The fact that the client code is going to look like `Obj.Foo = whatever` will practically foreclose on all but a small subset of possibilities.
- dragonwriter 9y agoBut classical setters aren't setters then, because the access is mediated (the are, or are backed by, methods which could do anything.) Only public fields provide unmediated access.
- noblethrasher 9y agoPlease see my reply to a sibling comment: https://news.ycombinator.com/item?id=14255796 https://news.ycombinator.com/item?id=14255796