Yes what matters is productivity. It is better than sitting 8 hours in your miserable cube in the office , spend 2 hours in commute and get stressed at that and not able to focus properly and churning out low quality code than you can do in 4 hours of quality focused time.