The reason that working more hours as a software engineer doesn’t lead to more productivity is that coding consists of making lots and lots of decisions. As the day progresses, decision fatigue sets in. As you become fatigued, you make poorer decisions, which means you write poorer code. Writing poor code is worse than writing no code; it is negative productivity.
As you become a more experienced programmer, you make less decisions because you no longer have to decide a lot of things that were once decisions. Instead, you just do the same thing you did last time. This is called pattern recognition and it comes with increased intelligence and experience.
If you are working on sufficiently complex code, there are only so many decisions you can make in one day because of decision fatigue. Working too many hours will put you in a position where you start making worse and worse decisions, or no decisions at all. You’ll stop weighing the scenarios of how your code may run against the likelihood of each outcome. You’ll stop weighing the amount of time it takes to write the code against the amount of time it takes to understand it. You might start solving problems that don’t need to be solved.
Writing bad code can mean negative productivity. When you factor the opportunity cost of what you could had been doing with that time (reading), the amount of times that you will have to read that code and model how it will run in your mind, the amount of time it will take other developers to understand it, and the amount of time it will take to work around that code, extend it, test it, and refactor it, it’s pretty clear that writing bad code is actually negative productivity. It’s worse than no productivity.
As you become more experienced, you see more scenarios and gain more real-world experiences that teach you the likelihood of different scenarios playing out. As a new programmer you have no way to understand what the chances of needing to refactor a piece of code are or what the chances of a edge case are. Every line of code is full of decisions. As an experienced programmer, you don’t have to make as many decisions because you simply repeat what has worked in the past.
Adding more hours of coding to your day won’t make you more productive. Adding more years of experience will.
But there are still things you can do to make your days more productive. You may only be fresh enough to write code for six hours a day, but you can certainly read about programming the other part of the day. And you can practice deliberately.