Some interesting notes on C++

84 views
Skip to first unread message

gmhwxi

unread,
Mar 24, 2014, 11:55:32 PM3/24/14
to ats-lan...@googlegroups.com

Not directly related to ATS but very interesting:

http://bartoszmilewski.com/2013/09/19/edward-chands/

H Zhang

unread,
Mar 25, 2014, 12:34:00 PM3/25/14
to ats-lan...@googlegroups.com
It seems what he is saying about C++ are generic challenges that are not unique to C++. For example:

1) What happens in ATS if malloc returns null pointer (insufficient memory)? For nonlinear types I assume that would lead to null pointer dereference down the line. For linear types it would be like C, depending on how much effort you want to spend on modelling such behavior?
2) Are exceptions safe in ATS? Here does manually managing memory with linear types work with exceptions? AFAIK longjmp/setjmp only unwind alloca-ed memories so I don't see how one does it with standard C. For nonlinear types you don't worry about it but that is due to GC.
3) Concurrency problem with shared memory is not unique to C++. It does not matter what language you use.
4) GC is not composable, in the sense that if C++ depends on GC then you can't use it to write low level libraries without bringing in the dependence on GC. So in the end you force everyone to either use the same managed run time or not use your language. It is interesting that for compiled languages with GC dependence only the ones targeting common managed runtimes (JVM or CLR) get popular. Python/Ruby/Lua are all dynamic languages that come with a complete environment with robust REPL support.

Haitao

gmhwxi

unread,
Mar 25, 2014, 2:37:36 PM3/25/14
to ats-lan...@googlegroups.com
A call to malloc in ATS does not return null; it aborts if there is no sufficient memory available.

Brandon Barker

unread,
Mar 25, 2014, 4:38:31 PM3/25/14
to ats-lan...@googlegroups.com


On Tuesday, March 25, 2014 12:34:00 PM UTC-4, H Zhang wrote:
It seems what he is saying about C++ are generic challenges that are not unique to C++. For example:

1) What happens in ATS if malloc returns null pointer (insufficient memory)? For nonlinear types I assume that would lead to null pointer dereference down the line. For linear types it would be like C, depending on how much effort you want to spend on modelling such behavior?
2) Are exceptions safe in ATS? Here does manually managing memory with linear types work with exceptions? AFAIK longjmp/setjmp only unwind alloca-ed memories so I don't see how one does it with standard C. For nonlinear types you don't worry about it but that is due to GC.

Based on my use of exceptions, they are save insofar as they can be expected to be (expressions using them are still required to return the appropriate type, but of course if an exception is called this will not actually happen dynamically.

Linear types and exceptions can be used in the same program, but it is not necessarily resource safe (for the linear resources) to do so. I believe there may be some restrictions as to where exceptions can be used with regard to linear types as well, but don't quote me on that.
 
3) Concurrency problem with shared memory is not unique to C++. It does not matter what language you use.
4) GC is not composable, in the sense that if C++ depends on GC then you can't use it to write low level libraries without bringing in the dependence on GC. So in the end you force everyone to either use the same managed run time or not use your language. It is interesting that for compiled languages with GC dependence only the ones targeting common managed runtimes (JVM or CLR) get popular. Python/Ruby/Lua are all dynamic languages that come with a complete environment with robust REPL support.
 
I always sort of assumed the JVM and CLR were popular because of their industry support and extensive libraries. In the same way, C/C++ are popular because of their immense libraries (and industry support, and yes, also speed). 
Reply all
Reply to author
Forward
0 new messages