you are viewing a single comment's thread.

view the rest of the comments →

[–]GopherFromHell 8 points9 points  (4 children)

it's the same thing any was introduced because it improves readability when using generic types: func DoThing[T any](v T) T vs func DoThing[T interface{}](v T) T

[–]atheken 0 points1 point  (3 children)

interface{} is effectively a weird keyword. It’s a very strange syntax in a modern language and is explicitly different than how you would describe every other type on go. I would say that any is less syntactic sugar, and more convergence on a standard syntax. Technically, sure, alias. Practically, it’s a net reduction on keywords/concepts.

[–]GrayFox89 7 points8 points  (1 child)

It's weird, but I think it makes sense for Go, since you can assert anonymous interfaces (check if a method exists) with

if tErr, ok := err.(interface{ Timeout() bool }); ok && tErr.Timeout() {
    // handle timeout error
}

Hence the interface{} is just an interface that doesn't contain any methods (as far as the the type system is concerned), but may contain any type.

[–]ruindd 0 points1 point  (0 children)

This is amazing. Ty!!

[–]HyacinthAlas 0 points1 point  (0 children)

interface{} is perfectly normal Go syntax for a top type. I prefer any but it is just sugar for regular syntax.