Strong Typing?
Nov. 17th, 2005 08:34 amGeek question:
What is the feature of a language that you consider "strong typing"? How does strong typing manifest itself (or not) in your favourite language or two?
Geek question:
What is the feature of a language that you consider "strong typing"? How does strong typing manifest itself (or not) in your favourite language or two?
(no subject)
Date: 2005-11-17 08:42 pm (UTC)$ cat test.pl
$foo="a";
$foo=++$foo;
print $foo;
print "\n";
$ perl test.pl
b
But, that reveals a parallel ambiguity in expressing "incremement" versus "add 1" in most languages. Perl (and other languages borrowing heavily from C) distinguish between them; other languages don't, and some use a partial typing to "do what I mean". Javascript doesn't like incrementing a string at all,
javascript: var foo = "a"; document.write(++foo);
NaN
which kind of indicates that it's doing some DWIM with regard to the "+" operator.
At the opposite end of things, we've got bourne shell scripting where EVERYTHING is a string operation, unless specified otherwise:
$ foo=1+1
$ echo $foo
1+1
$
If you specify the operation to be a numerical calculation,
$ foo=$((1+1))
$ echo $foo
2
$ foo=$((a+1))
$ echo $foo
1
$ echo $a
$ a=a
$ echo $a
a
$ foo=$((a+1))
/bin/ksh: a: expression recurses on parameter `a'
$
(no subject)
Date: 2005-11-17 08:44 pm (UTC)$ foo=$(($a+1))
/bin/ksh: a: expression recurses on parameter `a'
$