Opinions On Copy-Pasting Code

Hello there,

I’d like to hear some opinions on the copy-pasting of code from other teams, whether that be to build a robot faster during build season, to get a base system working for your bot, etc. Now, I don’t know the extent to which this is happening, so if I assume that this is a big issue, please feel welcome to correct me. Also, this doesn’t include the WPI libraries, but rather code written by other teams that use said libraries.

I wanted to bring this up because I feel that just copy pasting code from other teams is sort of a bad way to go about designing a robot structure and teaching students about said structure (Also, I mean deliberately copy pasting code and nothing else). I feel like when teams copy paste code in this manner, they ignore the key part of learning in-depth how and why that code works, as if, for example, someone decides to just copy paste in some code for auto shooting in a shooter system, then they don’t actually learn how it works on an in-depth level and therefore not only do not gain any experience, but also feel less satisfied with their programming because they didn’t gain an understanding of what they did, they just copied it. And this pattern of copy pasting programming can lead to lots of programmers on a team not gaining an equal level of knowledge on whatever they’re working on, which denies them the learning experience that FRC is about. Again, I mean deliberately only copy pasting code, as if you copy-paste code but learn how that code works and then be able to make a system similar to it, then that does not violate the learning process.

Please feel free to share your opinions on this post and offer up any criticisms.

3 Likes

If you understand what it’s doing? Who cares.

If you understand enough of it to make it work with your system? Who cares.

The reality is not every team has good programming mentors or even students that are interested in writing code. If copying and adapting code gets their students inspired then I’m very much pro it.

29 Likes

If the team has published a license follow it.

If there isn’t a license or text allowing it then generally in the professional world you can’t use it.

Now… that being said, I believe the guideline of making code public is for the purpose of sharing. So I’d say its in the spirit of the competition to allow its use.

If I were a student copying code I’d make every effort to learn how it worked.

6 Likes

Read any associated LICENSE file and make sure that you’re following whatever restrictions it sets out.

Be sure that you know that you know what it’s doing. If it does what you want to, you know why it does what you want it to do, go ahead and copy-paste. That’s how code goes.

However, I would bet that 99% of the time you’re better off rewriting it yourself instead of copy-pasting verbatim. Writing it yourself makes integrating it into your existing code easier and cleaner, and also helps you build understanding since you don’t just paste-and-forget.

4 Likes

What l would like to emphasize is that you have to know how the code works so that you can make it work on your robot. Take your example of auto shooting, l think that a good auto shooting should include both fancy controlled loops (like feedforward and PID Control loops) and a good algorithm ( like an interpolation table) . Since the parameters of these controlled loops and good algorithm are very unique , so you have to know how to tune it to meet your unique demand. At this time, you will search for docs or ask for help on how to tune these parameters since it is impossible to copy and paste these parameters. In the process of learning how to tune these parameters, you will truly learn a lot of things. l don’t know whether it is proper to use one of 1678’s golden rules here. Steal from the best and invent the rest!. (This golden rule has helped me a lot in my FRC career and l really like this rule and want to share it here!)

It is ok for you to copy their code since they choose to open-source their code, and their aim is to help more students learn their code. But since every robot is unique and your robot must be different from his. And your code structrue may be also different from his. So , it is impossible to just copy and paste his code and it will work on your robot.

What l think Steal from the best is what you say “copy and paste their code” , but it is more important to invent the rest for the reasons l have said above and it will also make it easier for you to debug your code in the future.

4 Likes

I see your point here, like the “Science is built upon the shoulders of giants” line, where you take the best solution available and try to make it into something even better. I definitely should’ve considered the fact that you need to know some of the code to actually use it… I guess I was just thinking that for some reason teams copying code would have similar software and hardware structures. Thanks for the reply; I definitely agree with 1678’s golden rule in that regard!

1 Like

Copy Paste is great prep for the real world.

Assuming it’s not plagiarized, why make more work for yourself? There are lots of reasons not to copy existing code – like more specialized functionality that’s unique to your machine/use case – but if the exact thing you want to do has already been done, don’t feel the need to reinvent the wheel if you want to prioritize your energy elsewhere.

9 Likes

Thanks for the feedback! I guessing I was thinking a little too deep on teams just copying complex subsystems or whatnot, not necessarily just copying common code (even our team reuses past code), and somehow not knowing how said complex code would work.

