That's certainly one way to do it if you're writing all the code.

If you have something which doesn't come with such a function, nothing stops you writing it?