Ideally one practices some sort of compartmentalization. There should be a clear boundary between work and non-work and you can set work aside as needed. It's something I'm really bad at, as seen in the example above.
It's something that needs a certain kind of discipline, and we all know discipline isn't my strong point. Working from home and with everything in the cloud and accessible online makes that discipline even more important. And even more difficult! It's a lot easier to create separation when your work stuff is only accessible from the office.
My tendency for multitasking probably doesn't help either. Even when I'm playing a video game or out on a walk, I can still get distracted by notifications on my phone. I'm used to it and I expect it and I don't really want to disconnect – so maybe I'm kind of asking for it too.
The other day I was supposed to take a day off from work and was planning to chill all day and maybe work on some personal projects. Still I ended up replying to a few emails and discussing some stuff on slack even while I was playing Persona 5. It wasn't much work time but still drove home that I was so bad at compartmentalization.
Software development is also like any other professions that involves creative problem solving. It's hard to set aside the problems you're trying to solve. You can't just suddenly quit on a problem at a certain time. They tend to keep spinning around in your head and will pop back into mind at random. And once a new idea or solution does come to you, one might think it wise to just write it down and pursue it later, but then you risk losing flow. Flow is a valuable commodity in professions like mine, so you kind of want to ride along with it when it decides to come.
Supposedly you should be setting aside specific times of the day for when you hunker down to work. That way your mind gets conditioned that "this is work time”. And it makes it easier for you to create that separation between work time and nonwork time. And hopefully flow comes to you at the proper time instead of randomly while pooping. That's not always easy though, and not always viable due to scheduling concerns. But it should be a step in the right direction. Hopefully it's not too late to learn that kind of discipline.