Questions & Answers

What is the difference between a function and a method?

You might have heard terms like function, method, procedures, subroutines, that all appear to refer to the concept that you can write a block of code and call it from elsewhere, potentially with some parameters, to perform some tasks. There might or might not be values returned.

For practical purposes, you can treat them as interchangeable. The differences usually come from the languages / platforms you are using and your background, and can sound weird outside of the context.

For example, the term method in Java refers to functions that belong to a class . Due to Java's large influence, people usually differentiate between class owned functions as methods, and non-class owned functions as functions.

Usually a method has an implicit parameter (usually called this) that you can use to refer to the object that the method is called on.

This is, however, not universally true, for example, in Python you need to pass in the object, and by convention called self.

Furthermore, a static method (a method that can only be referred to via the class rather than the object) doesn't have an implicit this passed in, either.

So, if you are speaking to people in an OOP context, chances are you could sound weird if you refer to a function attached to a class as a function instead of a method. You'll do well to follow the convention.