[cfe-dev] C++11 reverse iterators (was C++11 is here)
David Chisnall
David.Chisnall at cl.cam.ac.uk
Mon Mar 3 10:13:18 PST 2014
On 3 Mar 2014, at 17:48, Chris Lattner <sabre at nondot.org> wrote:
> That's a very objective-c thing to do :-), they use the pattern foo() and setFoo() for the getter and setter, respectively (and the naming is baked into the property model). I don't feel strongly against it, but we pretty consistently use the Java style 'get' prefix everywhere else.
The Objective-C (technically, OpenStep) convention is to use getFoo when you provide a buffer into which the thing will be put, which isn't the case here. My reason for proposing foo() instead of getFoo() is that getFoo(), to me, implies that now you have a foo that you can hang on to for a bit, whereas the object returning the reverse iterators is intrinsically a transient thing. You don't want people doing:
auto args = foo.arguments();
And then later doing:
for (auto arg : args)
...
While this may be a valid thing to do, determining whether it actually is requires some thought. I would be more inclined to expect it to unconditionally work if the method were called getArguments() than if it is called arguments(), but that may be personal bias.
The only places where the C++ standard library uses get (from my memory, may be completely wrong) are when there is some notion of ownership transfer. When referring to internal properties of an object, the name is undecorated (see the begin() and end(), not get_begin(), get_end(), that are the original cause of this discussion...)
David
More information about the cfe-dev
mailing list