Code that is reused from prior years is required to be published. In the FRC environment I don’t have an issue coping it verbatim. Rather or not it is a good idea is a different question. Situationally dependent. Sort a long the same lines. Teams mostly don’t rewrite code published in libraries.

1 Like

I’m not certain I can think of a case where this is true, and the robot comes out functional.

4 Likes

We hardly ever copy any of our own code from past years let alone copy others’. Debugging our own code is painful and debugging mystery stuff found on the Internet even more so. Even specific code given to us has been too hard to use. Once we had questions about some code another team gave us to solve a problem we had as did they. They were helpful but after we spent a lot of time on the code and asking more questions they said they never used that code. Occasionally we see here on CD teams asking for coding help and post only snippets thinking the whole module is way more important to us than it is.

We endorse and follow to some extent

but it has been of limited value for our software because:

The students haven’t been much interested in others’ code. And to emphasize some of the hazards of “stealing” from others a favorite example is:

2 Likes

I see two different takes on the question.

On one hand, a team might say “as a choice of how we do our team’s learning, we will develop all software from WPILib up, by ourselves.” This is analogous to how most educational institutions would structure a programming assignment: clearly define where the “student does” layer is at and let them learn.

On the other hand, there is a more general and not-nuanced attitude folks can take sometimes, where they basically say “we do everything ourselves”, but actually draw the line arbitrarily at WPILib. Why not draw the line below WPIlib, or require implementing logic from scratch on custom microcontrollers? Or require controls logic be done on discrete components a student hand-solders together, rather than relying on a purchased processor?

The key difference between these scenarios is the “why” of choosing a certain line in the sand. If it’s just personal pride or “makes out team better”, that’s not a good reason. Neither is “feels like cheating”.

However, “specifically chosen to achieve a measurable learning outcome” might be a solid choice.

As an aside, the more common and non-academia focused answer is “understand and use the available tools”. This includes copy-paste source code, libraries, suppliers… Whatever gets the robot on the field, with maximum functionality, for the least cost.

The beauty of FIRST today is that teams have the freedom to place themselves on that spectrum wherever they see the most need on their community.

10 Likes

Why reinvent the wheel when you could use the wheel to make a car?

5 Likes

The mark of the best teams and I agree whole-heartedly. But this process requires documentation and with few exceptions the students (and adults) abhor recording in any manner what they have done. Even 3rd-party libraries instructions leave something to be desired, however, they are much improved in recent years.

Personal view is that if you copy-paste code you don’t understand, you’re taking out a loan that you will most likely need to pay back later. Hopefully that isn’t in the middle of a competition before an important match.

Copy-paste responsibly.

8 Likes

This is absolutely the right way to view it. Basically all nontrivial abstractions have leakages where the underlying complexity becomes relevant; you can almost never copy-paste nontrivial code and have it “just work.”

Getting copied code to work without a good understanding of it can be even more work than rolling it yourself, because you have to not only understand the problem and solution, but understand someone else’s understanding of them.

3 Likes

And this is the crux of the matter.

Before I retired I was on a bulletin board where people could ask questions and others could answer. Someone would post a solution, and the questioner might respond, “Thanks, that worked.” The next response would be, “But do you understand why it works?”

Others might give an example and say, “But we don’t know your data.” And then caution the programmer to never put something in production that was pulled off the internet and pasted in without testing.

It always amazed me how many people had jobs where they had responsibility to program for the company, but they didn’t know how to do it without getting assistance from some unknown online source. OK, look for examples or guidance. But you’re supposed to be a programmer; you’re supposed to know how the code works if you’re going to use it.

6 Likes

Exactly.

I do a lot of code reviews at one of the companies I work for. I can spot the code copy/pasted from Stackoverflow a mile away. Sometimes you can get good examples, if you know what to ask for. If you search for the wrong approach, you’re going to get the wrong answer. I’ve seen a lot of big chunks of code that solve a problem in a roundabout way that I can solve in 2 lines of code using some built-in function, only because the developer had a pre-conceived solution in mind.

I’ve been writing embedded firmware for 30 years. I occasionally also google for stuff but I almost never copy/paste code.

5 Likes

As a professional software developer I can safely say that I have not worked on a project in the last 15 years that didn’t have significant functionality either copy+pasted from Stack Overflow, or borrowed from some open source library or other.

You need to learn how it works when you borrow it, but nobody I know in the profession writes all of their own code any more.

3 Likes

No one should ever have been doing this in the first place. Reinventing the wheel is a pointless waste of effort; the first part of solving a technical problem is figuring out if someone else has solved it first.