Why advanced languages like C# and Java does not enforce File Closing? -
most of times students gets console based management system assignments i.e. library or point of sale system etc. have store data using traditional file system.
and 80-90 percent times make mistake of forgetting close file after opening or creating it.
somefile.close();
(they have debug code find error, why data not being stored in file. being mentor have faced problem myself many times too.)
so real thing is, way these advanced languages java enforces exception handling why there isn't enforce file closure?
resources released whenever deallocated (by being garbage collected, not expected deterministic). if want dispose them in deterministic manner (and not @ moment of deallocation), in java there try
-with-resources block , in c# there using
block.
why don't enforce case types encapsulate autoclosable/disposable resources? well, because pattern in use cases. if enforced it, troublesome in other cases.
Comments
Post a Comment