Dendrites may exhibit many types of electrical and morphological heterogeneities at the scale of a few micrometers. Models of neurons, even so-called detailed models, rarely consider such heterogeneities. Small-scale fluctuations in the membrane conductances and the diameter of dendrites are generally disregarded and spines merely incorporated into the dendritic shaft. Using the two-scales method known as homogenization, we establish explicit expressions for the small-scale fluctuations of the membrane voltage, and we derive the cable equation satisfied by the voltage when these fluctuations are averaged out. This allows us to rigorously establish under what conditions a heterogeneous dendrite can be approximated by a homogeneous cable. We consider different distributions of synapses, orderly or random, on a passive dendrite, and we investigate when replacing excitatory and inhibitory synaptic conductances by their local averages leads to a small error in the voltage. This indicates in which regimes the approximations made in compartmental models are justified. We extend these results to active membranes endowed with voltage-dependent conductances or NMDA receptors. Then we examine under which conditions a spiny dendrite behaves as a smooth dendrite. We discover a new regime where this holds true, namely, when the conductance of the spine neck is small compared to the conductance of the synapses impinging on the spine head. Spines can then be taken into account by an effective excitatory current, the capacitance of the dendrite remaining unchanged. In this regime, the synaptic current transmitted from a spine to the dendritic shaft is strongly attenuated by the weak coupling conductance, but the total current they deliver can be quite substantial. These results suggest that pedunculated spines and stubby spines might play complementary roles in synaptic integration. Finally, we analyze how varicosities affect voltage diffusion in dendrites and discuss their impact on the spatiotemporal integration of synaptic input.