Classes vs. Functions

class, function, oop

Solution

Create a function. Functions do specific things, classes are specific things.

Classes often have methods, which are functions that are associated with a particular class, and do things associated with the thing that the class is - but if all you want is to do something, a function is all you need.

Essentially, a class is a way of grouping functions (as methods) and data (as properties) into a logical unit revolving around a certain kind of thing. If you don't need that grouping, there's no need to make a class.

Problem

What is the difference between functional programming and object oriented programming? How should one decide what kind of programming paradigm should be chosen? what are the benefits of one over the other ? Functions are easy to understand even for someone without any programming experience, but with a fair math background. On the other hand, classes seem to be more difficult to grasp. Let's say I want to make a class/function that calculates the age of a person given his/her birth year and the current year. Should I create a class for this or a function? Or is the choice dependent on the scenario? P.S. I am working on Python, but I guess the question is generic.

Original source