by Leon Rosenshein

Kilobytes, Megabytes, Gigabytes and Copy-Pasta

We’ve all looked online for solutions to problems, and that’s a good thing. Learning from others gives you time to focus on what’s important for you and your team, adding value for the company instead of reinventing the wheel. Whether it’s personal blogs, public Stack Overflow, internal Stack Overflow, or a generic Google search, it’s easy to find code snippets that purport to solving your problem, or at least something not entirely unlike your problem. Once you’ve found it, the question then is, what do you do with it.

It’s tempting to just copy/paste it into your code and move on, but that’s probably not the best choice. If nothing else, there’s no guarantee that the code you’re looking at actually works the way you want it to. Just because it’s got lots of up-votes, it could still be wrong. Or, the constraints on the code don’t quite match the ones you’re dealing with. Or there might be some edge case you or the author haven’t thought of. Or it might have some kind of license on it. You definitely want to check up on that.

Bottom line, internet searches can be really helpful, but they’re not without problems/risks. Here’s the story of one of the most copied pieces of code from StackOverflow, and how it’s wrong.