When is it useful to include the code in a thesis?
Making your code available along with your thesis can be very helpful to other researchers who are trying to reproduce your results.  I'd encourage you to do this.  

However, you should not simply insert a printout of your code into the text of the thesis, since that will make it difficult (practically impossible) for someone to use the code that they obtain from a printed copy of the thesis or even a .PDF of the thesis.  Rather, you should put the code into some online repository (such as e.g. github) so that others can download the code from the web.