5 ms·
> Lots of abstract classes such as "Processor", "Context", "Box", "Request" and so on, with no real meaning. This is a completely false dichotomy. Just because
by sdegutis 8y ago
> Lots of abstract classes such as "Processor", "Context", "Box", "Request" and so on, with no real meaning.
This is a completely false dichotomy. Just because a feature can be misused doesn't mean it's not legitimately useful. Generics make the language easier for the user, but are harder for the implementors. Most language designers / implementors recognize that this trade-off is worthwhile, and therefore nearly every other popular typed language has them. The Go implementors are the only ones against doing it, because, well, they would have to implement it, and they're concerned that it will make the codebase too complex for them to maintain. (Their sympathizers are against it too, which is still a mystery to me.)
- nemothekid 8y agoI'd argue that Generics make the language easier for the writer, not the reader which is what he was getting at. What I like about Go is the language is small, so at the expense of some verbosity, that in most cases you write once, its very easy to understand. One thing I dislike about some Java & Scala codebases is the "manual" unwinding you have to do to debug some functionality.
- whateveracct 8y agoThis is FUD. Parametric polymorphic code is not hard to read at all - in fact, it is easier to reason about since it is universally quantified for all types.
- chowells 8y agoMost people don't even know what parametric polymorphism is, let alone have ever used a language that supports it. I find it's basically impossible to explain just how powerful of a tool it is to someone who lacks experience using it.
- sdegutis 8y ago> Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, and others. > Java, C#, Visual Basic .NET and Delphi have each introduced "generics" for parametric polymorphism. https://en.wikipedia.org/wiki/Parametric_polymorphism https://en.wikipedia.org/wiki/Parametric_polymorphism
- chowells 8y agoA bunch of low-reach languages have true parametric polymorphism. A bunch of common languages have polymorphism that may be parametric or may be bounded by runtime type information checks, and you can't tell the difference from the types. Neither of those contradict my assertion that most programmers have never done work in a language where the type system can make guarantees that they can trust.
- whateveracct 8y agoThis is a very pedantic point
- aikah 8y ago"append","delete","copy" in Go is parametric polymorphism hardcoded in the compiler. append can be called with many different array types. There is nothing complicated with that. go can iterate over arrays irregardless of the element type the same way with the same construct using "range", therefore "range" is polymorphic. The real debate here is should the compiler be "privileged" or should there be API in userland to implement these behavior.
- whateveracct 8y agoThe only programmers who haven't used a language with parametric polymorphism are those who have only programmed in C, Go, or dynamic languages at this point. Outside of Java syntax noise, I really have my doubts that Java's parametric polymorphism is too complicated for the average programmer to understand. public static <A> A identity(A a) { return a; }
- chowells 8y agoJava does not have parametric polymorphism because instanceof exists in the language. That reduces what you can say about something from the type alone to "maybe parametric, maybe bounded by runtime checks that aren't visible in the type." How many languages provide you a way to guarantee at the type level that the behavior of a function cannot be influenced by instantiation of type variables? I don't believe that to be true of anything that runs in the JVM or in .NET, for instance, as runtime type information is always available. C++ has dynamic_cast. What common language actually has parametricity expressed in the type system?
- whateveracct 8y agoThat’s true..but Haskell has bottom and Scala has bottom + instanceOf checks and JVM reflection as well. And they clearly have usable parametric polymorphism despite things being “broken.” Saying Java doesn’t have parametric polymorphism because you can cheat is like saying Haskell isn’t pure because of unsafePerformIO.
- pwm 8y agoAgreed. There is always a point where it's the developer's responsibility to write good code, even in languages where it's very difficult to shoot yourself in the foot.
- jy3 8y ago> Just because a feature can be misused doesn't mean it's not legitimately useful. The point isn't that it can't be useful. In the real world, the amount of code I'm forced to understand that uses overly complicated abstractions is the issue. I'm glad one language finally took the opposite direction.
- munificent 8y ago> In the real world, the amount of code I'm forced to understand that uses overly complicated abstractions is the issue. This may say more about the specific codebases you work in than it does the software world at large. I spend most of my time in a couple of languages that all have generics and don't experience the problem you describe.
- pwm 8y agoThere are good and bad abstractions. In my experience good ones are usually grounded in math. Used the way they are intended generics/parametric polymorphism should reduce your cognitive burden. Eg. having a single, well defined and tested abstraction like Set that is type safe and its operators can work on any type it can contain is surely a good and worthwhile abstraction. The same goes for parametrically polymorphic functions that need not know about the concrete types they operate on and with the proposed contracts they can optionally require that its argument types possess a given constraint/capability like equality.