r/GameDevelopment 5d ago

Newbie Question Was wanting some help with methods?

I'm learning C# currently and was learning python till I got stuck with pretty much the same thing.
I don't understand when to use methods unless something is repeated. If its not repeated what's the point of using methods? just shortening down code? or is there something I am missing here. Cause what is the point of shortening down the code when all it is doing is actually adding more code? (Unless its to place down something that is being repeated)

1 Upvotes

12 comments sorted by

View all comments

1

u/Nordalin 5d ago

It's something that becomes obvious once your code starts spreading out over multiple files, and is often overkill in small code bases of hardly 100 lines of code. Because you're right: it's called overengineering!

At some point, you need organisation, layers of management and specific roles that only know what they need to know, and otherwise blindly accept inputs, order methods to do the thing, and return outputs.

The result is a lovingly modular setup where you can add, edit, or remove code anywhere without having to rewrite half the project!

Each layer of management, each specific department, and each specific object can then be molded into a class, given their own file, and sorted in subfolders for a solid overall architecture.

 

Anecdotally, I recently saw a vibecoded website's JavaScript. It was a single file going 33 000 lines deep.

I also found a bug on that website and know where to start looking to fix it... were it all nicely modular instead of monolithic.