DEV Community

Discussion on: Printing in D

Collapse
 
jessekphillips profile image
Jesse Phillips

Yeah, D programmers rearly utilize with even with limited scope it can hide the origin. The main thing here is to create a scope to automatically call close() like in Python.

{
auto f = File("text.txt", "w");
f.write(["my" , "name" , "is" , "Jesse"].join(","), "!");
} 
Enter fullscreen mode Exit fullscreen mode

But D also provides an explicit cleanup since, not all cleanup is the same, and not everything is expected to clean up at scope exit

{
auto f = File("text.txt", "w");
scope(exit) f.close();
f.write(["my" , "name" , "is" , "Jesse"].join(","), "!");
} 
Enter fullscreen mode Exit fullscreen mode