There is an entire field of CS research on this topic, commonly referred to as formal verification. Some programs are written this way.
However, the third year I studied how to formally define programming languages and really enjoyed it. It was all about delivery.
I think class size has an effect too - it's much easier to engage with smaller classes. The second year module was mandatory, whereas the third year module was optional.