I used to think that a lot of bad code out there was made by lazy, incompetent programmers... But then, after a certain job, I realized that this is probably not the case. Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works.
The main thing most programmers overestimate is their own working memory i.e the number of things you are retaining when writing a piece of code. Problem is: working memory is short term. After a few days, you revisit that code and you realize how much it costs to load it all in your head again. Basically, we need code reviews of code we wrote last week as opposed to code we wrote yesterday.
How to reduce the cognitive load of your code
141–150 of 239 posts
Re: How to reduce the cognitive load of your code
#142There are so many similarities between writing code and writing English. - Thinking of paragraphs as functions with one purpose - keeping sentences short to reduce load on working memory and increase comprehension - create visual breaks to help the reader by grouping common stuff together as mini-functions - reduce intimidation factor of reading by removing convoluted stuff - remove cognitive noise (dead code, unnece…
On the other end, on static language you will likely end up finding out that your initial architecture did not take in consideration this use case or this API, and you may spend a considerable amount of time fixing what would be trivial to do a dynamic language.
Re: How to reduce the cognitive load of your code
#143I used to think that a lot of bad code out there was made by lazy, incompetent programmers... But then, after a certain job, I realized that this is probably not the case. Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works.
> Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works. I would agree. But I think putting up with those conditions is a different sort of laziness, and agreeing to produce garbage is a different sort of incompetence. Looking back on the times I've done that myself, I deeply regret it. Programmers have a lot more power to shape process than th…
Re: How to reduce the cognitive load of your code
#144There are so many similarities between writing code and writing English. - Thinking of paragraphs as functions with one purpose - keeping sentences short to reduce load on working memory and increase comprehension - create visual breaks to help the reader by grouping common stuff together as mini-functions - reduce intimidation factor of reading by removing convoluted stuff - remove cognitive noise (dead code, unnece…
Re: How to reduce the cognitive load of your code
#145Earlier quoted context omitted.
Most of the bad code was made by very productive developers.
One of my co-workers likes to say that 10X engineers produce tech debt 10X faster than the average engineer :) Definitely been true in my experience.
It seems to make sense:
N * (debt factor) = debt
10N * (debt factor) = 10 * debt
Re: How to reduce the cognitive load of your code
#146I used to think that a lot of bad code out there was made by lazy, incompetent programmers... But then, after a certain job, I realized that this is probably not the case. Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works.
> Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works. I would agree. But I think putting up with those conditions is a different sort of laziness, and agreeing to produce garbage is a different sort of incompetence. Looking back on the times I've done that myself, I deeply regret it. Programmers have a lot more power to shape process than th…
Or don't even say it, just do it and don't tell the manager, while incorporating into your estimates.
Overall time to deliver working software with acceptable performance and bug count will still be faster, anyway.
Re: How to reduce the cognitive load of your code
#147Re: How to reduce the cognitive load of your code
#148I used to think that a lot of bad code out there was made by lazy, incompetent programmers... But then, after a certain job, I realized that this is probably not the case. Now I belive that most bad code out thare is made by overworked and tired programmers in a rush to deliver something that works.
Much of it is decent code that was then altered several times, without anyone taking a fresh look to clean it up.
But I'd guess the biggest factor is that most programmers can't tell good code from from bad very well, when writing it.
Re: How to reduce the cognitive load of your code
#149Like often with this kind of article it barely scratches the surface. "null != variable" will confuse people is downright silly. People confused by this won't have an inkling of what any non-hello-world program does. The rest has some validity, but it focuses on syntax and programming in the very small. It might take a bit of effort, but I can make sense of a tangled function (that's not an excuse to code sloppily th…
Re: How to reduce the cognitive load of your code
#150I didn't appreciate how much of a difference it would make until I tried it, but now I know that one of the best ways of making code more comprehensible is to eliminate any questions about interactions between components by using a language with referential transparency. The results of functions should be determined solely by the values of their arguments, with no contamination by shared state and no side effects.