On Wed, Sep 29, 2010 at 8:44 PM, Darren Duncan <dar...@darrenduncan.net> wrote:
> I would argue that naming accessors get/set is a bad idea, "set" in
> particular, because "set" would easily evoke thoughts of having something to
> do with "set" collection types and values.
That's a valid point . . .
> But regardless of whatever else you do, "set" for this purpose has got to
That's a much stronger statement, and I can't say I agree. The verb
"set" is so common in this context that it's practically de rigeur.
(getFoo/setFoo, getf/setf, __getattr__/__setattr__, getenv/setenv).
Other languages use set in this way without a corresponding get (csh,
VB, Postscript). Attribute accessors in general are very commonly
called "getters and setters", no matter what the actual name or syntax
happens to be.
You can certainly argue that "set" is confusing because of the data
type, but I don't think you can make a convincing case that it's so
bad it needs to be rejected out of hand. There's too much evidence to
But it's not universal, and there are alternatives. Of the ones you
mentioned, I would also probably pick "update" in the general case.
But if we're talking about implementing attribute assignments,
"assign" might be more logical.
Of alternatives you didn't mention, I like "put" - as pithy as "get"
and "set", with plenty of corresponding history (SmallTalk, POSIX,
Mark J. Reed <markjr...@gmail.com>