Bug 137728 - Have offsetFromContainer() / offsetFromAncestorContainer() take a RenderElement&
Summary: Have offsetFromContainer() / offsetFromAncestorContainer() take a RenderElement&
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-14 19:25 PDT by Chris Dumez
Modified: 2014-10-15 20:18 PDT (History)
6 users (show)

See Also:


Attachments
Patch (33.50 KB, patch)
2014-10-14 19:35 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (33.79 KB, patch)
2014-10-14 20:12 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (33.83 KB, patch)
2014-10-14 21:17 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2014-10-14 19:25:10 PDT
Have offsetFromContainer() / offsetFromAncestorContainer() take a RenderElement& instead of a RenderObject*. The argument passed is never null and the type should be a RenderElement as the argument is a container.
Comment 1 Chris Dumez 2014-10-14 19:35:59 PDT
Created attachment 239840 [details]
Patch
Comment 2 Chris Dumez 2014-10-14 20:12:33 PDT
Created attachment 239843 [details]
Patch
Comment 3 Benjamin Poulain 2014-10-14 21:10:42 PDT
Comment on attachment 239843 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=239843&action=review

rs=me

> Source/WebCore/rendering/RenderBox.cpp:1915
> +    auto* container = this->container(repaintContainer, &containerSkipped);

IMHO, "auto" is bad here, the type is 100% non obvious.

> Source/WebCore/rendering/RenderBox.cpp:1964
> +    auto* container = this->container(ancestorToStopAt, &ancestorSkipped);

ditto

> Source/WebCore/rendering/RenderBoxModelObject.cpp:2640
> +    auto* container = this->container();

ditto

> Source/WebCore/rendering/RenderObject.cpp:1874
> -        auto nextContainer = currContainer->container();
> +        auto* nextContainer = currContainer->container();

gosh I hate auto sometimes... It is just making code hard to follow :(
Comment 4 Chris Dumez 2014-10-14 21:14:47 PDT
Comment on attachment 239843 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=239843&action=review

>> Source/WebCore/rendering/RenderBox.cpp:1915
>> +    auto* container = this->container(repaintContainer, &containerSkipped);
> 
> IMHO, "auto" is bad here, the type is 100% non obvious.

I think Darin prefers auto* in this case because this way it always uses the same type returned by container(). For e.g., it is quite common for people to assign to a RenderObject* even though the function returns a RenderElement* nowadays. That said, I don't feel strongly either way. In this case, I do agree the type is not obvious.
Comment 5 Chris Dumez 2014-10-14 21:17:36 PDT
Created attachment 239846 [details]
Patch
Comment 6 WebKit Commit Bot 2014-10-14 22:01:38 PDT
Comment on attachment 239846 [details]
Patch

Clearing flags on attachment: 239846

Committed r174722: <http://trac.webkit.org/changeset/174722>
Comment 7 WebKit Commit Bot 2014-10-14 22:01:44 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Darin Adler 2014-10-15 09:22:17 PDT
At some point we should talk this style point. I agree that the type is non-obvious, but I don’t agree that is a problem. Why does the type need to be obvious?
Comment 9 Benjamin Poulain 2014-10-15 13:59:51 PDT
(In reply to comment #8)
> At some point we should talk this style point. I agree that the type is non-obvious, but I don’t agree that is a problem. Why does the type need to be obvious?

For me it is all about reading/reviewing/understanding code. I would rather spend 5 minutes making the code explicit when writing it than creating cognitive load for anyone reading the code.

I like that "auto" always get the right type even after refactoring of disconnected parts of the code but the code readability suffers so much that the cost far outweigh the gains.
Comment 10 Darin Adler 2014-10-15 16:21:39 PDT
(In reply to comment #9)
> (In reply to comment #8)
> > At some point we should talk this style point. I agree that the type is non-obvious, but I don’t agree that is a problem. Why does the type need to be obvious?
> 
> For me it is all about reading/reviewing/understanding code. I would rather spend 5 minutes making the code explicit when writing it than creating cognitive load for anyone reading the code.

What I’m not clear on is whether this cognitive load is an intrinsic result of this coding style, or a result of the fact that we are accustomed to the other style. I often don’t need to know the types of things; the names of the functions we are calling on them seem sufficient. Every time I see an explicit type name such as RenderObject I wonder if the type is correct.

We do not see the type names of function results or data members each time we use them. Is there some reason we need these type names urgently for local variables, but not those other things?
Comment 11 Benjamin Poulain 2014-10-15 20:18:07 PDT
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > At some point we should talk this style point. I agree that the type is non-obvious, but I don’t agree that is a problem. Why does the type need to be obvious?
> > 
> > For me it is all about reading/reviewing/understanding code. I would rather spend 5 minutes making the code explicit when writing it than creating cognitive load for anyone reading the code.
> 
> What I’m not clear on is whether this cognitive load is an intrinsic result of this coding style, or a result of the fact that we are accustomed to the other style. I often don’t need to know the types of things; the names of the functions we are calling on them seem sufficient. Every time I see an explicit type name such as RenderObject I wonder if the type is correct.
> 
> We do not see the type names of function results or data members each time we use them. Is there some reason we need these type names urgently for local variables, but not those other things?

Funny you mention that, you always have me remove my local variables :) I do use local variables to make types explicit whenever I feel that it clarifies the flow.

Let's talk about this face to face when you have 5 minutes, this is not the best forum.