I'll add my voice to this chorus: Take breaks.
Stopping to smell the roses is great. Maintaining your sanity is paramount.
Those aren't the reasons for this post. Taking breaks improves your productivity.
There are immediate effects. You can gain inspiration from time spent doing something other than your main task. Unbroken focus creates blind spots. For those and other reasons, you can be struggling with a problem before a context change that seems simple afterward.
There's also a long-term benefit: As a software developer, your mind is your tool and all tools dull with use. Taking breaks allows your mind to regain its sharpness. Problems that seem intractable when you are tired or burned-out can melt away once you are properly rested and recharged.
Relaxation and recreation may seem selfish, or even hedonistic to some, but they are actually productivity tools of the highest caliber.