DEV Community

Discussion on: Code snippets or nah?

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

I dislike code snippets for a few reasons:

  • Most, if not all, snippets I've seen online, for code I'm looking for, have mistakes in them. I've not once been able to find a numerical algorithm that didn't have floating point errors in it. I can't imagine there being any resource of perfectly clean code snippets.
  • Problems in snippets are magnified when used out of context. If you don't hand analyze every line of the snippet, you'll have no idea what lurks within.
  • It's basically boilerplate code, refer to the unfortunate world of boilerplate code

By all means, refer to snippets and examples for reference, but avoid the desired to Ctrl+C/+V them. And if for some reason you do, then you must analyse every line of that code and make sure you understand it. A hint, if you haven't modified it, possibly significantly, then you likely haven't understood it -- or you've hit the unfathomably rare occurence of a supreme quality, universally relevant, snippet.