A huge, seriously annoying problem with TCL is lack of deterministic cleanup for resources. If you don't manually close a filehandle, for example, it will leak. Doing this sort of bookkeeping in 2015 is infuriating.
proc withOpenFile {filename channelVar script} {
upvar 1 $channelVar chan
set chan [open $filename]
catch {
uplevel 1 $script
} result options
close $chan
return -options $options $result
} proc with {file as name block} {
uplevel 1 [list set $name $file]
uplevel 1 [list eval $block]
uplevel 1 [list close $file]
}
with [open foo.txt w] as file {
puts $file "Hello, World!"
}
I'm sure it's possible to do it in a cleaner way without [set], but my Tcl is a bit rusty.While it would be nice if this were baked into the language, it's pretty astonishing how extensible Tcl is without even having to touch the realm of C extensions.
So: What language(s) did you have in mind that do this right?
sub do_stuff {
my $thing = Thing->new; # no need to manually destroy thing. Its DESTROY method will be called at the closing brace.
}In the end, they all make trade offs depending on the "whim" of the language designer.
> Many scripting languages in practice do reference counting GC that will reliably and deterministically clean up resources other than memory.
When challenged, you offered one. So, is this a Perl-only thing, or can you give other examples?