I <[EMAIL PROTECTED]> wrote: > Incidentally, I'm not saying that such a feature would be a good idea. > It generally isn't provided in languages specifically because it gets to > be a big pain to maintain all of the type specifications for this kind > of stuff.
There are other good reasons, too, as it turns out. I don't want to overstate the "possible" until it starts to sound like "easy, even if it's a pain". This kind of stuff is rarely done in mainstream programming languages because it has serious negative consequences. For example, I wrote that example using variables of type int. If we were to suppose that we were actually working with variables of type Person, then things get a little more complicated. We would need a few (infinite classes of) derived subtypes of Person that further constrain the possible values for state. For example, we'd need types like: Person{age:{18..29}} But this starts to look bad, because we used to have this nice property called encapsulation. To work around that, we'd need to make one of a few choices: (a) give up encapsulation, which isn't too happy; (b) rely on type inference for this kind of stuff, and consider it okay if the type inference system breaks encapsulation; or (c) invent some kind of generic constraint language so that constraints like this could be expressed without exposing field names. Choice (b) is incomplete, as there will often be times when I need to ascribe a type to a parameter or some such thing, and the lack of ability to express the complete type system will be rather limiting. Choice (c), though, looks a little daunting. So I'll stop there. The point is that while it is emphatically true that this kind of stuff is possible, it is also very hard in Java. Partly, that's because Java is an imperative language, but it's also because there are fundamental design trade-offs involved between verbosity, complexity, expressive power, locality of knowledge, etc. that are bound to be there in all programming languages, and which make it harder to take one design principle to its extreme and produce a usable language as a result. I don't know that it's impossible for this sort of thing to be done in a usable Java-like language, but in any case, the way to accomplish it is not obvious. -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list