You're probably thinking of duck typing specifically. A lot of people who like dynamic typing like it because the code seems less verbose. DEF FN f(x) = x * 2 (Spectrum 48K BASIC!) is easier to read than the equivalent Java: public static int f(int x) { return x * 2; } and even the equivalent Scala: def f(x: Int) = x * 2, but it should be noted that there are typed languages (which don't do subtyping) that don't require you to write types explicitly ever, but don't mind terribly if you prefer to:
f x = x * 2 -- Haskell. And unlike the Scala or Java versions you can call Haskell's f on anything that's a member of the Num type class (i.e., Int, Double, etc.). In Java you'd need to copy and paste f a number of times to make it work for anything for which * is defined upon. Regarding duck typing, most of the benefits of emulating that in Scala are when working with code that can't be changed. E.g., some types with a close() in the Java libraries do not implement Closeable, so if you want to be able to accept anything that can be closed you use structural types. Other than that I don't think it's worth designing with structural types in mind. Nominal types will normally be far superior. The other benefits of duck typing can't be emulated with structural types. You would have to use reflection. Paul Phillips has written a convenient 'extension method', o, for reflectively accessing methods not known at compile time, e.g.: Class.forName("Bob").newInstance o "fireTheMissiles" I'm not convinced that's a good thing, but I think it's just an experiment and not in the standard library. Perhaps Scala will gain a 'dynamic' type like C# did recently. I don't think I'd use it other than if I needed to communicate with Ruby or some other untyped language, but if there's enough clamour it may happen. Ricky. -- Ricky Clarkson Java and Scala Programmer, AD Holdings +44 1928 706373 Skype: ricky_clarkson On Thu, Sep 9, 2010 at 10:34 AM, B Smith-Mannschott <bsmith.o...@gmail.com> wrote: > > > On Thu, Sep 9, 2010 at 08:28, Casper Bang <casper.b...@gmail.com> wrote: >> >> > I still have some hope for Fantom because I don't think it crossed that >> > threshold yet, but it's getting dangerously close to it. >> >> What speaks to Fantom's advantage is it's dynamic typing feature, >> something Scala ignores completely - in spite of various luminaries >> view that the static and dynamic world will inevitably merge down to >> opt-in semantics. Unfortunately Scala seems to run with all the >> attention, regardless of the bad taste in the mouth it leaves with lot >> of people. > > You can get much of the benefit of dynamic typing by using Scala's > structural typing: > http://codemonkeyism.com/scala-goodness-structural-typing/ > This has been part of the languge since at least 2.6 (July 2007). (3 years!) > I'm more and more convinced that the "bad taste in the mouth" people > complain about is born of ignorance. It's just the natural reaction many > have when confronted with something new and unfamiliar. Of course one feels > like a klutz at first, working with a new language with new concepts, > conventions and syntax. That's normal. Anyone who's learned more than one > language must know this by now. I found Clojure pretty weird when I started, > and that despite previous exposure to Scheme. Now I find, I can appreciate > its advantages. I'd encourange those unfamiliar with Scala to cut it some > slack or get familiar with it before spouting nonsense. > // Ben > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to javapo...@googlegroups.com. > To unsubscribe from this group, send email to > javaposse+unsubscr...@googlegroups.com. > For more options, visit this group at > http://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 javapo...@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.