This has been a life long question for WordPress and its developers since time began. Where should we add new code? The renown and agreed methodology is that all code that seeks to harvest information and display it to the frontend or admin, needs to be in a plugin.
Why? Short answer; because plugins have to be consciously turned off. However, themes get switched all the time and that data is not recoverable in the next few seconds of switching that theme.
For the short version of the answer to the question above, view this video below:
However, if your want the explanations as well, you can view this video as well.
What are your opinions of this war? Where do you store your code? Do you agree with the arguments above?