←back to thread

498 points azhenley | 1 comments | | HN request time: 0.21s | source
Show context
zahlman ◴[] No.45773060[source]
> and it avoids problems where you move a block of code and it silently uses a version of the variable that wasn’t what it originally had.

I find that keeping functions short also helps a ton with that.

No, shorter than that. Short enough that the only meaningful place to "move a block of code" is into another function. Often, by itself.

replies(1): >>45773136 #
williamdclt ◴[] No.45773136[source]
It helps with that, but it has other trade-offs: indirection isn't free for readability.
replies(2): >>45773197 #>>45773451 #
1. tengbretson ◴[] No.45773451[source]
> indirection isn't free for readability

Yes, but also no. If its a mostly side-effect free function with a good name and well defined input/output types its basically free.