RAII

# kevin curtis (16 years ago)

Any plans for RAII style functionality for ES6/Harmony. (It was briefly discussed re ES4 here: esdiscuss/2007-July/004387)

For example, a decorator style syntax which expands to code to do the resource acquisition/cleanup:

{ @raii f = new File("test.txt") // expands to 'let f = new File("test.txt");f.open()' and try/finally processFile(f); } // file is cleaned up/closed

Or a new keyword - say c#'s 'using'. Reuse 'with' - maybe not. Is there overlap re iterators and automatic closing of the iterator in a for loop. Like the Lisp macro with-open-file.

It's useful for memory management to distinguish between short-lived (stack) and long-lived (heap) objects. Could the @raii decorator provide a 'hint' to the VM gc that the object is short lived to assist memory management. Or even a @auto decorator or keyword. If a developer states their semantics upfront - this is a short-lived stack style object - then maybe they could get improved performance. This would not be a instruction to the gc to reclaim the memory immediately once the block is exited - just a hint.

Decorators/AOP seem to be have macro style functionality. Are decorators/AOP or even full macro's part of the plans for ES6?