A function is a callable unit of behavior. A method is a function associated with an object or a type and invoked through that association.
The exact terminology depends on the language, so universal one-line definitions tend to become confidently wrong.
Across languages
- C has functions but no built-in class-based object model.
- C++ has free functions and member functions.
- JavaScript functions are values; a function stored on an object is commonly called a method. The call site also affects
this. - Ruby describes callable behavior as methods. Even a method defined at the top level becomes a private instance method of
Object.
1 | def greet |
Ruby also has callable objects such as Proc, lambda, and objects implementing call, but those are not ordinary methods.
Why the distinction matters
Methods participate in object-oriented dispatch: receiver lookup, inheritance, visibility, and polymorphism. Free functions are resolved according to the language’s function and module rules.
The useful question is therefore not “Does this syntax look like a function?” but:
Who owns this callable, how is it resolved, and what context does it receive when invoked?
That question survives contact with more than one programming language, which is already an improvement over most definitions found in interview flashcards.