Skip to content
loading...

re: Printing in D VIEW POST

FULL DISCUSSION
 

Your examples make D look like a pretty unreadable language.

with(File("text.txt", "w"))
    write(["my" , "name" , "is" , "Jesse"].join(","), "!");

There's no clear indication that you're working on the text.txt inside the with, and write just magically changes target.

 

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(","), "!");
} 

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(","), "!");
} 
code of conduct - report abuse