A function in Go is a standalone block of code called by name, while a method is a function with a receiver, a special parameter that binds it to a named type. You call a function as Area(r) and a method as r.Area(). Methods let a type carry its own behaviour and satisfy interfaces; plain functions do not.
Both are declared with func, both can take parameters and return multiple values, and both can be passed around as values. The difference is the receiver and what it enables.
A function has no receiver:
The receiver (r Rectangle) plays the role of this or self in other languages, but you choose its name. By convention it is one or two letters derived from the type name and is used consistently across all methods of the type.
A method can use a value receiver or a pointer receiver.
Use a pointer receiver when the method must modify the receiver, when the struct is large, or when it contains something that must not be copied such as a sync.Mutex. Do not mix receiver kinds on the same type unless you have a reason; the Go code review guidance recommends staying consistent.
You can attach methods to any type you define in the same package, not only structs. You cannot add methods to built-in types or to types from other packages directly.
To extend a type from another package, define a new named type or write a plain function.
Methods can be used as values. A method value binds the receiver; a method expression does not.
Method values are handy for callbacks, such as http.HandleFunc("/", srv.handleIndex).
| Point | Function | Method |
|---|---|---|
| Receiver | None | One receiver of a named type |
| Call syntax | Area(r) | r.Area() |
| Namespace | Package scope, name must be unique | Scoped to the type, two types can share a method name |
| Interfaces | Cannot satisfy an interface by itself | Contributes to a type satisfying an interface |
| Overloading | Not supported | Not supported |
Go has no function or method overloading, so each name in a scope appears once.
fmt.Stringer.NewServer), and for generic helpers.func Map[T, U any](xs []T, f func(T) U) []U.A method on a generic type may use the type's parameters, but it cannot introduce new ones.
Largely yes. A method is a function whose first parameter is the receiver, and Rectangle.Perimeter as a method expression makes that explicit. The extra benefit is interface satisfaction and grouping behaviour with the type.
Not on the built-in types directly. Define your own type, such as type MyInt int, and add methods to that.
No. Each method name is unique per type, and each function name is unique per package. Use different names or variadic and generic parameters.
Use a pointer receiver if the method mutates the value, the type is large, or it holds a lock. Otherwise a value receiver is fine for small immutable types such as time.Time.
Functions are standalone; methods are functions bound to a named type through a receiver. Methods enable interfaces, keep behaviour next to data and allow value.Method() syntax. Pick pointer receivers for mutation and large types, stay consistent per type, and use plain or generic functions where no single type owns the behaviour.