Viewing a single comment thread. View all comments

tzaeru t1_iyco5g2 wrote

I'll add a little bit of philosophy and theory to this:

The general trend in the development of paradigms, rules and methodologies has been to restrict the programmer from doing certain things. goto lets you arbitrarily move to a different place in the code. This can be made less arbitrary by forcing the programmers to use functions and loops.

Similarly, encapsulating variables is a restriction. It restricts easy access to the variables from outside the class.

Type safety is a restriction. It forces assignment and other operators to require explicit casting for variables of different types.

So on, so on.

Without restrictions, the programmer could do anything at any time and it would be extremely difficult to read such code. When you restrict things, you force the code from different programmers to be more easily understandable and you (hopefully) decrease the amount of bugs in the code.

Sometimes you create a restriction that makes it hard to express some things in a clean way. For example, in C, goto still has a place in error checks and in ensuring that an error causes a function to release the resources it initialized at the start of the function. In more modern languages, there really isn't any reason to ever use goto, since the languages offer other more powerful (and more restricted!) constructs for dealing with the issues that goto is used for in C.

2