It is now customary for companies to request code samples from programmers they hire.
Back in 2008 I was told at a career advice seminar: “It will not be a programmer that reads your website, it will be a HR manager. Do not put any code on your website, reading code will make the HR manager’s head explode and you’ll never get hired!”
By modern standards that is now considered terrible advice, but I still have trouble with the idea of just dumping a load of code on someone visiting my website. I struggled to find a way to share the code I’ve written, in a way that gave context to the code, so the reader could understand not only what it does, but why it does it. Not to mention that the average piece of code will contain several references to libraries; Libraries that weren’t written in the same style as the code, or even by the same person. I concluded that the only code samples, that offer both context to what the code does and include calls to as little libraries as possible where tutorials.
Tutorials on how to use classes or functions I have created offer code samples with clear purpose, perfect for setting up some context while, as a bonus, being helpful to other programmers in the process.