Re:Popular Myths about C++, Part 1
by pjmlp on Tuesday December 09, 2014 @03:41PM
(#8725569)
You can do this in all modern GC languages.
Either with a using/try with resources/with construct, or by using closures.
// Pseudo language with FP capabilities
let withFile filename action =
let fd = open filename
action fd
close fd
withFile "config.sys" (fun fd -> write (readlines fd))
Real production code would also take care about proper closing the file in case of errors.
Either with a using/try with resources/with construct, or by using closures.
Real production code would also take care about proper closing the file in case of errors.