Code like the sum example there is essentially what differentiates math from programming. The code example there is making a real change to the state of the world, but a mathematical statements/theorems/proofs simply explain a relationship. There is absolutely a right way to think about things, and most programs are not the right way to think about things -- they are simply ways to make computers do things are thought about the right way.
It is a little different with functional programming which aims to resolve these two things. So, the sum example here, for example would be written statelessly, although in way more words than a simple \Sigma expression. The problem is that most people then complain that function programming is too hard.
Instead, we need to start teaching math better to our kids so that as adults, this is not a problem. In the meantime, explaining math to programmers through programs, of course, is a pedagogical tool that is extremely important.
But to tell mathematicians to start thinking in terms of programming is a gross mischaracterization of what mathematics is about in the first place.