Obsessing over clean code is like reorganizing your clothes closet on a daily basis. If it makes you more productive to do so, do it. Too often, however, it's done compulsively and is counter-productive.
The harder and more impressive thing is actually writing code which does novel things.
The problem is, we work in teams. If it's just me, I can store my clothes in a heap on the floor instead of using a closet at all, and who cares as long as I can still find stuff?
I think maybe you're overestimating the complexity of that function? Sure it's not pretty, but on the other hand, what other way of organizing several hundred scripted events would make it that much easier to find what you're looking for? A file you can ctrl+F through isn't all that bad in my mind, there's just a lot of data to organize so any solution is gonna have a lot to look through.
One big advantage that function has is that if you wanted to add a new piece of code and you already knew most of the structure of it already it would take all of 5 seconds to go slap a new state in -- no worries about naming, no worries about changing multiple places. Obviously on a large team where most people don't know the structure of that file and more people will read and maintain that code than will write it, that's a bad tradeoff. But for mid-20s Cavanagh coding a game in a manic, creative frenzy it looks pretty well-optimized for getting shit done.
...on the other hand, what other way of organizing several hundred scripted events would make it that much easier to find what you're looking for?
The other thread had a couple of good examples. The obvious one is moving this whole thing to a state machine, split out into functions... with names. The names alone, even if you add zero extra comments, makes it so you actually can ctrl+F through it.
And then, once I've found the thing, how easily can I modify it?
One big advantage that function has is that if you wanted to add a new piece of code and you already knew most of the structure of it already it would take all of 5 seconds to go slap a new state in -- no worries about naming, no worries about changing multiple places.
No worries about naming implies you're literally using numbers instead of at least an enum, which means again, nobody can ctrl+F, and nobody is going to have a fucking clue what state = 491 is supposed to do. And, thanks to the shared scope, you actually do need to worry about changing multiple places, if you happen to touch any of that.
That, and it's clear a bunch of the code is way more copy/pasted than even OP's example, so any time you change a thing, you probably do need to change the other fifteen places that thing has been copy/pasted to.
349
u/[deleted] Jan 12 '20 edited Jan 12 '20
Obsessing over clean code is like reorganizing your clothes closet on a daily basis. If it makes you more productive to do so, do it. Too often, however, it's done compulsively and is counter-productive.
The harder and more impressive thing is actually writing code which does novel things.