type MyClass struct {
var name string
var id integer
}
func (c *MyClass) DoSomethingWithName() error {
c.name = "foo"
}
func (c *MyClass) DoSomethingWithId() error {
c.id = "1010"
}
class MyClass {
var name string
var id integer
DoSomethingWithName() error {
name = "foo"
}
DoSomethingWithId() error {
id = "1010"
}
}
type Foo int
fun (f Foo) stuff() {}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why didn't the designer simply encapsulate that into a proper class?
It complicates things as it doesn't nicely package a class into one conceptual "block". You also have to add the redundant target struct or type in each function signature and inside each function you need to refer to the the target object explicitely. This all adds to a less readable code overall.Using 'class' doesn't require you to have everything into one file. Other statically typed languages offer ways to add methods to existing classes, in different files. In Scala you can use "implicit conversion" and in C# you can use "extension methods". The C# approach is more elegant. Simpler still is to allow multiple "class" definitions, each adds to/redefines the previous definition. That's what Ruby does. Yes Ruby is dynamic but this principle could be applied to a statically typed language.
It complicates things as it doesn't nicely package a class into one conceptual "block".
You also have to add the redundant target struct or type in each function signature and inside each function you need to refer to the the target object explicitely.
This all adds to a less readable code overall.
I'm new to Go. It seems to me that it complicates things by simply not allowing us to define classes like in most other language. Am I missing something fundamental here?
It complicates things as it doesn't nicely package a class into one conceptual "block". You also have to add the redundant target struct or type in each function signature and inside each function you need to refer to the the target object explicitely. This all adds to a less readable code overall.