-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce anonymous structs #474
Conversation
@@ -50,4 +50,15 @@ func main() { | |||
// Structs are mutable. | |||
sp.age = 51 | |||
fmt.Println(sp.age) | |||
|
|||
// Structs don't always have to be defined as instances of types, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, it's useful and I'm inclined to accept it.
Let's work out the details: I feel this comment is inaccurate because dog
is in fact an instance of a type, just a type that isn't named. It should say something more to the tune of unnamed struct type (but also the word anonymous
should be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eliben Sorry for the late response.
Which one do you think is better?
Structs don't always have to be defined as instances of named types, you can define a struct anonymously.
or
Structs can be instances of unnamed types, therefore you can define structs anonymously.
or we could simply go with "You can define structs anonymously".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll approve this for now and will tweak the comment a bit
@eliben
Its result: |
We actually do have an example of table-driven tests already in https://gobyexample.com/testing-and-benchmarking -- I will add a link to it from this anonymous example. "Value" is correct, even if it refers to a value of a slice type. |
Looks great, thank you. |
No description provided.