That's the price for having arbitrary side effects in your language.  If you don't like it, there's always haskell.