3 ms·
Let's dissect [5] in the above: > Is Go an object-oriented language? Yes and no. Although Go has types and methods and allows an object-oriented style of progr
by seanmcdirmid 13y ago
Let's dissect [5] in the above:
> Is Go an object-oriented language? Yes and no. Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy.
Classless prototype languages like JavaScript and Self also lack explicit type hierarchies, and they are still considered object-oriented.
> The concept of “interface” in Go provides a different approach that we believe is easy to use and in some ways more general.
There was a OO ML language called Moby [1] that had something similar. Just because the objects were structural didn't mean they weren't objects, though encapsulated communication (calling another object's private methods in the proper scope) is definitely more complicated.
> There are also ways to embed types in other types to provide something analogous—but not identical—to subclassing. Moreover, methods in Go are more general than in C++ or Java: they can be defined for any sort of data, even built-in types such as plain, “unboxed” integers. They are not restricted to structs (classes).
You mean like extension methods in C#?
> Also, the lack of type hierarchy makes “objects” in Go feel much more lightweight than in languages such as C++ or Java.
They are basically claiming that Go is not C++ or Java, not that Go is not object-oriented, of which the design space is much broader.
In my opinion, there is nothing interesting in Go, and it doesn't seem like a language I would want to use.
[5] http://golang.org/doc/faq#Is_Go_an_object-oriented_language http://golang.org/doc/faq#Is_Go_an_object-oriented_language
[1] http://cs.uchicago.edu/files/tr_authentic/TR-2003-10.pdf http://cs.uchicago.edu/files/tr_authentic/TR-2003-10.pdf
- masklinn 13y ago> There was a OO ML language called Moby [1] that had something similar. OCaml uses a structural object system (alongside the nominative type system it inherited from ML) [0] http://en.wikipedia.org/wiki/OCaml http://en.wikipedia.org/wiki/OCaml
- seanmcdirmid 13y agoThey are pretty contemporary, from the 2003 Moby paper: > The main differences stem from a fundamental design choice: OCAML’s design emphasizes the expressiveness of the object-type system, whereas MOBY’s design emphasizes the expressiveness of the class system. OCAML uses row polymorphism [R´em94] to support extensible object types, whereas MOBY uses structural subtyping. OCAML’s approach has two advantages: it is backward compatible with ML’s Hindley-Milner type inference, and one can get the effect of mytype by the use of recursive type variables. The cost of providing mytype is that OCAML’s classes are less flexible than MOBY’s. Specifically, if a method is public in an OCAML class, it cannot be hidden from either class clients or object clients of a deriving class, as required for the soundness of mytype. In addition, if a method is hidden from object clients in a class, it cannot be made public by a deriving class. The former restriction means that the class hierarchy determines an object-type hierarchy. These restrictions, along with the fact that OCAML does not have public fields, limit one’s ability to use the module system to implement friends via package scope in two ways. First, it is not possible to reveal inherited protected methods or fields to the friend functions, and any method that a class reveals to its friends must also be revealed to any client outside the module (assuming that the class is exported).
- oelmekki 13y ago> In my opinion, there is nothing interesting in Go, and it doesn't seem like a language I would want to use. I take it you're a C/C++ developer ? As a ruby developer, go got my interest like other compiled languages could not, and the reason for that has be pointed out by Rob Pike in his keynote at gophercon[1] : productivity. I'm used to a certain pace of development with interpreted languages that compiled languages just can't match. And well, time is money, I'll use a "slower to write with" language only on critical piece of software where something else won't do. Go has been a perfect fit, here : it allows to do more heavy processing while still being acceptably fast to develop. Other than that, its main advantage is what it has been created for to begin with : concurrency. It's a core concept, meaning you can express it with simple syntax (with goroutines and channels) and that you don't have to fear hitting limits (goroutines are not threads exactly, go do its best to map them on available threads, as much as there are cores, and you can thus have ten of thousands of goroutines running concurrently with no problem). There are probably languages that go further on concurrency, like erlang, but go is just the perfect balance between ease of learning, speed to develop, ease of implementing concurrent code and speed of execution. [1] http://confreaks.com/videos/3419-gophercon2014-opening-day-keynote http://confreaks.com/videos/3419-gophercon2014-opening-day-k...
- seanmcdirmid 13y agoC#, which is faster than Go with better features (parametric polymorphism, classes, interfaces, the works). Go's support for concurrency is nothing very novel and has nothing to do with its language design. Green threads have been around forever, and many platforms support thread pools.
- deleted 13y ago[deleted]
- leaveyou 13y ago"C# is faster than Go" do you have some links to prove that statement ? I'm really interested because in all the benchmarks I saw, C# seemed much more slower.
- pcwalton 13y ago> Moreover, methods in Go are more general than in C++ or Java: they can be defined for any sort of data, even built-in types such as plain, “unboxed” integers. They are not restricted to structs (classes). This doesn't quite mean what it sounds like it means for those familiar with extension methods or typeclasses, because you cannot define methods on ints in Go: http://play.golang.org/p/CuBT11_uF3 http://play.golang.org/p/CuBT11_uF3 Presumably what it means is that you can wrap built-in types in a local "type" wrapper and then implement methods on that. (That's not what I would call a "plain, unboxed integer" in the FAQ language, but this is a semantic quibble.) Anyhow, Go has nothing like the extension methods in C#: the closest thing you can do is to wrap external types in a "type" wrapper and implement methods on that, but this is not as general of a solution as it requires callers to perform the wrapping of individual values before calling the method.
- NateDad 13y agoSo, I think the key thing here is unboxed. You can write methods on values whose in-memory representation is the same as an int. It performs in all ways like an int (you can do arithmetic operations on it, etc). It's not boxed, the way other languages would require it to be in order to have methods. C# extension methods are just syntactic sugar. public static int WordCount(this String str) Yes, this means that you can now do this: string foo = "howdy partner!" int count = foo.WordCount() Is that really any better than this? string foo = "howdy partner!" int words = WordCount(foo) The only reason this is useful in C# is because it doesn't support bare functions, all methods have to be on an object. In Go, this is not a problem, you can have bare methods. Also, extension methods, in practice (and I have a lot of practice with them), are a pain in the butt... because they're magic additional methods on a class that only exist if you include the right project... which means if you try to copy some logic, some of the functionality will not compile in the new location until you figure out what projects to include in the new spot. That's still requiring work by the caller, except that it's much less obvious what you need to do to get it to work. In contrast, Go's type definitions are 100% clear and obvious, and there's never a question where the functionality is coming from. That clarity makes a huge difference when you're trying to understand the code. Of course, you'd never actually do that for most C# extension methods in Go, it's ridiculous to make a new type just to make it look like you're calling methods on that type. You'd just write a bare function like a normal person: package count func Words(s string) int {} // elsewhere foo := "Howdy Partner!" words := count.Words(foo)