[webkit-dev] When to use "auto"? (I usually consider it harmful)

Filip Pizlo fpizlo at apple.com
Thu Jan 2 14:48:42 PST 2014


I think that this article is one of many great examples of arguments in favor of less explicit typing.  These lines of reasoning are often used by proponents of both dynamic languages (like Ruby) and type-inferred languages (like ML or Haskell).  C++'s auto is almost exactly like what ML and Haskell have and it's not surprising to me to see bloggers rehash these decades-old arguments.

But what I like about how we use C++ in WebKit is that we avoid writing English comments, and try to document our code using types, function names, and variable names.  Types are a particularly powerful form of documentation because it is checked by the compiler.  I think that the main source of my distaste for using auto everywhere is that it takes away our compiler-checked documentation.

The article seems to suggest that we should say:

    auto x = type { expression };

when we want documentation.  But this is more noisy than saying:

    type x = expression;

I don't think that the auto-based type expression suggested by the article has any merits over the traditional variable type.

-Filip


On Jan 2, 2014, at 2:31 PM, Brent Fulgham <bfulgham at apple.com> wrote:

> Hi Adam,
> 
> On Jan 2, 2014, at 2:08 PM, Adam Roben <aroben at webkit.org> wrote:
> 
>> I found http://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/
>> very persuasive in my thinking about when to use auto.
> 
> I think this does a much better job of explaining the benefits of ‘auto’ than I was able to come up with.
> 
> -Brent
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140102/b2d7b291/attachment.html>


More information about the webkit-dev mailing list