in reply to "strong typing" is a meaningless phrase
in thread (Completely OT) - Hero(i)n programming language on Slashdot

Then consider that you've told perl not to check for type violations.
Hmm. Honest question: how do you tell perl to turn on type checking?


-- All code is 100% tested and functional unless otherwise noted.
  • Comment on Re: "strong typing" is a meaningless phrase

Replies are listed 'Best First'.
Re^2: "strong typing" is a meaningless phrase
by dragonchild (Archbishop) on Dec 14, 2004 at 18:19 UTC
    What do you consider "type-checking"? That's also an honest question - it means different things to different people.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      In the litature, types systems are well-defined. In essence, a type system limits what operations you can do with a given piece of data.

      Note that "types" come out of formal logic, and predate computer science.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      Alright, jdporter from below has a good pointer to a message about typing my MJD, where Mr. Dominus lays out some of the crucial issues. Here's my view on the issue of typing. First, I'll tackle my definition of typing. A type system is a meta-program which examines other programs in order to prevent meaningless ones from executing. Take the set of ASCII files. Only a small number of those are valid perl programs which will pass a perl -c check. Now take the set of perl programs. A type checker would disallow certain syntatically correct programs that didn't conform to the type system. The classical example (forgetting perl for the moment) is a statement like 3.14 + "dog". If we assume that 3.14 is a floating point number, "+" is the addition operator, and "dog" is a string, most people might agree that the statement is meaningless. So the people creating your type system might say, "Arrrgh! That's garbage, let's outlaw the programmer from using statements like that." Or the less controversial statement, "That statement has little meaning, we'll add more value (through program clarity, cleaner semantics, fewer typos, etc.) by banning such statements." Of course the other camp says, "We don't like meaningless programs either." So they solve it by decreeing that every syntatically valid program has meaning. And you get (well documented) behaviors like, $a = $b + @c; where the array @c in that statement refers to the length of the array, instead of the actual array.

      Now, I'm going to submit to the jury that the "strong" part of "strong typing" is currently potentially ambiguous. I say currently, because eventually, I think enough people will start to agree on one definition (here's to hoping they pick a version close to mine). Different people will see things differently. Just like the word "hot". Some might say that the sahara desert can get hot. Residents of Venus might disagree. But most of us will agree that the surface of the sun is hotter than the surface of Pluto. So I'll try to outline some of the things that I think make a type system "stronger".

      • A larger number of types make the type system stronger. If you only have one universal type, you can't have type errors and won't reject any programs.
      • Fewer number of implict conversions makes the type system stronger. If the system automatically converts between all types (regardless of how well documented) you're no better off than the system with one type.
      • Catching type errors earlier makes the type system stronger. Catching errors at compile time is better than at run time. And catching type errors at run time is better than not catching them at all (i.e. core dump).
      Questions? Comments? Suggestions?


      -- All code is 100% tested and functional unless otherwise noted.

        A lot of the "strong typeing is good!" comes out from people who use (by choice) langauges that are more acurately called "static" (i.e., the types are determined at compile time), not "strong". Any language with a type system like Pascal's falls into this category (including C and Java).

        However, most of these people don't realize what a real strong type system looks like (for starters, real type systems don't need int/float/etc. declarations). There are languages with weaker type systems (like TCL, where everything is a string weather you like it or not), but C and Java are actually pretty far down on the list in regards to the strength of their type system.

        You are correct to say that the strength of the type system is not a binary proposition, but rather a ranking. I assert that Perl's type system is overall stronger than C's or Java's, even if it's limited in the number of types it has. OTOH, it's significantly weaker than OCaml or Haskell.

        "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        The classical example (forgetting perl for the moment) is a statement like 3.14 + "dog". If we assume that 3.14 is a floating point number, "+" is the addition operator, and "dog" is a string, most people might agree that the statement is meaningless.

        *thinks real hard about this*

        So, if I'm understanding what you're saying and all the links that have been provided ... we could arrive at the following definitions:

        • A type is a set of values (with defined characteristics for inclusion) for which a set of meaningful operations is defined. (Whether or not the set of operations is closed over the set of values is indeterminate.)
        • A type system is a set of types. (Whether or not the various types overlap is indeterminate.)

        So, in your example, the operation '+' isn't defined for the value "dog". However, let's say we had the operation '_' (string concatenation). It would be defined for "dog" ... it could also be defined for "3.14". So, the statement 3.14 _ "dog" could have meaning ... right?

        I do understand what all the fuss is about re: types ... having a strong type system would eliminate whole classes of bugs, in the way that automatic memory management has eliminated a whole class of bugs. Arguably, it is the Lazier solution to do this. And, I think that some of the people on the lambda site are correct in saying that it's a sociological issue, not a technical one ... sort of.

        I think I need to think on this topic some more ...

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^2: "strong typing" is a meaningless phrase
by ysth (Canon) on Dec 14, 2004 at 22:41 UTC
    types.pm is an effort in that direction.