http://qs321.pair.com?node_id=160252


in reply to Griping about Typing

I've usually been told "strong typing: good!" with no rationale. Occasionally, I'm told "strong typing helps prevent programmer error", with no explanation of how it prevents errors. (Okay, so it stops me from adding a string and an int. If I was adding strings and ints and expecting to get something useful, I have deeper problems than weak typing.)

It occurs to me that a C-like "suggested typing" system encodes some information about a variable's domain. For instance, declaring int foo; says some things about foo: it measures a discrete value, for one. Chances are, the more information you give the person reading your code, the better; on the other hand, I can't think of any situation where this would be more useful than a proper variable name (my $line_count;).

About the only advantage I can see in a stronger typing system than Perl's is the ability to align data in memory very precisely, which is useful when you're talking directly to hardware. I don't know of anyone doing that in Perl, though, and it doesn't require a strongly typed language: C does it rather well.

--
:wq

Replies are listed 'Best First'.
Re: (FoxUni) Re: Griping about Typing
by kappa (Chaplain) on Apr 19, 2002 at 08:23 UTC
    You wrote:
    Occasionally, I'm told "strong typing helps prevent programmer error", with no explanation of how it prevents errors. (Okay, so it stops me from adding a string and an int. If I was adding strings and ints and expecting to get something useful, I have deeper problems than weak typing.)
    Please consider this C code:
    char name[] = "miguel"; int st_len = 0, namel; namel = strlen(name); st_len += name;
    See my error (actually a typo)? See how gcc warnings (which are kinda weak strong typing) save my time?