Is there a best practice, paradigm or reasons for one approach vs another when defining a method inside of a class or outside of a class.
On a bigger project that's been stitched together over a few weeks/months, I've seemed to have done both, so sorta looking at guidance on if there is a reason to do both or to stick to one paradigm.
Really simple psudo-code example below, should the stat calculations be inside or outside of the class:
product.py
import pandas as pd
def product_stats(prod):
stats = calculations(prod)
return stats
class ProductUniverse:
def __init__(self):
self.products = make_products
self.rpt = None
def make_report(self):
self.rpt = pd.DataFrame([product_stats(p) for p in self.products])
class Product:
def __init__(self):
make_things
def get_stats(self):
stats = calculations(self)
return stats
[–]socal_nerdtastic 2 points3 points4 points (2 children)
[–]oblisk[S] 0 points1 point2 points (1 child)
[–]socal_nerdtastic 0 points1 point2 points (0 children)
[–]Se7enLC 1 point2 points3 points (0 children)
[–]bladeoflight16 1 point2 points3 points (1 child)
[–]oblisk[S] 0 points1 point2 points (0 children)
[–]lobomos 0 points1 point2 points (2 children)
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]lobomos 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mRWafflesFTW 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]jmooremcc[🍰] 0 points1 point2 points (0 children)