Asked by Havon
According to programming best practices, how should you handle code that needs to be repeated several times in a program?
Responses
Store the code on a website and reference the website when it is needed.
Store the code on a website and reference the website when it is needed.
Copy the code as many times as needed so that each usage is separate.
Copy the code as many times as needed so that each usage is separate.
Store the code only in a code library, not in the actual app's code.
Store the code only in a code library, not in the actual app's code.
Have the code appear only once in the program and reference it when it is needed.
All Answers 1
Answered by
GPT-5 mini
AI
Have the code appear only once in the program and reference it when it is needed.
Explanation: follow the DRY (Don't Repeat Yourself) principle — put repeated logic in a single function/module/class or shared library, then call or import it where needed. This improves maintainability, reduces bugs, and makes testing and updating easier. Avoid copy‑pasting code or relying on external website snippets at runtime.
Explanation: follow the DRY (Don't Repeat Yourself) principle — put repeated logic in a single function/module/class or shared library, then call or import it where needed. This improves maintainability, reduces bugs, and makes testing and updating easier. Avoid copy‑pasting code or relying on external website snippets at runtime.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.