4 ms·
It's not very like Java at all. The only OO-like feature it has is interfaces, which are more like Haskell's type classes combined with existential types than a
by barrkel 13y ago
It's not very like Java at all. The only OO-like feature it has is interfaces, which are more like Haskell's type classes combined with existential types than anything else. (The resemblance here is actually very close, implementation-wise: roughly, vtables at the per-instance level rather than per-class level).
The other semi-interesting things it has are (a) channels + parallel functions and (b) the return of error codes for error handling.
Java things it doesn't have start with reflection, bytecode (CPU independence), dynamic runtime code generation, inheritance hierarchies, generics, "everything is an object", array covariance, exceptions as an idiomatic error propagation scheme, scoping based on nested namespaces, no code outside of classes, nested types with scoping to match, inner classes with implicit outer class self pointer, only value parameter semantics, and only reference user-defined types.
In fact most of what makes Java distinct from the subset it shares with C is missing, except for a garbage collector.
- NateDad 13y agoNot sure if I'm reading your response incorrectly... but go has reflection. I'm not sure what you mean by scoping based on nested namespaces.... Go has similar scoping to pretty much every other modern language. Are you saying java has no code outside of classes? Because Go has that (and doesn't have classes). Also... Go has OO features. You can make an object-like thing by tying data (a struct) with behavior (methods tied to the struct). It doesn't have inheritance which is not the same as not having OO features.
- barrkel 13y agoI think you think I'm criticising Go. I'm not. Beyond that, I think you misunderstood my response.
- NateDad 13y agoYeah, I figured I was misunderstanding you. It seems like you were giving a list, half of which was stuff Go didn't have and half of which java didn't have.... anyway, no big deal, just trying to clarify.
- pron 13y agoI don't mean it's like Java in terms of particular language features, but in terms of "feel" and philosophy. It uses abstractions on the same level as Java (higher than C, lower than Clojure), designed as a blue-collar language, emphasizes readability (at the expense of verbosity), and generally avoids low-level bit-diddling as well as high-level meta-programming tricks.
- NateDad 13y agoAhh yes, you must be an inferior programmer if you work in language X. Pretty much any common language other than C/C++ could be (and probably has been) called a blue-collar language - C#, Java, Javascript, Python....
- pron 13y agoWhat? Being a blue-collar language is a virtue! C#, Java, Python, Javascript etc. are all pretty much blue-collar languages; Haskell, Scala, C++ (depends), Rust (probably; I don't know much about it) and Clojure (sadly), aren't. But you're right: "white-collar" languages have the habit of never being too popular.
- stcredzero 13y agoThere were days when Python was white collar. There are places where C++ is blue-collar. (Games, for one.) Rust is meant to be white collar, seems to me.
- pcwalton 13y agoIf "blue collar" means "used in industry for real work", and "white collar" means "a research/niche language", Rust is designed to be blue collar. It's not designed to be a testbed for research beyond what was needed to get safety out of zero-cost abstractions.
- pron 13y agoLet me revise my previous comment. While many might categorize Python, Javascript and Ruby as blue-collar languages, they do encourage all sorts of metaprogramming tricks, while Java, C# and Go absolutely don't. I think this is a big philosophical distinction, because the second group favors readability and the ability to share code in a large team over language power, and this is what makes Go much closer to Java/C# in its philosophy than to Python et al.
- danieldk 13y agoIt's not very like Java at all. The only OO-like feature it has is interfaces, which are more like Haskell's type classes combined with existential types than anything else. That's a bit disingenuous, since Haskell typeclasses go hand in hand with parametric polymorphism, which Go doesn't offer. Typeclasses plus existential types allow you to implement subtype polymorphism. But it is generally frowned upon in the Haskell community and certainly not widely used. Disregarding implementation, if you drag in typeclasses + existential types, Java's interfaces are also comparable (yeah, they don't offer compile-time duck typing, but neither does Haskell).
- barrkel 13y agoJava classes have to be declared to implement an interface. Haskell types don't need to be declared to "implement" a typeclass, since the typeclass instance is declared separately. You don't need to modify the original definition in order to package up a value + functions into an existential; to me, that's the essential advantage of duck typing for larger projects, where you don't have the ability to freely modify any and all source included.
- danieldk 13y agoJava classes have to be declared to implement an interface. Haskell types don't need to be declared to "implement" a typeclass, since the typeclass instance is declared separately. Let's be more specific: instances should be declared with the class or with the data type. Orphaned instances (that go with neither) are discouraged and with good reason - instances cannot be imported explicitly [1]. It is all to easy to have two conflicting instances if people start defining instances apart from the type class or data type. Don't do that! Luckily, -Wall will complain loudly about orphaned instances. where you don't have the ability to freely modify any and all source included Given the above, this is not really true in Haskell. Since orphaned instances are bad, people often wrap a data type using newtype and define the instances with that type. Of course, this is not so much different from creating a wrapper class in Java with another superclass or interface. Except that defining new types in Haskell comes with far less ceremony ;). [1] http://www.haskell.org/haskellwiki/Orphan_instance http://www.haskell.org/haskellwiki/Orphan_instance