Most of us want an easy button when it comes to software development. Out of the dark ages when you literally had to code everything yourself came the frameworks that did a lot of the dirty work for you and all you needed was to figure out what those framework calls were. Tools like Xojo make this even easier because the framework has been around a long time, well known and documented, and mostly complete. Add in the rise of internet searching and it’s quite possible to find huge chunks of code that do what you want. Be wary, though, because that convenient piece of code you just found might have bugs in it.
The reality of programming is that any code that you didn’t write should be considered suspect. That’s not the same thing as saying Other Peoples Code (OPC) is wrong, it might be perfectly safe to use, but you really should vet the code and thoroughly test it before putting it into your application.
I’ve seen it on the Xojo forums where someone whips out some code from memory and it contains a bug or simply doesn’t work. The person asking the question then gets mad that it doesn’t work. Normally the bug is simple to fix but it’s obvious that in many cases the developer getting mad didn’t even attempt to read any documentation. Come on, people! If it was that easy, we’d have created AI’s to do the programming by now.
Really, in the long run, you need to understand what you’ve copied. Maybe it looks right on screen but it is horribly optimized, or worse. Maybe it calls into the netherworld and summons Cthulhu. Anything is possible, right? Do you want to be responsible for the software Armageddon in your company?
Much of the example code given on the internet is lacking defensive coding for the sake brevity. This can lead to runtime exceptions that can cause needless headaches. If I had a $1 for every Xojo programming that’s wondered why their Recordset is coming back nil and not checking for database errors I’d could probably buy an enterprise license of Xojo every year.
It’s been my experience that any code you find you will have to tweak it (either a little or a lot) to fit the business requirements of your application. If you don’t understand the code you’ll never be able to figure that part of it out. Learn the individual bits of code and learn how to use the debugger for heavens sake. The Xojo documentation has some great information. The debugger is your friend!
When it’s your own code that you’re copying and pasting (especially in the same project) it’s a very strong indicator that you should refactor your code. Perhaps making a global method or making a helper class makes sense. That’s actually a good time to ask the forum on the best strategy because you’ll probably get two or three different responses. Learning new techniques is good and in the in long run those will become new tools in your arsenal of programming tricks. And remember that in a year or two you’ll look back at your coding today and be embarrassed (this is natural) because you’ve learned SO much since then.
There is no easy button when it comes to software development. Even with RAD tools like Xojo you need to learn the language and the framework to bend it to your will. Sure, use OPC as a way to learn how parts of it work but copying and pasting verbatim without learning why it works is a recipe for disaster.