First is the abandoning of covariance and contravariance, the property which guarantees sensible subtyping: that bytes are also integers, and integers are also objects, extending systematically to container types and functions.
-
-
Prikaži ovu nit
-
Without garbage collection, offering an array of bytes where an array of integers is required requires stack-allocating an array of integers and converting each byte to an integer every time a subtype is used in place of an actual type. This is so absurd that it’s not done.
Prikaži ovu nit -
So now when we want to recover performance, we need to write all containers and their operations using an increasingly elaborate set of templates or generic functions, which the compiler must specialize for each type at significant cost. This is what C++ and Rust do.
Prikaži ovu nit -
Or we can create a very clunky wrapper like array_of_anything that is used wherever generic types are required, which manually casts and converts values among types dynamically each time it’s accessed. Java generics did this and they were awful.
Prikaži ovu nit -
But if we have garbage collection, we can store our large data structures once with whatever type is required, then dynamically create wrappers that reinterpret it as any subtype that’s required. We pay the cost of GC and indirect control flow for accessors but that’s all.
Prikaži ovu nit -
Unfortunately, most languages missed this opportunity. The C family including C# and Java are overly imperative and lost variance due to wrongly-scoped mutability. And functional languages have generally chosen type systems lacking subtypes, covariance, and contravariance.
Prikaži ovu nit
Kraj razgovora
Novi razgovor -
-
-
Strong disagree. C++ is slow for reasons that are entirely fixable if you change the compilation model. Rust is slow for some of those reasons, plus some others. I have to say I don't understand, though, what your "array of integers" example represents in the general case.
-
i.e. I am not sure what concrete programming problem that is supposed to represent and why it's a problem.
- Još 7 drugih odgovora
Novi razgovor -
-
-
I've been on the other side, using Bohems GC jacked into C malloc and IMHO it was a big design mistake to use it. We are now chained to slow performance, poor caching, random drops in perf. due to mem scans and memory retention.
-
Once the GC was put in, the pattern has spread in the sys and is now basically impossible to remove. GC is a bad crutch for devs who dont know other, better memory management options and should be avoided at all costs.
- Još 1 odgovor
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.