Why should you not use an external file name in any place other than the open statement?© BrainMass Inc. brainmass.com October 10, 2019, 6:21 am ad1c9bdddf
This one seems a bit ambiguous. I'm not sure of the context it is asked it. Nevertheless, I will try to answer it for you the best I can.
In one sense the statement is true. If you are only considering file i/o in a computer program, then you would most likely only be using the actual file name once, and that would be in the "open" statement. Both the C and the Php programming languages, for example, require the file name in whatever open statement is being used. After that, reads, writes, closes, rewinds, seeks, and all the other commands one executes with that file would reference the file pointer generated by the open command and not the actual file name.
In that case you would not want to "use an external file name in any place other than the open statement". Even in the case I outlined above, though, you might decide it's more efficient to place the actual, external file name into a variable, perhaps at the top of the program code, to make it easier to find if it needs to be changed.
The reason I said it was a bit ambiguous, though, was that there might be other operations you want to do with that file in that ...
This brief document (about 850 words) answers the question of whether or not to use external file names more than once. It describes the disadvantages and explains why. While it only discusses hard-coding file names, this document will also convince you to use the good programming practice of using specific constants sparingly.