
65535 interfaces ought to be enough for anybody - kiyanwang
http://aakinshin.net/en/blog/dotnet/mono-and-65535interfaces/
======
ungzd
Android is worse — it limits number of _methods_ to 65535 (but has hacks to
workaround it)
[https://developer.android.com/studio/build/multidex.html](https://developer.android.com/studio/build/multidex.html)

~~~
throwawayish
A coworker mentioned that multidexing also take ages and uses huge amounts of
memory.

~~~
d33
Are there any legitimate use cases for that many methods?

~~~
vkou
Java's crippled generics, lack of tuple support, and lack of default
parameters encourage interface bloat in utility libraries.

Given how bloody good Java IDEs are (By which I mean to say - how good
IntelliJ is), the cognitive cost of this interface bloat is very low... Until
you start developing for Android.

~~~
monocasa
Wouldn't Java's crippled generics actually help reduce the method count since
due to type erasure they're all the same method at the VM level anyway?

~~~
josefx
On the one hand yes, on the other hand Java also generates Bridge methods when
you implement a generic interface. A MyType implementing Comparable<MyType>
will contain a compareTo( MyType ) method and a generated compareTo(
Comparable ) bridge method.

It is more likely that generated classes, countless getters and setters and a
tendency to small methods has a higher impact.

------
amelius
Also:

65535 tcp-ports ought to be enough for anybody [1]

65534 hardlinks ought to be enough for anybody [2]

[1] [http://stackoverflow.com/questions/113224/what-is-the-
larges...](http://stackoverflow.com/questions/113224/what-is-the-largest-tcp-
ip-network-port-number-allowable-for-ipv4)

[2] [http://unix.stackexchange.com/questions/5629/is-there-a-
limi...](http://unix.stackexchange.com/questions/5629/is-there-a-limit-of-
hardlinks-for-one-file)

~~~
sixothree
I find it extremely awkward that we actually use numbers for ports. Port 80 is
typically used for HTTP, but there's nothing preventing another application
from using port 80. Why not call the port "HTTP" instead. Better yet why not
give it an integer range of ports to go along with the naming - Eg MyApp[1],
MyApp[2].

If you want to hide a port from being probed then give it a GUID as a name. No
more port scans.

~~~
overgard
Packet size is important. If your ports are strings, every packet gets that
much bigger. Nobody wants slow internet for programming convenience.

~~~
revelation
It's not even convenient. Strings are one of the biggest scourges of any
programming language out there. Giant mess in basically every language until
Java got it somewhat right, and even then don't forget your equals...

C# (.NET) could be the forerunner if only they had not gone with UTF16, but
then it's only with hindsight that we can point out UTF8.

~~~
Retra
Strings are only a problem because they are being treated as text. In this
case, they would simply be treated as binary identifiers, so there is no
problem. The raw bytes would do just as well for this kind of thing.

~~~
jmiserez
Only if they are fixed length. If you used variable length strings in packet
headers things would get complicated.

But if you're fine with fixed-length strings, you could just as well use all
those bits to represent a number instead.

------
janstenpickle
[http://www.catb.org/jargon/html/Z/Zero-One-Infinity-
Rule.htm...](http://www.catb.org/jargon/html/Z/Zero-One-Infinity-Rule.html)

------
Beltiras
After yesterdays posting of the list of incorrect assumptions programmers make
about the world I put it into my daily web routine to visit the page and read
one list per day till done.

~~~
dsacco
Do you have a link to this? I missed it and would like to read it.

 _EDIT_ : Think I found it?
[https://news.ycombinator.com/item?id=13640409](https://news.ycombinator.com/item?id=13640409)

~~~
Beltiras
[https://github.com/kdeldycke/awesome-
falsehood](https://github.com/kdeldycke/awesome-falsehood)

------
JoeAltmaier
File this under 'premature optimization bites after 12 years'.

~~~
astrobe_
Why makes you say it is "premature"? Isn't it possible that they hit that
limit because the project is a monolithic monster? Or because it uses
libraries that waste those resources?

------
to3m
Any time you have a 16-bit count, it won't be enough. It's a dangerous size...

~~~
jandrese
The same is true of 32 bit numbers. 64 bits might finally be enough. _crosses
fingers_

~~~
paulddraper
Well, for _counts_ 32 bits is enough, unless you count something really small,
like every individual byte in something.

And for _counts_ 64 bits should be enough, since it's 20 billion billion.

~~~
duskwuff
For counts of things you have in memory, 32 bits is usually enough -- even if
each thing is just 8 bytes, 2^32 of those objects would require 32 GB.

~~~
jandrese
32GB isn't an exceptional amount of memory these days.

~~~
duskwuff
Sure -- but it is an exceptional amount of memory to use for tiny objects like
those. If you're working with four billion objects at a time, they're probably
more substantial than eight bytes.

~~~
detaro
Or you spent a lot of effort to get them to 8 bytes or even smaller, to fit as
many of them as possible in memory. See use-cases like time-series/analytics
databases, point-clouds, simulations with many elements...

------
antfarm
16 bits can represent 65536 different values, not 65535.

~~~
StringEpsilon
0 Interfaces 1 Interface ... 65535 Interfaces

~~~
recursive
I can't tell if you're joking, but when you're counting a quantity, you don't
start from 0.

~~~
surye
Why not? Is having zero interfaces not distinct from having one interface?

~~~
recursive
It is. But when you have one interface, that interface can be given the number
0. So you have a total of 1 interface, even though you've only counted up to
0.

Edit: I misunderstood. I'll leave the comment up. But I originally interpreted
the story as meaning that each interface needed to be assigned an unsigned
16-bit id, which allows for a total of 65536. That was just inference on my
part though. It literally says that more than 65535 are not allowed.

------
rdtsc
This sounds familiar. Mono worked for me until it didn't. And it would be some
corner case like timing and sockes, or HTTP connection issues. By that time we
already bought into it and so I was running around opening a huge black box
trying to figure out the internals.

------
Grollicus
Remember how we laughed about visual basic which supports just 65536 different
variable names?

~~~
tempodox
How many of these would fit into 640 kB of RAM, anyway?

~~~
adrianN
you need 16 bits per name, so 2^20 bits. That fits nicely into about 20% of
your 640kB of RAM.

------
tonyg
It's almost as if programming languages should support integers, rather than
just machine words. Or, put differently: Fixed-Width "Integers" Usually
Harmful.

------
ungzd
> A short fact about .NET: if you have an interface IFoo<T>, the runtime
> generates a separate method table per each IFoo<int>, IFoo<double>,
> IFoo<bool>, and so on.

In Java you have to do the same manually:
[https://docs.oracle.com/javase/8/docs/api/java/util/stream/S...](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#mapToInt-
java.util.function.ToIntFunction-) wow such polymorphism much ad-hoc

