Home Redundancy

What is redundancy?

You should aim to eliminate as much logical redundancy from your code as possible. If you need to repeat a task, don't copy-and-paste the code. Instead, take the common lines and refactor them into a helper method.

A large part of this class and of your grade will be oriented around being able to detect and eliminate redundancy.

Detecting redundancy

Sometimes, it can be hard to tell when something is worth refactoring or not. If you have 6-8 identical lines of code, it's pretty obvious that should be refactored, but what about 1-2 lines of code? What about expressions like 'a' + 1? Where does the boundary lie?

When considering this sort of question, you should ask yourself how many "operations" you'll end up saving if you refactor something into a method. If you end up with a net gain after refactoring something, it was probably the correct decision.