A demo of building a WordPress plugin
To get started: https://developer.wordpress.org/plugins/
Why? Most of the time you'll find that someone else has already developed the plugin that you had in mind, but sometimes you need something really specific to your website, or you've found a snippet of code that fixes a problem you have and it's suggested that you put it in functions.php of your child theme. The main reason not to do that is flexibility. If you want to change themes you're better off putting that snippet of code in a small plugin rather than in the functions.php file, so it doesn't disappear when you change themes.