Code Snippets Found Online

One dangerous thing that lot of people have talked about in the past is the danger of getting code snippets online. They're just not trustworthy. Yes, this includes mine. I would like to think that most of mine are good, but I don't have time to carefully check everything I post. I'll make mistakes and include typos sometimes. I attempt to make sure that what I post is accurate and useful, but you should keep in mind that anyone can post on the Internet. There is no restriction, so be careful when taking code snippets and using them. Make sure that you understand what the code does and why it is written the way it is. This understanding will keep you safe when using the code, because you'll be able to identify mistakes before you put them in production code.

One thing that always worries me when I am posting code online is that someone will use my "bad example". I sometimes use an example of the right way and the wrong way. I try to make sure that it is clear which is which, but since I put the bad first, I am worried someone will use it. I have even used the words "bad code do not use this" to describe a snippet which I was pointing out the problems with. I am pretty sure someone has used it though. I admit I've even used the "bad code" from someone's blog before, because the improvement couldn't be made in my circumstances. I did this with some SQL code where I was working with a table instead of a single row as the improvement was.

Be careful when posting or using code from the Internet. If you don't understand something don't use it.

Comments