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