Programming languages all come with features that allow you to reuse code. So what's the difference between copying and reusing code?
If you copy code, you simply duplicate it. But when you reuse code, you have a single copy of the code that you can call in all the places that you need it. Not only will your programs be shorter, but it also means that when you amend code, you will need to change it only once and in one place only.
So you want a new gravity-bomb launcher added to each of the star-fighters? No problem. I'll change a few lines of code and every craft in the fleet will be updated.
So code reuse is a good thing. But how do you do it?
define your function
Give the function a name.
The tode shave is you mde^ed-
Was this article helpful?