The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
What if Constant Values were also valid Types?
by Christopher Diggins
January 18, 2006
I don't know any language which is so perverse as to do such a thing, but I want to throw it out there as an idea to torment people.


I want you to think about the implications of making the following change to C++ or Java: allowing any constant literal to be used as a type.

This would mean that you can declare instances of them:

  42 x;
You can inherit from them:
  class FourtyTwo : 42 { };
You can alias them:
  typedef 42 fourty_two;
You can overload functions using compile time constants:
  int fubar(true x, int n) { return n + 1; }
  int fubar(false x, int n) { return n - 1; } 
I know this is a perversion of nature, but it does simplify a language from a designer's standpoint. I bring this up because it looks like I am going this route for the time being as an undocumented feature in the next Heron release, and I thought it might blow a few people's minds.

Talk Back!

Have an opinion? Readers have already posted 41 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 ( ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at

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

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use