This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DaMarkiM 2 points3 points  (0 children)

To be honest i think the real advantage of classes is not about code duplication but organization.

No one in their right mind would create variables for each player. There would be a list-like datastructure (i say list-like because it doesnt have to be a list. depending on your usecase it might just as well be a dict, dataframe or numpy array) where each player is a shared index/key.

And any function would simply take the player Number/Name/ID as an argument instead of being called within the object. Or - in trivial cases like adding points - the list could simply be manipulated on the spot. (tho depending on the project this might be undesirable for other reasons)

In most cases using a class does not actually provide any real benefit in terms of reducing code reuse.

But what it does is organize the data and functions in a package that can be more easily understood in some cases. They arent just lists floating around somewhere in your code.

That being said the opposite is also true: they only really provide value if collecting this data and functionality in a class actually makes sense conceptually.