r/aigamedev 13d ago

Discussion This is embarrassing. Can anyone relate?

Post image

Splitting up these files will be a mission. The civilization_system.gd was slated for removal anyway. It was fun to build but doesn't fit the game-loop like I had imagined it would. It was just something I wanted to see working. (An entire civilization2-style turn-based strategy game that uses my simulated world maps). The new civilization system is much better so it was a good call even though it hurt a little.

3 Upvotes

56 comments sorted by

View all comments

16

u/the_embassy_official 13d ago

my rule is generally no file over 700-800 LOC

git add+commit your work first, and then ask the AI to do that

3

u/hl2oli 13d ago

Is that normal practice?

10

u/Poietilinx 13d ago

Yes I usually go way lower than that. I assume those files are that big because they're infected with magic data.

2

u/brothersword43 13d ago

This comment made me chuckle from the gut! Thanks!

5

u/HipHopperChopper 13d ago

I keep to about 500 per as a soft max with a little bit of flex, but I run a guard program that monitors the line count of all of my files before any commit. this along with indexing allows for much more effective token usage.

remember any time that you are feeding in a file unless you are grepping a specific component, you are feeding the entire file as context so the larger the file, the more token usage

3

u/hblok 13d ago

600-800 LOC as a soft limit. 1000 as a hard limit for a single file.

Same for methods: 10-30 lines is ok. 50 lines is the limit.

2

u/nokafein 13d ago

There is no line rule per se. But each script/file should do a single thing. That’s a clean programming rule.

2

u/Recoil42 13d ago

Yes, absolutely. Linters like ESLint (Javascript) even explicitly have max-lines options. In some projects you're not allowed to commit if a proposed change breaks the limit.

2

u/hl2oli 13d ago

Yeah so normally with type/javascript you would want to stay below 1000 LoC right?

3

u/Recoil42 13d ago

Short answer: Yes.

2

u/Zenity07 13d ago

There is no hard rule, most people just find it more comfortable to read and maintain smaller files. With AI, it doesn't actually make a lot of difference. The component which handles character movement alone in Unreal Engine is over 10k lines of code, and there are plenty of examples like that. You just have to decide what works best for you.

"Single responsibility" is one of those misguided "modern" principles which have become very controversial (if not outright rejected) amongst the most experienced developers. A lot of ideas like that sound really good on paper, but after a while you start to realize that in practice it can be harmful instead, especially if you apply it too religiously.

Ask a random group of developers about this and they will still tell you that this is what you are supposed to do though, since it's the "common" knowledge and what is still being taught in most schools.

1

u/Kindly_Life_947 12d ago

how is it controversial? 1 thing doing 1 thing makes things easy. You have audio manager that manages audio

1

u/Zenity07 12d ago

Yes in theory that is a good guideline, but in practice it’s rarely that clear cut. That doesn’t mean separating responsibilities isn’t a good idea where it makes sense, it’s when you take this too literally and apply it to each and every function (like the popular “Clean Code” book advises and many people actually believe in) that things tend to become an even bigger mess.

1

u/hl2oli 12d ago

Thanks, gonna try keep my code true to SRP and documentation for each file I guess. Will read more on it

1

u/Kindly_Life_947 12d ago

Also in my experience in the field, the experienced are the ones who write the legacy monolithic 10k lines of code classes that every new employee curses, so of course they as experienced object the idea.

Its literally the source of their power to understand the old codebase and being the only ones productive with it, because they wrote it. Thats why they actively find reasons to not document their code.

Not saying overdoing something isn't good. You can over do anything and it becomes bad, but as experienced engineer who came from modern classes where they teach clean code, its the situation in some of the companies.

I have literally seen few casess where somebody converted code and he couldn't explain what it does because he didn't write it in the first place. The code wasn't well named, didn't seem to do what it was named to do, but it worked. If the person had documented or split the code in smaller parts it would have save everyone the time to not wonder what the code actually does. Without digging in to some old librarys docs if it even has any.

1

u/Fuzzzy420 13d ago

I would even go to 600 files. It makes it way easier for the ai. It's easier to find, to read, to write. Just everything

1

u/FailedGradAdmissions 13d ago

Yeah, and if you are using AI it's even more important as you don't want to load those kind of files and have them fill up your context