I've heard some developers say that if a variable is only referenced one place, to just replace the reference to it with the value assigned to it. I've also heard developers say if a function is only called once, to just put its statements in place of the single call to it.
The reasoning typically given is that when reading the code you don't have to "jump all over" just to find out what the code is doing.
What patterns or practices would such inlining either adhere to or violate? What benefits are there to inline or to avoid it?
Things that come to mind:
- similar to the Single Responsibility Principle, writing functions that don't try to do "too many things" (hence, easier to write, test, read/maintain)
- optimize for the reader of the code, not the writer
- added overhead of function calls and memory allocation (perhaps only relevant in older languages?)
I think this is distinct from some other questions in the neighborhood that didn't seem to ask/answer the same question.