Half of the pain of programming TeX is the difference between expandable and non-expandable commands, the latter usually being a result of an assignment taking place inside the command definition. That makes me wonder why neither Knuth’s TeX nor any later TeX engines add a construction \local\def (or with some other name) that solves this issue once and for all? Then you could do
\def\mycmd{%
\local\def\tempa{<something>}%
\local\def\tempb{<something>}%
\local\def\tempc##1##2{<something>}%
\tempc{\tempa}{\tempb}%
}
and still have an expandable command. (I know you can use a construction like \group_begin: ... \tl_set:Nn \l__gaussler_temp_tl { ... } \exp_args:NV \group_end: \l__gaussler_temp_tl to go obtain a workaround, but it will not be expandable). In other words, it would work just like a function in a more modern programming language. Using \local outside of a command definition could yield an error. This would solve a great deal of the headaches of programming TeX.
Why has this not been done yet?

\localseems an odd name, eg luatex has expandable immediate definitions but they are not local to a definition (having anything local to a definition would be odd in a macro expansion language) – David Carlisle Nov 13 '20 at 14:46#characters in the\tempcdefinition. – wipet Nov 24 '20 at 20:55