... make it a script first, then think about
whether it's simple enough to become a function.
Forgot to mention, you can also get the best of both worlds by writing a function with sections (up to even the whole function body) wrapped in subshell parens.