Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: (OT) "Learn one new language every year"? Yeah, right.

by fergal (Chaplain)
on Oct 08, 2004 at 12:43 UTC ( #397625=note: print w/ replies, xml ) Need Help??


in reply to Re^3: (OT) "Learn one new language every year"? Yeah, right.
in thread (OT) "Learn one new language every year"? Yeah, right.

I don't like about Java and C++ (Static typing is just wrong!

Java and C++ are not really statically typed, in that they allow casts, in fact they require casts. This means that type errors can occur at runtime, which is exactly what static typing is supposed to prevent. Have a read MJD's excellent talk? You should read some ML or Haskell, you don't have get into monads to appreciate a lot of Haskell's typing system. I'm not even sure if I correctly understand monads because I haven't ever tried to write anything in Haskell but I can still appreciate what real static typing (with type inference so that you don't have keep telling the compiler things it could work out for itself) can do.

I think it's cecil that brings another rather cool feature to static typing, it lets you get it wrong but still compiles your code (issuing warnings of course). This allows you to experiment with your classes as in a dynamic language without having to rewrite half your code just to get it to compile.

So yes, Java and C++'s static typing is absolutely wrong but it's not really static typing.


Comment on Re^4: (OT) "Learn one new language every year"? Yeah, right.
Re^5: (OT) "Learn one new language every year"? Yeah, right.
by revdiablo (Prior) on Oct 08, 2004 at 17:28 UTC
    Java and C++ are not really statically typed

    They are not strongly typed, but they are statically typed. There is a distinction. Strong typing means you cannot easily convert between data types (for instance, Perl is strongly typed. It is not particularly easy to convert between an array and a scalar). Static typing means the types are determined at compile-time. Casting is what you have to do in C and Java to circumvent the static type checking.

    If you look at MJD's excellent talk again, you'll notice it is saying that strong typing can be good. It is also describing why static typing, as implemented in Pascal and C (and by extension, Java), is not very helpful.

      It seems to me that he is singing the praises of lanagues which are (according to your definitions) both strongly typed and statically typed.

      His Spectacular Example shows ML detecting an infinite loop at compile time (ie statically) but ML's fancy static type system wouldn't be much better than Java's if it wasn't also strong (that would essentially be Java + type inference, allowing you to cut out lots of declarations but still leaving you open to run time type errors). Strong without static would be Perl and that talk is definitely not a celebration of Perl's type system.

      The definitions are controversial and somewhere (possibily in that or another MJD talk) there's a list of about 8 conflicting definition for various kinds of typing but in that talk, on this page he says "static" and "strong" typing are the same.

      If you really want to make a distinction you could take "strong" to mean that conversions (casts) are impossible and "static" to mean that types are determined at compile time. Then, if you want to say that Java really is statically typed you should probably make it clear that you mean that "types are determined at compile time but might have been determined incorrectly". Come to think of it, that's a great definition, it makes it clear just how badly Java, C, and C++'s type systems suck.

      Maybe we should call Java a "hopefully typed" language :-).

        The definitions are controversial and somewhere (possibily in that or another MJD talk) there's a list of about 8 conflicting definition for various kinds of typing

        I would like to see this list. In my mind, the basic definitions are fairly straightforward, though there are many people who muddle them together. Just think about the words themselves: "strong" and "static." Strong typing imparts strength (as opposed to weakness) to the type system, and static typing imparts staticness (as opposed to dynamism).

        on this page he says "static" and "strong" typing are the same

        I think that page is saying that FORTRAN's type system is both static and strong. He doesn't talk a whole lot about a distinction between strong and static typing, but if you look at the talk notes, he does say, "contrary to what you might think, Pascal is not a strongly typed language, but a weakly typed one." This is after he has described it as statically typed. So he too seems to draw a distinction between the two.

        you could take "strong" to mean that conversions (casts) are impossible and "static" to mean that types are determined at compile time

        That is the definition of static I would use, but I'm not so sure about the definition of strong. That is too tied to a particular concept (i.e. casts) for me. I still like my earlier definition, "strong typing means you cannot easily convert between data types," but I know it's not perfect. Obviously, people will bicker endlessly about specific details of specific type systems, but I think the general idea is pretty simple to understand.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-08-27 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (235 votes), past polls