42 ms·
What if my name is "anonymous user"? Anyway, primitive types in java is one of the reasons, why java has success. Try to do image processing or fast networking
by jkot 11y ago
What if my name is "anonymous user"?
Anyway, primitive types in java is one of the reasons, why java has success. Try to do image processing or fast networking, while each byte is represented as an object.
- masklinn 11y agoAn object is an interface, nothing precludes optimising representations either specifically (tagged pointers, unboxed values) or generally (collection strategies and JIT unboxing). The former being what C# does, its primitive types can still be interacted with as objects, you can even add new methods on `int`.
- david-given 11y agoI have an experimental and somewhat half-baked programming language where all types are anonymous; type names always refer to interfaces. It then does global type inference to decide whether the thing you're referring to is a primitive type or an object for the actual implementation. What this means is that at the semantic level, the language doesn't distinguish between objects and scalars, so avoiding the horrible schizophrenia that languages like C++ and Java do --- you can subclass an integer just as easily as you can anything else. Performance is really good, too, mostly. The downside is somewhat unpredictable behaviour due to invisible boxing and unboxing. e.g.: function complexExpression(x: int) { // do something expensive with x } complexExpression(4); complexExpression(numberlikeObject); The type inference will see that complexExpression() is being called by both a scalar and an object, which means that x needs to be implemented as an object pointer, and the literal 4 needs to be boxed. This means the calculations inside complexExpression() will end up being a lot more expensive due to boxing and unboxing overhead. I should readdress this at some point; it was a really nice thing to write code for. http://cowlark.com/cowbel/example.html http://cowlark.com/cowbel/example.html
- wtetzner 11y agoYou could specialize for primitives, e.g. under the hood generate complexExpression_int() and complexExpression_ref(). It wouldn't be too bad in terms of code size, because you only have to specialize primitives, and all reference types can share the same implementation.
- david-given 11y agoYes, that'd be the obvious thing to do, but I think right now it doesn't (I could be wrong; I haven't looked at the code for ages). I did at one point try to specialise everything. The results were hilarious... var a = cons(cons(cons(cons(empty, 1), 2), 3), 4); As the left-hand-side of each cons was a slightly different type, it ended up generating four different versions of the cons function!
- iopq 11y agoTry to do anything where each struct is represented as an Object... oh wait, in Java, it is!
- deleted 11y ago[deleted]