3 ms·
I find the inlined style can actually improve clarity. A lot of code written toward the "uncle bob" style where you maximize the number of functions has fantas
by marginalia_nu 2y ago
I find the inlined style can actually improve clarity.
A lot of code written toward the "uncle bob" style where you maximize the number of functions has fantastic local clarity, you can see exactly what the code you are looking at is doing; but atrocious global clarity, where it's nearly impossible to figure out what the system does on a larger scale.
Inlining can help with that, local clarity deteriorates a bit, but global clarity typically improves by reducing the number of indirections. The code does indeed also tend to get faster, as it's much easier to identify and remove redundant code when you have it all in front of you. ... but this also improves the clarity of the code!
You can of course go too far, in either direction, but my sense is that we're often leaning much too far toward short isolated functions now than is optimal.
- silvestrov 2y ago> atrocious global clarity much like microservices.
- int_19h 2y agoOne thing that's nice about functions is that they force the associated block of code to be named, and for state that is specific to the function to be clearly separate from external state (closures aside). It would be good to be able to retain those advantages even in linear code that nevertheless has clear boundaries between different parts of it that would be nice to enforce or at least highlight, but without losing the readability of sequential execution. To some extent you can have that in languages that let you create a named lambda with explicit captures and immediately invoke it, e.g. in C++: int g; void doThisAndThat(int a, int b, int c) { doThis: auto x = [&a, &b] { ... }(); doThat: [&g, &c, &x] { ... }(); } The syntax makes it kind of an eyesore though. Would be nice to have something specifically designed for this purpose.