Skip to content

Separate "Methods" and "Extension Methods" sections #3941

@loic-sharma

Description

@loic-sharma

Problem

Currently dart doc mixes methods and extension methods in the same "Methods" section (example).

If the Flutter framework introduced 50+ extension methods on the Widget type, it would flood the Widget's methods with extension methods. It becomes difficult to find Widget's "real" methods.

Solution

Similar to how the "Static Methods" have a separate section (example), we should consider adding a separate section for "Extension Methods"

Activity

srawlins

srawlins commented on Dec 3, 2024

@srawlins
Member

Thanks for the suggestion. Methods and extension methods are currently integrated, intentionally, to avoid the converse problem: If you were looking for a method available on a class (you don't know that it's an extension method, and why should you?), it would become difficult to find the method.

Why should they be separated? Why would a user be looking for Widget's "real" methods?

loic-sharma

loic-sharma commented on Dec 4, 2024

@loic-sharma
Author

you don't know that it's an extension method, and why should you?

I don't think we should treat methods and extension methods like they're exactly the same. Unlike methods, extension methods might not be available depending on your imports. Separating the extension methods might help make this clearer.

it would become difficult to find the method.

Is that true? We already separate static methods, but I wouldn't say they're more difficult to find.

Why should they be separated?

In my opinion, the separate sections would organize the content better :)

srawlins

srawlins commented on Dec 4, 2024

@srawlins
Member

it would become difficult to find the method.

Is that true? We already separate static methods, but I wouldn't say they're more difficult to find.

Yes, I think so. If I am looking to call a method on an instance of a class, I look in the Methods section. Sometimes I'm thrown because it turns out I'm looking for a property (like Map.isEmpty for example). And It seems a little weird that operators are in their own list; they could be "alphabetically" in the Methods list.

I don't see static methods as related to instance methods at all; it kind of grates on me that we call them "methods" when they don't use an instance of the enclosing class as a receiver.

Unlike methods, extension methods might not be available depending on your imports.

I think it would be a disservice to "set aside" methods that might require an additional import. I can't think of a reason a user would be prefer to not use the method they we seeking, if it would require importing an additional library.

loic-sharma

loic-sharma commented on Dec 5, 2024

@loic-sharma
Author

I think it would be a disservice to "set aside" methods

I think this is the core of our disagreement. I personally like that properties and operators are separated, I find this makes the docs more organized. In my mind, these aren't "set aside" -- they're grouped together!

it kind of grates on me that we call them "methods" when they don't use an instance of the enclosing class as a receiver.

What would you call them instead? Personally, I'm ok with that name as it's a widely understood term that is easily understandable by newbies.


Side note: dart doc also separates classes and exceptions.

srawlins

srawlins commented on Dec 5, 2024

@srawlins
Member

What would you call them instead?

Static functions.

added
type-enhancementA request for a change that isn't a bug
area-web-designSomething a web designer interested in helping could do.
on Dec 6, 2024
bwilkerson

bwilkerson commented on Dec 16, 2024

@bwilkerson
Member

... it kind of grates on me that we call them "methods" when they don't use an instance of the enclosing class as a receiver.

It's a hold-over from Smalltalk, where classes are objects and class methods are actual methods whose receiver is the class.

... it's a widely understood term ...

I agree. I doubt that any of our users get confused enough by the term that it's actually worth changing it.

you don't know that it's an extension method, and why should you?

... Unlike methods, extension methods might not be available depending on your imports.

I think that's a valid point. It could also be confusing for users if they look at the current page and see a method on the class, try to use the method in their code, and are then told that the method doesn't exist (because it's an un-imported extension method).

Separating extension methods into a separate section is one solution, but as pointed out it might introduce other sources of confusion.

I don't claim to have a perfect solution, but one other possibility that comes to mind is to clearly annotate which methods are extension methods and where each extension method comes from (how to import it).

A more complex solution would be to have some filtering built in to the output so that a user could ask for subsets such as all methods, only non-extension methods, or maybe only non-inherited methods.

gbassisp

gbassisp commented on Dec 17, 2024

@gbassisp

Why should they be separated? Why would a user be looking for Widget's "real" methods?

They are a little bit like "sealed" method, given they are not part of the class definition and cannot be overridden. Implementing that method in a subclass would be like a "new" method (c# keywords in quotes for trying to be clear on what I mean).

Sorry if I'm saying a bunch of non-sense... 😅

added
P3A lower priority bug or feature request
on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-web-designSomething a web designer interested in helping could do.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pq@srawlins@loic-sharma@bwilkerson@gbassisp

        Issue actions

          Separate "Methods" and "Extension Methods" sections · Issue #3941 · dart-lang/dartdoc