5 ms·
Unlike Java, Go doesn't have to worry about bytecode backwards compatibility. That was the main issue that had them reaching for type erasure. Take a look at
by monocasa 8y ago
Unlike Java, Go doesn't have to worry about bytecode backwards compatibility. That was the main issue that had them reaching for type erasure.
Take a look at C# which added it without many issues (because they were willing to break back compat of their bytecode). Go fits this model a whole lot better.
- enitihas 8y agoDid C# really break backwards compatibility of their bytecode? What I understand is that C# generic and non generic APIs are completely different, and are not inter operable.
- kjeetgill 8y agoYea from the wording I think they mean you can either break backwards compatibility or "fork the world". In Java's case, old bytecode using Map would correctly work with change to Map <K, V>. C# introduced a new set of collections I believe.
- mohaine 8y agoNot sure on the first part but the second part is true. When there is a C# class that both has and doesn't have type information, they are actually completely different classes that just happen to share a base name. This really made it painful when they first added generics. If you used generic containers but wanted to call into a library that predated it you hand to transform your data in/out of all the calls to the library. In Java land you didn't have to do anything other then a blind cast on the out side which doesn't even have a runtime penalty. Long term the C# way was probably better but then they didn't have nearly as robust of a library ecosystem when they added generics.
- monocasa 8y agoYeah, IIRC they added the "constrainted." instruction prefix. It's a prefix to the callvirt instruction that constrains the the underlying call to the specified type, allowing runtime generic type decisions/exceptions rather than only compile time decisions like Java.
- bunderbunder 8y agoTo the first - yes, the version of .NET that introduced generics broke bytecode backward compatibility. Stuff compiled for .NET 1.0 will not run on the CLR for 2.0 and later. In practice, this wasn't a big deal; maintainers just shipped two different versions of their packages, and you'd download the one you wanted. To the 2nd - The concrete types are separate, but they fit into a common interface hierarchy, so, at a source code level, they're plenty interoperable. For example, the (non-generic) IEnumerable interface has a Cast<T>() extension method that will convert it to a (generic) IEnumerable<T>. IEnumerable<T>, for its part, simply inherits IEnumerable. In general, I actually like using those conversion methods for downcasting, because it gives a clearer indication of when I'm in a danger zone - for example, converting a non-generic list to a generic list might fail if the non-generic list contains a mix of different types of object. Java's situation feels less predictable to me, as this article illustrates fairly well. A few keystrokes for the sake of safer code is a dandy tradeoff in my book.
- teh_klev 8y ago> Stuff compiled for .NET 1.0 will not run on the CLR for 2.0 and later That's not true. (Mass shared hoster kinda guy here) when we pushed a bunch of customers code compiled for .NET 1.0/1.1 over to hosting environments with only CLR 2 available, their code ran just fine. These were .NET 1.0/1.1 assemblies. There are some edge cases where stuff could break, say when doing reflection or emitting your own IL, but that for most LOB web hosted apps was pretty rare. I did in fact marvel how backwards compatible CLR 2 was when it first shipped.
- pjmlp 8y agoThe missing part every time this story gets told, is that Microsoft already had a generics implementation ongoing being lead by Don Syme of F# fame. They just decided to release 1.0 without generics, instead of waiting for it to be 100% ready. As Don clearly describes on his blog.
- monocasa 8y agoSure, totally. In fact, I'm a big fan of how Microsoft does versioning, supporting previous versions, but releasing major versions with backwards incompatible changes. You see this in DirectX, and IMO, that's why we're talking about DirectX and Vulkan, rather than AZDO OpenGL these days. It really gives you an opportunity to clean up the cruft.
- pjmlp 8y agoYeah, although I think they missed an opportunity to move beyond "only C goes" mindset at Khronos.
- majewsky 8y agoIs there any language besides C that's not a complete pita to generate FFI bindings for?
- bunderbunder 8y agofortran?
- pjmlp 8y agoThere are many ways to define APIs, we don't need to struggle ourselves only to C. Metal uses Objective-C/Swift, with shaders in C++14. The Objective-C runtime can be used as FFI. DirectX, uses COM with HLSL (a C++ subset). Likewise any COM or .NET (via RCW) aware language can talk to it. One of the reasons OpenCL lost to CUDA was being stuck with C, while CUDA offered C, C++, Fortran and any additional language that could target PTX. Which was what eventually made them come up with SPIR and later SPIR-V. NVN and LibCGNM are also based on C++ and C++ inspired shader languages. All modern OO, with nice SDKs that handle font, texture, materials, maths, GPGPU debugging.
- pron 8y ago> added it without many issues Except for the fact that all CLR languages must adopt the same variance model, enforced by the runtime (or choose not to interoperate well).
- monocasa 8y agoSure, but in context Go doesn't have that issue. Go's compiler only supports Go in a more or less statically linked binary.
- pron 8y agoGo doesn't have this issue because there aren't other languages running on that runtime. If there were (and you wanted an interop of those languages with Go so that you could use Go libraries), then you'd have this issue regardless of the fact that the runtime is linked with the image.
- deleted 8y ago[deleted]
- alexeiz 8y ago> Take a look at C# which added it without many issues I wouldn't say "without many issues." It took a major surgery in the CLR codebase to add generics. The difference between CLR 1.1 without generics and CLR 2.0 with generics was huge. No area of code was untouched.
- mnd999 8y agoExcept they didn’t - they introduced annotations at the same time and bumped the class file version for that.
- jeremyjh 8y agoChanging the class file doesn't necessarily break backwards compatibility. Are you saying a 1.4 JVM couldn't run 1.3 bytecode?
- mcculley 8y agoGo doesn’t have an ABI? Does every library ship only as source code? I didn’t know that. I was thinking of more fundamental changes to Java idiom and the standard library had generics been part of the design (e.g., how arrays work).