We investigate the connections between compression learning and scenario based optimization. We consider different constrained optimization problems affected by uncertainty represented by means of scenarios and show that the issue of providing guarantees on the probability of constraint violation reduces to a learning problem for an appropriately chosen algorithm that enjoys compression learning properties. The compression learning perspective provides a unifying framework for scenario based optimization and allows us to revisit the scenario approach and the probabilistically robust design, a recently developed technique based on a mixture of randomized and robust optimization. Our analysis shows that all optimization problems we consider h...