We present a formalism for the calculation of the optical response of semiconductors in the independent-particle approximation. The unphysical divergences at zero frequency that plagued earlier approaches are eliminated by a careful treatment of interband and intraband motion, yet the calculations can be made in a way very analogous to usual perturbation theory. The general formalism is illustrated by deriving an expression for the response coefficient for second-harmonic generation