Sponsored Link •
|
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 deletedI 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 itThe 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?
Have an opinion? Readers have already posted 5 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
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. |
Sponsored Links
|