This may be rudimentary question for some and not even a programming one technically but I just stumble upon a thought process which I could not find an answer myself.
As we all know file handling operations are one of the important aspect of the programming and it is also one of the painful aspect if not used carefully specially closing the open file objects.
for example we have at least two ways of file handling ways (using python for simplicity purpose)
f = open("file.txt", "r")
content = f.read()
f.close() # does not executes, in case of exception
Or more safer approach using context manager like
with open("file.txt", "r") as f:
content = f.read()
# No need to worry about file closing
We can all can agree that the approach using context manager "with" is always better approach. This made me wonder why the first approach is even permitted.
I agree that all languages change and improve throughout time. And there are numerous examples of how, in newer versions, the language may stop supporting some of the old functions, classes, and so on, or at the very least give an alert that the way has been decrypted and will no longer be supported in future versions.
I would appreciate some explanations, as well as any references that I may go into in order to better comprehend the concept.