Re:Simple Ways of Reducing the Cognitive Load in Code
by robmcm on Wednesday June 29, 2016 @04:56AM
(#12000338)
Remember this is in the case of spiting out smaller functions to improve readability.
Variable naming will only add to that, as you can rename variables in the extracted methods for their local purpose.
If you have too many arguments you can package them up in a object/map/tuple of your choosing (depending on language).
(Reverting to local state would in my opinion increase confusion and decrease readability.)
Re:Simple Ways of Reducing the Cognitive Load in Code
by gnaritas on Tuesday June 28, 2016 @12:26PM
(#11995079)
State can be stored in instance variables as well, and should be if many small functions share them, it's what objects are for.
Re:Simple Ways of Reducing the Cognitive Load in Code
by signa11 on Tuesday June 28, 2016 @11:57PM
(#11999401)
> State can be stored in instance variables as well...
but then we are back to the beginning of the thread...
Re:Simple Ways of Reducing the Cognitive Load in Code
by gnaritas on Wednesday June 29, 2016 @05:47PM
(#12005076)
No, we aren't, since objects are the proper way in this case to reduce cognitive load. This notion that all the code has to be in one method to be understood is symptomatic of programmers who don't know how to factor correctly thus leading to the necessity of having to read a methods implementation to understand what it does, i.e. they're bad programmers blaming their shortcomings on well factored code rather than learning how to read and write well factored code correctly. Breaking down large methods into numerous small ones makes the code easier to read and understand, not harder, unless you do it entirely wrong.
edit-1 : fixed typo