Why does the explicit api mode require me to annot...
# announcements
p
Why does the explicit api mode require me to annotate functions of interfaces with a visiblity? Is anything but public even valid on interfaces?
j
I didn't tried, but maybe you can have private functions with a default implementation. And a public one with a default implementation which use the private one.
p
It’s possible to have internal interfaces
p
@pablisco No, that doesn't compile:
Copy code
public interface MyInterface{
  internal fun hello()
}
p
ah, missread the original question, my bad. Yeah, the visibility of the functions should inherit from the interface. You are right, that’s a bit odd then 🤔
e
Because it is an explict mode
y
And also IIRC there's some plans to support a form of private methods on interfaces or something along those lines
c
i disabled explicit api mode again because it made the code look so verbose. if it is meant to be a good default for most libraries then it is a bit too verbose imo
e
There might be some form of less-visible interface members in the future, but that's irrelevant.
The explicit mode is primary targeted for stable library maintainers that need to be constantly reminded when they edit any piece of their code which parts represents their public API surface.
p
To us our gradle modules are libraries
☝️ 1
We have lots of them and we want to carefully think about visibility
e
Moreover, a stable library usually has tons of documentation, so when you see a line
fun foo()
somewhere, it is not immediately clear whether it is public or not, since it will be preceded by pages and pages of text
In a such a library an extra
public
does not add much verbosity
p
Its just too much noise on interfaces
I mean it's not that it's consequent in other places. Here we need a public on every function of an interface where only public is allowed in the first place
p
I think there is potential use cases for internal functions in an interface as we may have certain functionality that we only want to access internally but only expose part of this functionality, in which case the public “verbosity” would be granted 🙂
p
But then for data class properties I get no warning when I accidentally expose a property I didn't mean to.
e
That's explicit, though. Now as I library maintainer I don't have to remember about the context.
We made an exception for data class props after revieiwing our code.
They are usually dense and don't have much docs.
p
Maybe we could have this configurable if there is demand for eliminating such restriction
p
With the same logic you apply to interfaces you can argue that this is necessary on overwritten methods too.
e
That've been a lot of design discussions on specific rules and surely there are lots of tradeoffs. There's no way to define some clearcut rules that are great in everybody's minds. Needs compromises.
p
Or configuration options
e
Maybe yes, maybe not. Too much configuration has its problems, too (maintenance, complexity). The very concept of having a new special mode in the language was quite controversial in itself, let alone making it configurable.
e
Quoting @Javier:
I didn't tried, but maybe you can have private functions with a default implementation. And a public one with a default implementation which use the private one.
This is possible, so this:
Here we need a public on every function of an interface where only public is allowed in the first place
is not correct.
👍 2