Why Use Methods?

So far we determined, that methods help with dividing larger programs into smaller tasks, which leads to easier solving of the problem in question. This makes our program not only better structured and easier to read, but more understandable as well.

By using methods we avoid repeating code. Repetition is bad practice, because it complicates maintaining the program and leads to errors. If a certain part of our code can be found more than once in the program and we need to change it, the changes must be made in all of the repetitions of the code in question. There is a great probability to miss a spot where correction is needed, which would lead to incorrect behaviour of the program. This is the reason why it is good practice if we use a certain fragment of code more than once in our program, to define it as a separate method.

Methods make it possible to use certain code multiple times. With solving more and more problems you will find that using already existing methods saves a lot of time and effort.

results matching ""

    No results matching ""