Hacker News new | past | comments | ask | show | jobs | submit login

>In this case I hope nobody is proposing a single 1000-line god function.

Why not? Who said it's worse? What study settles the issue?

Some times a "1000-line god function" is just what the domain needs, and can be way more readable, with the logic and operations consolidated, than 20 50 line functions, that you still have to read to understand the whole thing (and which then someone will be tempted to reuse a few, adjust them for 2-3 different needs not had by your original operation, and tie parts of the functions implementing your specific logic to irrelevant to it use cases).

And if it's a pure 1000-line function, it could even be 10,000 lines for all I care, and it would still be fine.




Yeah, when code gets spread out across too many classes and functions, it's like you're trying to navigate a maze without a map. You hit a breakpoint, and you're left scratching your head, trying to figure out what the heck each class is supposed to do. Names can be deceptive, and before you know it, the whole architecture feels like a jigsaw puzzle. It's a cognitive load, having to keep track of all these quirks. Maybe it was easier for the author to do it that way when they started from scratch, but after they finished, it's another deal.


Okay, I don't care much about all of the unproven "software engineering" cargo cult rituals, but maybe 10,000 lines is pushing it a bit!


1000-10000 lines typically mean the developer just doesn’t know how to abstract. Don’t go overboard with the function extraction but also don’t make me read every line of your code so I can find the one tiny part I want to change.pseudo-functions, like the commented segments of code like in the linked post, helps but it’s not obvious which data those segments of logic are depending on.


I think the only good use case I have for 50+ lines functions are finite state machines and renderers, whatever the form.

Do you have other examples of 50+ lines functions where you thought it was the best to not separate issues?


Specialized parsers. Encoding and decoding tasks. Complex computation is often isolated to help with peer review. Pattern matching routines.

Also, constructors with many validation steps that are compiler constrained to their local scope. That seems common.


Aren't specialized lexer/parsers finite state machines? As are encoder/decoders?

OK fir complex computation, I left the world of mathematics 7 years ago, and I wasn't at the edge on that, I trust you, but to be clear, all your examples scream 'FSM' to me. If you have a pattern matching routine of 50+ lines that isn't a finite state machine, you're doing something wrong imho, and should consider changing abstraction (I'm not a big OO guy, but maybe use dynamic dispatch?)


Yeah any routine that is not Turing complete is a FSM. Most things are FSM, so it’s not a useful distinction


Anything consisting primarily of a switch statement with a great many cases.


Finite state machines then. I never used more than 3 cases unless I had to write one.


Also event dispatchers. I've written switch statements for various event systems that need to handle 60-100 events. You can easily get to hundreds of lines without things getting unreadable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: