←back to thread

142 points jmillikin | 3 comments | | HN request time: 0.636s | source
Show context
Neywiny ◴[] No.44546748[source]
The intent here is nice. I historically hate state machines for sequential executioners. To me they make sense in FPGA/ASIC/circuits. In software, they just get so complicated. I've even seen state managers managing an abstracted state machine implementing a custom device to do what's ultimately very sequential work.

It's my same argument that there should be no maximum number of lines to a function. Sometimes, you just need to do a lot of work. I comment the code blocks, maybe with steps/parts, but there's no point in making a function that's only called in one place.

But anything is better than one person I met who somehow was programming without knowing how to define their own functions. Gross

replies(3): >>44547042 #>>44547331 #>>44547585 #
1. throwaway81523 ◴[] No.44547331[source]
> there's no point in making a function that's only called in one place.

There's nothing wrong with doing that if it helps make your code clearer. The compiler's optimizer will inline it when appropriate so there's no runtime overhead either.

replies(1): >>44548486 #
2. munch117 ◴[] No.44548486[source]
Not only that, the compiler's optimizer might actually do a better job if you split up a big function. Because the smaller functions have less register pressure.
replies(1): >>44550564 #
3. Neywiny ◴[] No.44550564[source]
I'm not sure I agree and I think you should try some stuff out on godbolt first. The compiler can see where variables are no longer in use, whereas unless you turn on link time optimization (which is known for being messy so nobody seems to), you'll likely get a lot of unnecessary push/pop between the function calls.