A roof needs vents so that the building can have proper air flow and ventilation. Some older homes that were build without roof vents have gable vents. These gable vents do not meet modern building codes, so they are only allowed on older structures.
Roofs that come together at a slope are required to have vents on each end of the roof. These are called the eave vents. At the peak of the roof is the ridge vent. Shed style roofs only have vents on the eaves, since they do not have a peak that would require a ridge vent.