bcholmes: (Default)
[personal profile] bcholmes

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)
From: [identity profile] hellsop.livejournal.com
It's programming languages... "should" hardly enters in. The distinction between adding 1 and incrementing isn't express in the sample. perl can do that as well, and gets the result you're expecting:

$ 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)
From: [identity profile] hellsop.livejournal.com
also

$ foo=$(($a+1))
/bin/ksh: a: expression recurses on parameter `a'
$

Profile

bcholmes: (Default)
BC Holmes

February 2025

S M T W T F S
      1
2345678
9101112131415
16171819202122
2324252627 28 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Powered by Dreamwidth Studios