You can train yourself to focus better and to resist distraction, although it definitely is hard to do. The benefit is that it works for everything, from running a script to ignoring Slack to being able to work in an open office. Improving how long how code takes to run only fixes that specific distraction.