On 06/02/2015 12:58 PM, smaug wrote:
> So, I'd like to understand why people think 'auto' is a good thing to use.
> (bz mentioned it having some use inside bindings' codegenerator, and
> sure, I can see that being rather
> valid case.)

One common "auto" usage I've seen is for storing the result of a
static_cast<>.  In this scenario, it lets you avoid repeating yourself
and makes for more concise code.  I don't think there's much danger of
fragility in this scenario (unlike your refcounting example), nor is
there any need for a reviewer/code-skimmer to do research to find out
the type -- it's still right there in front of you. (it's just not
repeated twice)

For example:
  auto concretePtr = static_cast<ReallyLongTypeName*>(abstractPtr);

Nice & concise (particularly if the type name is namespaced or otherwise
really long).  Though it perhaps takes a little getting used to.

(I agree that mixing auto with smart pointers sounds like a recipe for
fragility & disaster.)

~Daniel


_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to