On Tue, 2016-09-06 at 16:05 +0000, Michael Ferguson wrote:
> 
[…]
> We've talked about having a 'with' construct in the context of the
> improvements to error handling. I don't remember anybody being
> opposed
> to it but I'd expect Chapel to get better error handling first.

Having this would be good for gaining Pythonista approval but I am not
sure it is needed (from an outsider perspective) since there are
records and they can have constructors and destructors. This means you
can do RAII without extra syntax.

> Right now, one of my least favorite Chapel language features is the
> 'let'
> keyword. Perhaps that could be used/abused to implement such a
> context.
> (But I don't personally see anything wrong with the "with" syntax).

I'm not sure I even knew about that keyword, so getting rid of it will
not be a problem for new users!

> Generally though for now I'd expect to wrap class object, file
> handles, etc
> in records. We've been talking about how we can create generic
> records
> to enable that wrapping. That will put is in a similar place to C++'s
> std::unique_ptr and std::shared_ptr. I think it's reasonable to
> consider
> ways the Chapel language can help make such ideas easy to use, but
> I'd
> personally try to start with the equivalents to the C++ mechanisms.

std::unique_ptr and std::shared_ptr are something of a disaster for all
except the most dedicated C++-phile. They are the reason I tried to
switch to Rust for an application I started earlier in the year.

I believe the RAII strategy in C++ is to avoid all heap allocations.
Lambda functions have helped with using this unitary approach.
std::unique_ptr and std::shared_ptr are more to do with ownership and
lifetime of internal objects and obtaining external resources
associated with heap storage appears to be increasingly frowned upon.

Using stack-based records with constructor and destructor for RAII
seems to work well both in C++ and D.

Python's context manager and with statement arose simply because Python
has no destructors, so objects with __enter__ and __exit__ methods
managed by the with statement are just creating the stack protocol of
records in Chapel and structs in D.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[email protected]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [email protected]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to