The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Implicit Casting, Good or Evil?
by Christopher Diggins
September 12, 2005
Summary
Currently Heron is not allowing implicit casting to function arguments. I am trying to decide whether this is a good thing.

Advertisement

In C++ you can write the following:

struct A {
 A(int n) : m(n) { }
 int m; 
}

void f(A x) {
  ...
}

void g() {
  int n = 42;
  f(n);
}
This is handy, a temporary is created which gets passed to f. In a trivial example like this there is really no confusion. When there are multiple overloads of functions, then things get increasingly confusing. In non-trivial software it is very common for even experienced C++ programmers like myself, to get caught by implicit conversion bugs.

Currently Heron prevents implicit casting through constructors. It makes the code slightly more verbose, but I wonder if this is a worthwhile price to pay for increased safety and maintainability.

Talk Back!

Have an opinion? Readers have already posted 6 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