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

2014-01-02 Thread Geoffrey Garen
Hi folks. Recently, I’ve seen patches go by using the C++11 “auto” keyword. For example, let me pick on Andreas: http://trac.webkit.org/changeset/161143 +auto newRenderer = textNode.createTextRenderer(style); +ASSERT(newRenderer); …. +

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

2014-01-02 Thread Filip Pizlo
On Jan 2, 2014, at 1:12 PM, Geoffrey Garen gga...@apple.com wrote: Hi folks. Recently, I’ve seen patches go by using the C++11 “auto” keyword. For example, let me pick on Andreas: http://trac.webkit.org/changeset/161143 +auto newRenderer = textNode.createTextRenderer(style); +

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

2014-01-02 Thread Dan Bernstein
On Jan 2, 2014, at 1:12 PM, Geoffrey Garen gga...@apple.com wrote: Hi folks. Recently, I’ve seen patches go by using the C++11 “auto” keyword. For example, let me pick on Andreas: http://trac.webkit.org/changeset/161143 +auto newRenderer = textNode.createTextRenderer(style); +

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

2014-01-02 Thread Alexey Proskuryakov
02 янв. 2014 г., в 13:12, Geoffrey Garen gga...@apple.com написал(а): I think an appropriate style guideline for “auto” would say something like: - Use “auto to declare a disgusting templated iterator type in a loop - Use “auto… - to define a template-dependent return type in a class

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

2014-01-02 Thread Brendan Long
On Thu, 2014-01-02 at 13:12 -0800, Geoffrey Garen wrote: I think an appropriate style guideline for “auto” would say something like: - Use “auto to declare a disgusting templated iterator type in a loop - Use “auto… - to define a template-dependent return type in a class template - In

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

2014-01-02 Thread Filip Pizlo
On Jan 2, 2014, at 1:40 PM, Dan Bernstein m...@apple.com wrote: On Jan 2, 2014, at 1:12 PM, Geoffrey Garen gga...@apple.com wrote: Hi folks. Recently, I’ve seen patches go by using the C++11 “auto” keyword. For example, let me pick on Andreas:

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

2014-01-02 Thread Brent Fulgham
On Jan 2, 2014, at 1:54 PM, Filip Pizlo fpi...@apple.com wrote: I think the goal should be that if you do introduce a temporary variable for some reason, then being explicit about its type is better. Consider that in your second example, there might be 200 lines of code between the call to

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

2014-01-02 Thread Adam Roben
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. -Adam ___ webkit-dev mailing list webkit-dev@lists.webkit.org

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

2014-01-02 Thread Filip Pizlo
On Jan 2, 2014, at 1:59 PM, Brent Fulgham bfulg...@apple.com wrote: Hi, On Jan 2, 2014, at 1:12 PM, Geoffrey Garen gga...@apple.com wrote: +auto newRenderer = textNode.createTextRenderer(style); +ASSERT(newRenderer); …. +parentRenderer-addChild(newRenderer.leakPtr(),

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

2014-01-02 Thread Geoffrey Garen
I think this use of “auto” is net harmful. I disagree. I think the use of auto is an improvement, because it makes it less likely that we have something like the following: int wrong = something.get64BitInt(); // potential truncation This argument is a red herring for two reasons: (1)

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

2014-01-02 Thread Geoffrey Garen
We tend to avoid local write-once-read-once local variables, i.e. we tend to prefer { setSize(optimalSize()); } to { CGSize newSize = optimalSize(); setSize(newSize); } But the up- and down-sides of this are the same as those of using auto. I think I basically agree

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

2014-01-02 Thread Geoffrey Garen
What do you think about these examples? auto failureCallback = [promiseWrapper]() mutable { promiseWrapper.reject(nullptr); }; Here I think auto is good because the type is disgusting to write out by hand, and because the type is clearly visible on the right hand side of

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

2014-01-02 Thread Brent Fulgham
Hi Adam, On Jan 2, 2014, at 2:08 PM, Adam Roben aro...@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’

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

2014-01-02 Thread Filip Pizlo
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

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

2014-01-02 Thread Brent Fulgham
Hi Filip, Coming back to your earlier example: auto newSize = optimalSize(); vs: CGSize newSize = optimalSize(); If I understand your argument, you feel that the explicit CGSize declaration helps the reader because it makes the return value of optimalSize() explicit. However, that

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

2014-01-02 Thread Geoffrey Garen
One interesting point in this article, which I tend to agree with, is that it seems generally appropriate to use “auto” in any line of code that already conveys type. For example: (1) Lambda, as pointed out by Alexey: auto failureCallback = [promiseWrapper]() mutable {

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

2014-01-02 Thread Filip Pizlo
On Jan 2, 2014, at 2:55 PM, Brent Fulgham bfulg...@apple.com wrote: Hi Filip, Coming back to your earlier example: auto newSize = optimalSize(); vs: CGSize newSize = optimalSize(); If I understand your argument, you feel that the explicit CGSize declaration helps the reader

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

2014-01-02 Thread Karen Shaeffer
On Thu, Jan 02, 2014 at 01:12:46PM -0800, Geoffrey Garen wrote: Hi folks. Recently, I’ve seen patches go by using the C++11 “auto” keyword. For example, let me pick on Andreas: http://trac.webkit.org/changeset/161143 +auto newRenderer = textNode.createTextRenderer(style); +

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

2014-01-02 Thread Ryosuke Niwa
On Thu, Jan 2, 2014 at 4:12 PM, Geoffrey Garen gga...@apple.com wrote: I think an appropriate style guideline for “auto” would say something like: - Use “auto to declare a disgusting templated iterator type in a loop - Use “auto… - to define a template-dependent return type in a class

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

2014-01-02 Thread Maciej Stachowiak
On Jan 2, 2014, at 2:48 PM, Filip Pizlo fpi...@apple.com wrote: 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