logoalt Hacker News

EdSchoutentoday at 5:02 PM3 repliesview on HN

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.


Replies

munificenttoday at 5:29 PM

> 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:

    list_clear(my_list);
    queue_clear(my_queue);
    map_clear(my_map);
show 1 reply
pjmlptoday at 8:25 PM

Well, C has a kind of pseudo generics since C11.

And everyone gets to invent their own vtable implementation since the 1980's.

etsetoday at 5:38 PM

What was the reason for interfaces having to work at runtime?