Open iadityanath8 opened 4 months ago
I've been thinking about something like this too, but there's a few too many unknowns for me at this point to consider adding this into the language. Some questions about your suggested approach:
If we can come up with a good design for this system that fits in well with the rest of the language - then definitely we should implement it.
As we know how much defer is important when freeing or delaying any resource such as memory management and file io etc
But i find the problem while implementing mutex locks such as every time i have to write defer which is kind of annoying sometime
i think instead of doing this we should implement some kind of guarding mechanism which looks it cannot be implemented without constructors and destructors for example
A language known as odin implements this feature using deferred attribute above the function which tells which function to defer after the current function is ended for example
Which will defer the mutex_unlock function which is similar to this syntax
Now introducing this kind of attribute will be very important because of the resources that will be freed within the blocks