Another thought; if there is a mammoth difference between top-of-function and narrowest-scope-possible, that suggests that you may have very large functions, and might consider refactoring so that the difference between your method and his is small?
Another thought; if there is a mammoth difference between top-of-function and narrowest-scope-possible, that suggests that you may have very large functions, and might consider refactoring so that the difference between your method and his is small?
The size of the functions isn't really an issue, but I see your point.
If they're as small as the examples above, it doesn't make much difference.
Mutable composite types that use the heap should be scoped broadly, to reuse their heap buffer without touching the memory allocator. Example: C++ std::string.
Immutable heap composites could be scoped narrowly to reuse heap as soon as possible. On the other hand that reduces locality of reference for the deallocator code, and probably spams the branch predictor. If the immutable is small and deeply nested, it should probably be broadly scoped because branch prediction is made of solid gold (unless the language is garbage collected, making deallocation branchless).
Hmm... That got complicated. Stick them all at the top unless you are optimizing a nested loop.