(I meant to include this in my previous post.)
One big difference is the ability to create heterogeneous lists with ease in untyped language. That allows us to create powerful general purpose functions. For example, compare
# "pack" in an untyped language.
my $packed = pack('c N c/a*', $c, $i, $s);
# "unpack" in an untyped language.
my ($c, $i, $s) = unpack('c N c/a*', $packed);
vs
# "pack" in an typed language.
Array<Object> unpacked;
unpacked.push(c);
unpacked.push(i);
unpacked.push(s);
String packed;
pack(packed, "c N c/a*", unpacked);
# "unpack" in a typed language.
Array<Object> unpacked;
unpack(packed, "c N c/a*", unpacked);
char c = unpacked[0];
int i = unpacked[1];
String s = unpacked[2];
I don't care so much about the difference in *code size*. The size is not that much different. (80% seems ridiculous.) In fact, the code is not that much different. The real difference is in the amount of *hassle*. Almost all of the extra code needed in a typed language is very repetitive.
In order to hide the extra code and avoid more hassle, you end up creating (repetitive) special-purpose functions as shown below. Of course, this is a hassle as well.
# "pack" in a typed language.
Func pack_my_format(String& packed, char c, int i, String s) {
Array<Object> unpacked;
unpacked.push(c);
unpacked.push(i);
unpacked.push(s);
pack(packed, "c N c/a*", unpacked);
}
pack_my_format(String packed, c, i, s);
# "unpack" in a typed language.
Func unpack_my_format(String packed, char& c, int& i, String& s) {
Array<Object> unpacked;
unpack(packed, "c N c/a*", unpacked);
c = unpacked[0];
i = unpacked[1];
s = unpacked[2];
}
unpack_my_format(packed, char c, int i, String s);
Note: For the typed language, I used a mixture of C, C++, Java, Pascal and Perl that keeps the code as small as possible. Features include implicit type conversion, autoboxing, object allocation without "new", no separation of variable declarations and code, templates or generics, a Variant type, etc.
|