Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: "strong typing" is a meaningless phrase

by dragonchild (Archbishop)
on Dec 14, 2004 at 18:19 UTC ( [id://414797]=note: print w/replies, xml ) Need Help??


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

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.

  • Comment on Re^2: "strong typing" is a meaningless phrase

Replies are listed 'Best First'.
Re^3: "strong typing" is a meaningless phrase
by hardburn (Abbot) on Dec 14, 2004 at 20:13 UTC

    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.

Re^3: "strong typing" is potentially ambiguous
by sleepingsquirrel (Chaplain) on Dec 14, 2004 at 21:39 UTC
    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.

        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.
        Ah, here's where we part company. C and Java have many types (unlimited in fact, go ahead make your own structs, unions, etc.). And they also do their type checking at compile time. Sure, if you want you can subvert the type system in a way that you couldn't with an ML or Haskell, but its much harder to do it accidently. Fewer types is synonymous with having fewer proofs of the programs behavior. I like perl as much as the next guy (heck, counting just now, I've got 6 books on my bookshelf with "perl" in the title), but all else being equal (i.e. same quality programmers, etc.), if I had to choose between being hooked up to a heart/lung machine running Java, and one running Perl, I'd pick Java. I wonder what they really use? If we knew the answer we'd probably all shudder. Now the question becomes, if I was going to design the heart/lung machine I'd be using on myself, what language would I use? I'd probably want to create some sort of very minimal strongly-typed hybrid lisp/haskell, in which I'd proven the compiler correct with some sort of computer algebra system.

        If you want more typing theory discussion than you can shake a stick at, I'd recommend some of these threads...

        Why type systems are interesting
        Why type systems are interesting - part II
        Why type systems are interesting - part III: latent types


        -- All code is 100% tested and functional unless otherwise noted.
      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.

        A type is a set of values

        Note that most type theorists say that type theory is based on Category Theory, not Set Theory. Category Theory is much broader and more ambitious than Set Theory.

        "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.

        A type is a set of values ...

        I'm glad you brought this up; it gives me a chance to take the flame war in a different direction. ;-)

        Under some ped^Wsemantic systems at least, what you've given, above, is a definition of "class", whereas "type" is defined in terms of behavior, not representation. If two objects can "do the same things", then they're the same type. (Usually this means having the same defined behavioral interfaces, irrespective of actual implementation. Sometimes the definition is made more strict: to "do the same thing", the objects must have idential implementations.) Of course, OO language vendors (who shall not be named, *cough*), prefer to use the terms "type" and "class" interchangeably, it seems.

        Stand by for updates as I'm forced to recant...

        I recently came across this paper which gives a nice introduction to some advanced type theory.


        -- All code is 100% tested and functional unless otherwise noted.
        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?
        Yes, that could have meaning. If you're the person designing the type system, you get to decide which statements have meaning. So you weigh the trade-offs. On the one hand, allowing the use of '+' in a statement like 3.14 + "dog" has the advantage of being short and sweet; easy for the programmer to type, and it reduces the number of operators/functions he has to learn. And if the programmer has a question about the semantics, he can look it up in the manual. On the other hand, you ask if it is really so much trouble to break that operator into two separate ones: stringify(3.14) + "dog" or 3.14 + numify("dog") . Now the programmer is forced to make his intentions explicit in the code, rather than implicit (i.e. in the documentation). Is one method better/faster/cleaner/buggier than the other? You get to decide (but be forewarned, that's the stuff of holy wars).


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found