3 ms·
One big problem with most high-level languages is that their support for automatic resource reclamation is limited to garbage collection, which is grossly inade
by catnaroek 10y ago
One big problem with most high-level languages is that their support for automatic resource reclamation is limited to garbage collection, which is grossly inadequate for non-memory resources.
- mingodad 10y agoI did a fork of Squirrel -> SquiLu https://github.com/mingodad/squilu https://github.com/mingodad/squilu because I found the syntax more familiar and also been made with C++ that make create extensions easier than plain C. Then I started adding more and more C/C++ like syntax options with the idea to have a way to develop fast prototypes in a way that could be migrated to C/C++ when performance was not good enough, the idea is to be able to parse and accept C/C++ syntax but without actually inforce it at scripting level (accept discard/warning) and be able to use a real C++ compiler to do the heavy work. Ideally it'll lead to something like Terra http://terralang.org/ http://terralang.org/ or Cxx.jl https://github.com/Keno/CXX.jl https://github.com/Keno/CXX.jl But now Haxe http://haxe.org/ http://haxe.org/ has several advantages that's worth consider.
- pjmlp 10y agoThose languages provide other mechanisms, but people keep ignoring them on this discussions. Besides the usual set of using, with, try-finally, there are higher order functions for those languages that support it. For example, with-file "/pathname" { //fd is only visible and open here } accept-connection { // socket } // .... You just need higher order functions and implicit parameters to be able to do that in your GC language of choice.
- catnaroek 10y agoThe problem is actually remembering to use `using`, `finally`, `with-foo`, whatever. With RAII, I don't need to remember - forgetting to free is literally impossible.
- pjmlp 10y agoRAII only works with global and stack allocated data. You also need to remember to use RAII in every other case. You might also need to implement RAII handle classes in specific use cases.
- catnaroek 10y agoOnce for every struct/class, which is much better than once for every individual resource used.
- pjmlp 10y agoYou don't need to do it for every individual resource used, specially if the language has support for meta-programming. I guess these FP patterns are yet to be widely known.
- gpderetta 10y agoThe biggest difference between RAII and other approaches based on higher order functions and closures is that RAII is bound to object lifetimes, while other approaches are bound to scopes. They compose differently.
- lmm 10y agoAbsolutely right, and it absolutely is immensely valuable. It's perfectly possible to do the same thing in a higher-level language though - if you only expose with-file then you have the same safety guarantees as RAII. If you only expose composable commands and a way to execute them (i.e. a free monad approach - doobie is a good example) then you can get even better guarantees than are practical with RAII (there's no way to do the equivalent of "&myFile").