I would use (2) if I wanted to emphasize that the same value is used throughout the code or if I would like to emphasize that the type of this value is int . Emphasizing things that are true but not obvious can help readers quickly understand the code.
I would use (1) if I did not want to emphasize any of these things, especially if they were incorrect, or if the number of times that TestFunction() is called, it is important because of side effects.
Obviously, if you emphasize what is currently true, but then in the future TestFunction() changes and becomes false, then you have an error. Therefore, I would also like to have control over TestFunction() own or to have some confidence in the copyright plans for future compatibility. Often this trust is easy: if TestFunction() returns the number of processors, then you will be happy to take a snapshot of the value, and you will also be happy to store it in int no matter what type it actually returns, you should have minimal confidence in future compatibility so that use a function in general, for example. to be sure that in the future it will not return the number of keyboards. But different people sometimes have different ideas about what a βbreakβ is, especially when the interface is not documented exactly. Therefore, repeated calls to TestFunction() can sometimes be a kind of defensive programming.
source share