Skip to content

proposal: removal of interface{} type in Go 2.0 #20188

@henryas

Description

@henryas

Hi,

Given Go's powerful interface, I think it is possible to remove the "blank interface" type entirely, making the language simpler and more streamlined. For instance, instead of fmt.Printf(format string, args ...interface{}), we can perhaps write it as fmt.Printf(format string, args ...Stringer). The idea is to shift as much work as possible to the compiler and leave very little to the runtime type checking.

At the moment, the "blank interface" type is increasingly being misused as a convenient way to bypass Go compiler's type checking. There are places where "blank interface" is used in place where explicit interface could have been used.

The problem with runtime type checking is that you will never know if there is a problem until it is run. With static type checking, you can catch the bug during compile time. By removing the "blank interface" type, Go will have a stronger type system.

In addition, with explicit interface, it will be easier to understand what a type does than with "blank interface". There will also be less code associated with runtime type checking.

I know this will be a breaking change to the language as well as to the existing standard library, which is why I am proposing this for Go 2.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions