this post was submitted on 13 Nov 2024
813 points (96.1% liked)

Greentext

4383 readers
1523 users here now

This is a place to share greentexts and witness the confounding life of Anon. If you're new to the Greentext community, think of it as a sort of zoo with Anon as the main attraction.

Be warned:

If you find yourself getting angry (or god forbid, agreeing) with something Anon has said, you might be doing it wrong.

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 17 points 1 day ago (8 children)

object orientated programming is the wrong idiom for almost all problems, and even in the few cases where it makes sense, you have to be very careful or it'll hurt you

[–] [email protected] 8 points 1 day ago (4 children)

I have been trying to be more functional but I still use classes for things like loading/modeling configs. What are some common situations where using an object is a good solution?

I use python if that helps at all.

[–] [email protected] 8 points 1 day ago

Objects are great for game programming.

Stuff like enemies, bullets, loot, items, etc. are constantly changing and affecting each other. This makes it difficult to program in fixed functions that run through and crosscheck a bunch of constantly changing arrays. It makes logical sense to have objects with their own functions stored in dynamic lists instead of arrays. A lot of the properties are used by several different objecs, like coordinates or health points, so it also makes sense to describe them in classes.

So, I'd say that it's a useful way to classify data that is very dynamic, or when different functions need to run depending on that data.

I don't like putting all code into classes, because a lot of code doesn't need that kind of flexibility.

load more comments (3 replies)
load more comments (6 replies)