

Java.next() - Scala: The Revenge of the Static Typing - bozhidar
http://batsov.com/2011/05/08/jvm-langs-scala.html
An overview of the Scala programming language. Part II of the series Java.next()
======
lloeki
Worthwhile article, if only for reading one of the less biased dynamic vs
static typing pros an cons.

~~~
thesz
I should note that author added some unneccessary cons to static types.

He said that metaprogramming is hard. The area of metaprogramming is partially
covered by higher-order functions. The coverage is big, in my opinion, I
haven't missed metaprogramming in Haskell for ten years, at least (I missed it
for first two weeks with Haskell).

He also said that there's no mechanism to compensate for the absence of duck
typing. In Haskell, at least, there are type classes which allow you to make
your types as duck as you would wish, maybe slightly less. I think that some
Scala mechanisms provide that power.

~~~
dan00
"He also said that there's no mechanism to compensate for the absence of duck
typing. In Haskell, at least, there are type classes which allow you to make
your types as duck as you would wish, maybe slightly less."

I think that type classes are the way to go.

Duck typing is mostly popular because multiple inheritance sucks, and because
inherting a class to only overload a method sucks.

Languages like Ruby, Python or Perl are so popular because they are less
verbose than Java or C++, with the disadvantage, that the compiler can't help
you that much.

Haskell is a language that combines the advantages, less verbosity with a
helping compiler, and a static type system that rocks.

~~~
rit
While this is a statement in some ways of preference it is a reasonable
comment; not sure why it's getting downvoted.

However, can you clarify why you would argue for type classes over
duck/structural typing? You indicate that 'type classes are the way to go' but
don't explain why.

Scala of course does have a form of Type Classes and while they tend to be
what I reach for more often than Structural Types in Scala, it doesn't obviate
Structural Types completely and I'd be interested in analysis of the diffs.

~~~
kscaldef
With dynamic duck typing you just have to hope the object actually quacks.
With type classes, the compiler proves it quacks.

------
st0p
Interesting article, but I did wonder what he means with this: Duck typing
allows to reduce immensely the coupling between your classes

Can anybody explain?

~~~
js2
Let's say that I have a list of objects of mixed type, and I only care that
they implement a given method. With duck typing, the types of the objects need
not be coupled via a common base class (or even interface). For example:

    
    
      # Less coupled
      class A:
         def foo(self):
           print "A"
      class B:
         def foo(self):
           print "B"
    
      for x in (A(), B()):
        x.foo()
    

vs:

    
    
      # More coupled
      class Base:
         def foo(self):
           pass
      class A(Base):
         def foo(self):
           print "A"
      class B(Base):
         def foo(self):
           print "B"
    
      for x in (A(), B()):
        x.foo()

------
bkudria
What's a well-designed statically-typed language whose syntax resembles more
Ruby than Java/C/etc.

I'm thinking something like SML. Any others?

~~~
primodemus
CLU comes to mind. <http://en.wikipedia.org/wiki/CLU_programming_language>

A hello world sample: <http://hopl.murdoch.edu.au/showexample.prx?exp=59>

~~~
bkudria
I was hoping for something a bit more ... modern. A real language used in
production systems.

------
TheBoff
This is a good article, but I must take issue with "Static typing allows you
to generate the optimum bytecode/binary", simply because whilst you generally
get faster binaries, you can't know that it's optimum.

Just a nitpick, though.

~~~
bad_user
Another nitpick -- static languages on top of the JVM are indeed able to
generate faster binaries.

But that's only because the JVM was optimized for Java. And the fastest
language around, X86 (or MIPS) assembly, is completely dynamic and loose.

I don't think it's a secret that commercial Smalltalk VMs kicked ass while
executing one of the most dynamic languages in existence ... where performance
was (and still is) comparable (even better in some tests) to the JVM or .NET

------
orangecat
I don't get the claim that dynamic typing requires more unit tests. Sure if
you pass a string to a Python function that expects an int it will blow up at
runtime, but is there any value in testing for that?

~~~
snprbob86
If you are doing TDD and are aiming for near complete specification and
coverage, then dynamic languages and static languages will pretty much require
the same number of use cases.

However, most people _don't_ do TDD. With a dynamic language, your compiler
isn't doing entire categories of checks for you. You're putting more
responsibility on the tests, so you wind up writing more of them sooner and
running them almost as frequently as static language users run their
compilers!

Since people generally stop long before 100% coverage, you wind up with far
more tests for the average dynamic project than the average static one.

~~~
jhpriestley
Complete specification is impossible with tests, except for functions with
finite domains.

Testing is about reducing bugs to a certain level. Entirely different
techniques - namely formal proofs - are required to eliminate bugs. Strong
static typing is more effective than tests, in terms of cost/benefit, at
reducing bugs.

------
Egregore
Can you please give some examples of real world applications in scala?

~~~
DavidMcLaughlin
Foursquare[1], Twitter[2], LinkedIn[3] and The Guardian[4] use Scala.

If you are looking for code examples, you can explore here:

<https://github.com/languages/Scala>

I have been using Scala lately for some personal stuff and I've really fallen
in love with it.

[1] - <http://www.scala-lang.org/node/5130> [2] -
[http://www.artima.com/scalazine/articles/twitter_on_scala.ht...](http://www.artima.com/scalazine/articles/twitter_on_scala.html)
[3] - <http://www.scala-lang.org/node/6436> [4] - <http://www.scala-
lang.org/node/7808>

~~~
jordibunster
Yammer also uses Scala for many of its backend services.

------
smcj
Scala 2.9 was released as well as Akka 1.1 today.

The companies behind have been merged to a new company called Typesafe which
offers Training, consulting, support and a tool stack containing Scala, Akka,
Eclipse and SBT.

The persons behind it read like a who-is-who of the JVM world:
<http://typesafe.com/company/team>

