Go is often thought of as a successor of C. C doesn't have methods, only global functions. From my perspective, Go added methods primarily so that you can use them in combination with interfaces. Given that interfaces don't support generic methods, I'm personally not convinced that this feature was worth adding.
> From my perspective, Go added methods primarily so that you can use them in combination with interfaces.
They also give you a limited form of overloading. Without methods or overloading, you end up in the situation that C and Scheme are in where every operation on a data structure has to redundantly have the data structure in its name like:
In Go you would methods for that: my_list.Clear(), my_queue.Clear() and my_map.Clear(). Now you can define a Clearer interface, which has only the Clear method. That allows you to write a function clearAndLog(item Clearer) and it will work with the list, queue and map.
> Without methods or overloading, you end up in the situation that C and Scheme are in
Well in C at least we now have this:
...although it turns out the other nice thing about methods is automatic namespacing.Well, C has a kind of pseudo generics since C11.
And everyone gets to invent their own vtable implementation since the 1980's.
What was the reason for interfaces having to work at runtime?