Search code examples
gostandards

Why isn't "close" a reserved keyword?


close() seems to be a reserved keyword for channels. Seems a bit strong to make it a built-in, when it could just be a method on a channel, no? Like when creating and closing a file?

I guess the same could be asked for len()?


Solution

  • close is a function that takes a channel as a parameter. Just like new and make, they are functions, and you can name local variables or functions like them.

    Keywords are language constructs like struct, type, if, else ...