It's essential to the growth pattern of dendrites that neurons are able to recognize and avoid themselves. There's evidence that alternative splicing (the genetic differences you mentioned) arose in cadherins before even the immune system. Basically alternative splicing provides each neuron with a random key that has a ~1/30,000 chance of collision.