3 ms·
I still love 'with-open-file and its sisters in LISP. Get that resource in one line and it's guaranteed to be cleaned up right without ever thinking about it ag
by WildUtah 10y ago
I still love 'with-open-file and its sisters in LISP. Get that resource in one line and it's guaranteed to be cleaned up right without ever thinking about it again. Then you have total freedom to use it however you want and the results destructure themselves.
- civility 10y agoYou could implement something comparable: int main() { with_open_file_for_writing("foo.dat", [](FILE* fp) { fprintf(fp, "old style I/O, automatically closed\n"); }); return 0; }
- Animats 10y ago"With" is even better in Python. Exceptions during closing work right. The big problem with RAII is that if anything goes wrong in a destructor, you're in trouble.