Fondling cacti with your bare hands is often ill-advised. These spiny plants are icons of plant defense mechanisms. Cactus spines are actually modified leaves/bud scales. They develop from a bundle of cells called "primordia" that are nearly indistinguishable from leaf primordia. Unlike leaves, however, cactus spines are not made up of living tissue. The genes for leaf development are shut off in these cells and instead, genes for wood fibers are ramped up, creating the stiff structures many of us have had to pry out of our skin.
It is easy to assume that spines are simply there for defense. For a lot species they certainly do the trick. However, for many other species, spines serve another important purpose - they provide shade. This is exemplified by the fact that cacti growing in rainforests and cloudy highlands often have reduced or no spines at all.
For cacti living in the sun-baked regions of the world, sunburn is a serious issue to contend with. Full sunlight can damage sensitive photosynthetic machinery and while intense UV rays wreak havoc on the genome. As such, any adaptation that can shelter these sensitive tissues to some degree is advantageous.
Spines also buffer the cactus from huge temperature swings. Think of fuzzy or papery spines as a sort of blanket covering the cactus. These spines create a boundary between air immediately surrounding the cactus and the cold nighttime air of these arid climates. This insulation can come in handy as desert temperatures can drop quite low when the sun goes down.
Another benefit spines have is to catch and direct water to the base of the plant. Rain is often scarce in these habitats so when it does occur, a cactus needs to be ready. Water collects on the spines and then runs down to the base. They also act as dew catchers, causing water vapor to condense on their surfaces. In this way, cacti are able to take advantage of every last drop available.
Though they certainly offer some protection, many of these shade spines are too thin and flexible to deter a hungry herbivore. That is where secondary compounds come into play. It is no wonder why some cacti are extremely toxic to herbivores. Whether they are for shade, protection, or water harvesting, cacti spines have managed to capture our imagination and knowing a bit more about their function makes these plants even more impressive.