Typing Systems 101. HINT: The understanding of weak/strong typing expressed in this thread is mostly wrong.
Dimension 1: Strong vs. Weak: While ever so often this dimension gets interpreted as automatic type coercion or not, that's not really the case. Note that if it means automatic type coercion, virtually all languages ever written are WEAK, including java. After all, "" + true works out and automatically coerces the boolean into a string first. So does "2 + 5.0", which will coerce the integer '2' to a double. The only exception I know of is Haskell. What it really means is: Do OBJECTS know their own types, and do they police this fact? For example, C is weakly typed. If you cast an object to a type that it isn't, you can do that. And usually core dumps occur. C also has no such concept as 'instanceof', which is a clear sign of a strong language. Python, Java, C#, and Scala are all strongly typed. Dimension 2: Dynamic vs. Static: Whilst dimension 1 was all about the objects themselves, Dynamic v. Static is about variables. Variables are distinct from objects. A variable is basically a pointer, or a 'reference'. Do these references hold types? In java, yes: You write "String x" and not "var x". In python, no: Variables just exist and you can shove whatever you want in them. Generally speaking, in dynamic languages, you can try any construct on an object and a check to ensure that the object even contains this construct is done at runtime. In other words, you can call any method on any object, and at runtime you'll get an error if said object doesn't have that method. In static languages, on the other hand, the reference has to have the appropriate type. Java is static. Python and Ruby and javascript aren't. Dimension 3: Manifest vs. Latent typing. Scala seems 'dynamic' because you can write 'var x' or 'val x' instead of 'String x'. But they aren't - the type of 'x' in: "var x = "foo"" in scala is still String, it's just inferred. Languages that infer types are latent languages. Languages that force you to be explicit about it are manifest languages. As usual this isn't a black and white kind of deal. Java is probably the most manifest language ever designed, whereas something like haskell is very latent. Scala is somewhere in the middle. Even java has latent bits, though. Such as inference of generics in methods. Dimension 4: Nominal vs. Structural. In a nominal language, types have names. For example, in java, which is almost entirely nominal, you have Guns and Cameras. You don't have "thingies that have a shoot() method". Even if both the Gun interface and the Camera interface have a shoot method, guns aren't cameras, and you can't cast one to the other or treat one as the other. In structural languages, you CAN - the only important fact is that a certain type has a certain construct in it. Here, too, you can have hybrids. For example in scala you can create an ad-hoc interface that means: "Anything that has method X() in it", and any object that does can be cast to this, and then you can call X on it. Regardless of name. You really could create a Shootable interface and ad-hoc cast both Guns and Cameras to this. In java, you can't. However, java does have some structural bits. For example, executable classes are structurally defined: It's anything that has a method with signature "public static void main(String[] args)" in it. That's structural, obviously. The nominal solution would have been to create an "Executable" interface containing "public void main(String[] args)" and adding a rider that the JVM will call your no-args constructor before invoking your main method. Java is 99% Nominal, 90% Manifest, 90% Static and 100% Strong. Most other languages aren't that easily described. For example, scala is about 70% Nominal, 65% Latent, 95% static and 100% Strong. For example, even java isn't 100% static because 'null' not being part of java's type system is clearly a dynamic quirk. Any given reference of type "String" for example can contain either a string OR not a string (null), and this isn't in the type system. One can imagine a language that has no null, or a language that does, but only the type "String?" can hold it, and not "String". On Apr 23, 2:57 pm, Robert Casto <[email protected]> wrote: > I think the issue has to do with features and functionality. They want to be > more productive and with these new languages, you can do that. I think your > concerns are valid though. Unless you are careful, there are plenty of > opportunities for bugs. The new languages do a lot of things better and they > are trying to eliminate the problems you mention. Still, I like being told > about problems at compile time rather than during testing or worse, in > production. I came to Java from C/C++ and enjoyed the garbage collection, > simpler reference handling, and other features. These new languages are much > more productive, but there are always tradeoffs. > > > > > > On Thu, Apr 22, 2010 at 2:06 PM, scphantm <[email protected]> wrote: > > ive been looking a few languages the past few days, groovy, ruby being > > the big two. i see all over the web people praising the world of > > dynamic type languages and the same question keeps ringing in my head, > > WHY IN THE WORLD WOULD YOU WANT A DYNAMIC TYPING LANGUAGE???? i came > > to java from the VB and PHP world. both of those are dynamically > > typed and it was that one thing that drove me nuts. especially in > > working with teams of developers. when i moved to java and its static > > typing system, everything finally made sense, tweetie birds were > > flying, humming birds were humming around around and i was in love, i > > found a language that is quick and has inherent type checking built in > > at compile time. > > > i just remember the disasters and amount of bugs that occured with me > > in the dark days of (god help me) asp, vbscript, and to an extent PHP > > and don't understand why anyone in their right mind would not want > > their language of choice to be statically typed? ive heard the answer > > of, well its easier, in this case in my mind easy=lazy. i don't get > > it, please educate me. > > > -- > > You received this message because you are subscribed to the Google Groups > > "The Java Posse" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<javaposse%2bunsubscr...@googlegroups > > .com> > > . > > For more options, visit this group at > >http://groups.google.com/group/javaposse?hl=en. > > -- > Robert Castowww.IWantFreeShipping.com > Find Amazon Filler Items easily! > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/javaposse?hl=en. -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
