What's the maximum number of methods in an `interf...
# compiler
c
What's the maximum number of methods in an
interface
? Is it the same on all platforms?
m
JVM has a 64k method limit IIRC
Android has 64k/dex file limit. And trying not to cross that number for the whole app was a thing a long time ago
All in all, it's probably platform dependent
c
Yeah, hence the question. I think I'll reach maybe 2k, so hopefully I should still be very far from the limit
I'm a bit worried about IDE completion performance though 😅
m
That sounds... a lot. Although you're probably fine, handling a 2k list should hopefully be fast enough on modern hardware
e
JVM's 64k limit per class may actually a bit lower than that - while it is true that there can only be 64k methods defined, their names come from the constant pool, which is also limited to 64k, and is shared with plenty of other things in the class
💯 1
c
Still, if I reach a max of 1–2k, that should be far from the limit, right?
m
Only one way to find out ^^
I think technically you'd be fine
Whether the developper experience is going to be good is another question
My brain context window can probably not handle 2k methods
But I hear we should design for the robotic brains now
c
Only one way to find out ^^
sure, but that's the kind of thing that wrecks years of development if you discover it too late 😅
My brain context window can probably not handle 2k methods
The brain is very very good at filtering out information, and almost all of them will be convenience overloads, which the brain can easily ignore Now, whether it'll look good in the IDE completion popup, is a very different question.
e
for comparison, PHP has close to 4k top-level functions 😛
c
Oh, I wouldn't worry about top-level functions. My problem is that I rely on interface delegation a lot, so they all need to fit within whatever class ends up implementing multiple interfaces at the bottom.
e
if you might use default methods in your interfaces, consider the interplay with interface delegation. https://youtrack.jetbrains.com/projects/KT/issues/KT-18324/When-delegating-interface-implementation-default-methods-arent-overridden
c
@mbonnin as an example:
Copy code
User::rate set cond(
    condition = User::age gte 18,
    ifTrue = Product::rate, 
    ifFalse = 0.1,
)
Here, the
cond
method will have 24 overloads to account for all the combination of parameters you could give it. But as a developer, you only need to remember that there is a function named
cond
and what it does.
e
you'd have a lot fewer overloads if you used builder-style chains,
Copy code
User::rate set cond
    .condition(User::age gte 18)
    .ifTrue(Product::rate)
    .ifFalse(0.1)
c
True, and in this specific function the usability may be identical 🤔