Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Group Methods or Classes #84

Open
norswap opened this issue Jul 4, 2016 · 9 comments
Open

Suggestion: Group Methods or Classes #84

norswap opened this issue Jul 4, 2016 · 9 comments
Labels
enhancement An issue for a feature or an overall improvement plugin idea

Comments

@norswap
Copy link

norswap commented Jul 4, 2016

Would it be possible to create groups of methods and/or classes in a package, for the purpose of documentation?

Rationale: the documentation pages can get quite long, and there is often a logical grouping to be made. At the same time, one does not necessarily want to split the methods between packages and require extra imports.

Being able to require that top-level methods and classes be grouped per file for certain files (maybe specify this as a file-scope annotation?) would be a great start.

@yole
Copy link
Contributor

yole commented Jul 5, 2016

If there is a logical grouping of entities in your code, why deprive those who work with your code from access to that grouping, and present it only in the documentation?

I don't see how, with IntelliJ's import management features, requiring extra imports is a problem at all. You don't need to write them, and you don't need to see them.

@yole yole closed this as completed Jul 5, 2016
@norswap
Copy link
Author

norswap commented Jul 5, 2016

If there is a logical grouping of entities in your code, why deprive those who work with your code from access to that grouping, and present it only in the documentation?

They wouldn't be deprived of it, if the methods are grouped inside the same file, or appear sequentially in the code separated by some form of heading comment (e.g., // ----- My Section ------).

I don't see how, with IntelliJ's import management features, requiring extra imports is a problem at all. You don't need to write them, and you don't need to see them.

There is a cognitive dissonance here with the fact that everything in the standard library is imported by default (unlike in Java).

Furthermore, if you consider a library that works with 3 or 4 "kinds" of objects, of which there are many variants. I would group those into categories, and you suggest to fit these categories into packages. So now each time I use my library, I must import things from these 4 packages. It's hardly insurmountable, but if I'm going to do it every time, that looks like a blatant DRY violation.


For an example of why this would be beneficial, consider https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/. I don't consider the laundry list of methods at the bottom to be especially user friendly. It would pay to split it a few sections: one for accessing elements of the list, one for filtering or taking subsets of the list, one for conversions, one for sorting, ...

@superbobry
Copy link

Here's a good example of how useful grouping can be for libraries with large number of functions. It isn't from the Java world, but it illustrates the point nonetheless.

@yole
Copy link
Contributor

yole commented Jul 5, 2016

They wouldn't be deprived of it if they looked at the source code of your library. However, they wouldn't see any of this structure if they used regular IDE features such as code completion to explore its API.

The main reason why most of the standard library is imported by default (actually not everything - e.g. kotlin.comparators isn't imported by default) is that the split of the standard library into packages happened very late in the development of Kotlin 1.0, and we wanted to minimize the impact on existing applications.

I agree that the list of extension functions for List is kind of hard to read, but given that those extension functions are declared in many different places, a file-based grouping wouldn't help much. A better solution would be a tag such as @group that could be applied to the doc comments of different functions, regardless of where they are declared.

@yole yole reopened this Jul 5, 2016
@kamildoleglo kamildoleglo added the enhancement An issue for a feature or an overall improvement label Sep 13, 2019
@Kordyjan Kordyjan added this to the Post-Stable milestone Sep 1, 2020
@aajtodd
Copy link

aajtodd commented Apr 29, 2021

any status on this? Is it currently possible as a custom plugin?

@kamildoleglo
Copy link
Contributor

Yes, certainly possible with a custom plugin, however no work has been done

@vincentsong
Copy link

Also looking for this feature

@aajtodd
Copy link

aajtodd commented Feb 24, 2022

Is there an example or any direction on how we could do this with a custom plugin?

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Feb 25, 2022

Hi @aajtodd

Dokka has some documentation on plugin development that can be found here: https://kotlin.github.io/dokka/1.6.10/developer_guide/introduction/

As for examples of how to actually group methods/classes together, I think it depends on what exactly you want to do, but you can have a look at SameMethodNamePageMergerStrategy. As can be concluded from the name, it merges methods that have the same name and puts them on the same page :) An example of such a page for kotlinx.serialization here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An issue for a feature or an overall improvement plugin idea
Projects
None yet
Development

No branches or pull requests

8 participants