Evolution of modularity

How and why did modularity evolve?