The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Pointers and References and Temporaries
by Christopher Diggins
September 3, 2005
Summary
File this under: too many darn symbols.

Advertisement

For the current moment the Heron specificiation has swelled to four different kinds of pointer/reference types:

  type* weak_pointer; // can be reassigned, can't be deleted
  type^ strong_pointer; // can be reassigned, can be deleted 
  type$ temporary; // can't be reassigned, can't be deleted
I didn't want Heron to have garbage collection as a default (at least not in the variant of Heron which I am using) but I wanted to make memory managment easier. The primary way I plan on doing this, is to differentiate between pointers which own the resource (strong pointers) and pointers which simply reference a resource (weak pointers). The strong pointers force programmers to be very explicit about what they are doing, for instance you don't copy strong_pointers, you either transfer them (like auto_ptr) or you share them (like share_ptr). For instance:
  my_type^ x = new my_type();
  my_type^ y;
  y = x; // illegal instruction, ownership is either transfered or shared 
  y = transfer(x); // x is set to NULL in the process
  x = share(y); // now both point to the object 
  x = NULL; // x releases hold on object
  y = NULL; // runtime error, y has sole-ownership but forgot to delete it
The goal here is to simply require the programmer to be explicit about what they are doing with their pointers. This should clear up a lot of the memory management gotchas that occur in C/C++ code.

Of course the drawback of this explicit pointer stuff is that the language is now harder to learn. My question is, is the increased safety worth the increased syntactic complexity?

Talk Back!

Have an opinion? Readers have already posted 5 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us