Re:How to reduce the cognitive load of your code
by mathattack on Tuesday March 29, 2016 @09:35AM
(#11381308)
It's both. Some of my worst code was to look at someone else's code after a manager shouted "FIX THIS NOW!!!" with some kind of quick and dirty hack, and then never going back to get it done right. I'm pretty sure this happens independent of whether or not I am any good. :-)
[ Parent
| on HN ]
Re:How to reduce the cognitive load of your code
by ktRolster on Tuesday March 29, 2016 @10:55AM
(#11381903)
When you're really good, you learn to FIX IT NOW while also not making a hack. Your code becomes flexible enough to handle that kind of change.
Re:How to reduce the cognitive load of your code
by chimprich on Tuesday March 29, 2016 @12:19PM
(#11382576)
You can't anticipate every emergency change required to the codebase. Sure, you can make some intelligent predictions about certain points in the code and encapsulate possible changes but it's impossible in the general case. Trying to code to future possible requirements is often far more harmful because of over-abstraction than occasionally having to perform a quick hack and then fix it later.
Re:How to reduce the cognitive load of your code
by ktRolster on Tuesday March 29, 2016 @08:44PM
(#11386177)
Yeah. It's a balance between "build as little 'framework code' as possible;" and "build the framework as you go."
I say 'framework code' but it could be called structural code, or glue code or something, too.
Re:How to reduce the cognitive load of your code
by st3v3r on Tuesday March 29, 2016 @01:43PM
(#11383283)
That's assuming it's your code. Most of the time it's not your code. While one would hope that the rest of the team writes flexible code as well, that's not always the case.
Re:How to reduce the cognitive load of your code
by ktRolster on Tuesday March 29, 2016 @08:57PM
(#11386230)
Then settle for making the code better than it was when you started working on it.
Re:How to reduce the cognitive load of your code
by szatkus on Tuesday March 29, 2016 @11:14AM
(#11382043)
Usually it's not my code :/
Re:How to reduce the cognitive load of your code
by mathattack on Tuesday March 29, 2016 @02:08PM
(#11383514)
I'm not that good to pull that off with other people's code. :-)
Re:How to reduce the cognitive load of your code
by ktRolster on Tuesday March 29, 2016 @08:55PM
(#11386217)
Nah, you're good enough. If the code is bad, change your goal to "make it better than it was when I got here." That's something you can do.
Re:How to reduce the cognitive load of your code
by mtbcoder on Tuesday March 29, 2016 @09:47AM
(#11381388)
Happens to the best of us! Also, it's very difficult to keep entropy at bay in something that requires so much abstract thought and effort as programming, especially with how broad software's reach has gotten.
Re:How to reduce the cognitive load of your code
by collyw on Tuesday March 29, 2016 @05:10PM
(#11384897)
I was having this dilemma on my walk home. I try to write good idiomatic Django code, and know how to make it efficient in the ways described in Two Scoops (a book about Django best practices). I have inherited an app, parts of which are exactly the opposite of Django best practices (thin models fat controllers being the most obvious one - the application's documentation says that's the philosophy , while Django encourages, and works better the opposite way).
So do I spend more time refactoring and bringing this application to a decent state, or do I just keep on hacking more crap on to it? No one except for me seems to give a shit as long as it seems to be working.
Re:How to reduce the cognitive load of your code
by JoeAltmaier on Tuesday March 29, 2016 @05:12PM
(#11384915)
A rewrite is a different animal than writing new code. The problem with rewrites is the marginal utility is a diminishing return. Unless the code is really bad, or will require very frequent revisits.
Re:How to reduce the cognitive load of your code
by mathattack on Tuesday March 29, 2016 @05:15PM
(#11384939)
I think the best practice is to just refactor the bits that you need to touch. At a minimum avoid leaving them worse, and in an ideal world leave each piece you touch better for your having looked at it.