Re: design question about "programming to interfaces"
Lew wrote:
Lew wrote:
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.
Tom Forsmo wrote:
Could you explaining in more detail all the things that would
complicate it, because the one example you gave as an oppositional
argument I seem to have mentioned in my previous post.
Consider an object in a typeless language like VBscript or Javascript,
with the pseudo-syntax:
v = "some string";
v = 143.5;
v = new { a="String element", b=16 };
Being untyped, v could be assigned an unexpected type occur at the wrong
time in a program, say in a function that has a bug,
The caller might try to dereference v after the function,
Yes that is true, but only for an immature language.
In perl, for example there is a separation between scalar, arrays and
associative arrays. In Lisp, there are only lists as a type (there is
structs and objects as well, but they have to be explicitly defined and
hence separable from lists.) In python you have the same.
But of course, in a lesser language one would try to use some language
idiom to avoid that problem, such as "treat a specific variable as a
single/same type always". If not, you are asking for trouble. Much in
the same way as you need to learn the C pointer idioms before you can
handle pointers without problems.
Many language problems can be overcome by learning the proper idioms,
that does not mean that there does not exists better and safer solutions
for the problem than the idioms try to solve.
Java was designed to be type-aware from the beginning; making it untyped
would make it not Java. Sure, there are times when untyped languages
are more convenient; that's why they exist. For large applications
type-aware languages are very helpful.
....
That's part of why C++ has
gained traction over C, and why C# and Java are in their ascendancy.
I am not sure if what you are saying here makes any sense. But, the
reason why OO by way of C++ and C# and Java won is that C is not as
suitable for making business systems, which is what the majority of
programming in the world is about. C (and other procedural languages) is
better suited for system/technical programming.
When it comes to the type-aware languages argument, that has to do with
the fact that until recently (5-10 years ago) interpreted/type less
languages were slower and less efficient than compiled type safe
languages. So therefore type safe languages got more attention.
(As a side note. Today it is widely accepted, by academia and the best
system architects in the world, that the only way we can continue to
create more and more complex systems is if the programming languages and
tools develop so they can handle the increasing complexities of
programming and help the programmer do more in less time and with less
resources. A type less language is considered one of the developments
that can reduce the programming complexities by an order of magnitude.
Other developments are programming to interfaces, incremental
compilation, auto completion, auto build systems, iterative development
and many other auto magic tools that the computer can use to relieve
the programmer from mundane or complicating work).
tom