Re: design question about "programming to interfaces"
Tom Forsmo wrote:
In any case, this leads me to an observation I just made. It seems to me
that a lot of the work in programming java is dealing with indirection
code to solve how to dynamically pass/invoke different object types.
Would it not be easier if java did not have types, in the same way as
f.ex. python, ruby(?), lisp. Then, my original question would not apply.
My reason is as follows. When I program I know what data/object types
apply in the different cases, so I don't need the system to check that
for me. Hence all the indirection code to fool the system into passing
the data/objects I snot needed. I know there is the question of what
about when I make a mistake and pass the wrong object to a method, and
that java can check for such errors before hand. But it still makes for
an interesting idea, albeit, maybe a bit heretic in this news group :)
Yes, it would not be easier. You could use Map <Object, Object[]> or
Map < ? extends Object, Object []> with appropriate casts with equal ease.
Removing types from Java, quite aside from making the language not be Java,
would complicate all sorts of other things that types and type-safety make
possible, much less easier. Types exist for a reason (many reasons), not just
to make your one "original question" harder for you to solve.
Your representation of the object-oriented type system as existing to "fool
the system" bespeaks a fundamental lack of understanding about types. Just to
mention one purpose, types properly used usually permit the compiler to catch
and prevent errors at compile time before they become bugs at run time.
If you prefer typeless programming, there are alternatives to Java. It
doesn't make sense to suggest undoing the most fundamental aspect of the
language, not because it's heretical but because it is fundamentally off.
It's like suggesting that carrots would be better if they were made of aluminium.
- Lew