Learning with Distribution Shift: Theory and Practice