Jan de Boer wrote:I am reading through some old code and the creator of the source is using static functions in a class everywhere he can. For example also private functions that are always called from a created object of the class. Is there some efficiency reason for doing this? Why should people prefer to make 'everything' static where they can?
Quite a bit there.
Let's deal with your questions:
1. Is there some efficiency reason for doing this?
Answer: theoretically yes, but in practise no; and even if there were, it's the sort of micro-optimization that
Donald Knuth warned us all about a long,
long time ago.
2. Why should people prefer to make 'everything' static where they can?
Answer: They shouldn't. And the only reason they
would (and this is just my guess) is probably because they're beginners, and they discovered that you can't call an instance method from
main(); which is where newbies usually start out doing all their work - a
very bad habit, I might add.
So, congratulations: you're clearly developing a good sense of "code smell".
Winston