jQuery in Action, 3rd edition
The moose likes Scala and the fly likes Scala type system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Scala
Bookmark "Scala type system" Watch "Scala type system" New topic

Scala type system

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

Are Guido and Steve thoughts correct regarding Scala and its typing system?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
That's a hard to answer for someone else. I can only say that it hasn't been a problem for me, but I rarely wade into the deep end of the type system pool. It is more complex than Java's type system, and the type guru's can do some weird tricks with it. Sometimes I'll look at a message on the scala-user mailing list and think, "What on earth is that supposed to do?" But those messages usually only come from a few people who really enjoy diving into the hairier parts of the type system. The majority of the time, I just let the type inferencer work its magic.

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
The trade off is that Scala's type system allows one to do things which are absolutely not expressible in Java. The critics will argue, "We've been expressing our types just fine in Java, if Java's type system doesn't have it that's because it doesn't need it." Which may be true, but some things sure are nice when you learn how to use them.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15093

I prefer the static typing of Scala or Java above the dynamic typing of Python or Ruby, especially for larger, non-trivial software projects.

I've never written a large project with a dynamically typed language, but I can imagine it would become a mess if you'd have to keep in your head all the time what type of data is supposed to be in each variable, and the compiler doesn't do anything to help you. It would be really easy to make mistakes. Proponents of dynamically typed languages say that you just have to write unit tests, but think of all the unit tests you don't have to write if the compiler checks the types for you. I'd rather have the safety of static typing than having to write lots of boring unit tests.

Scala's type system seems more complex than that of Java, but it is also more powerful and better implemented. When I learned about how generics and for example variance annotations work in Scala, I understood better what the issues are with Java's implementation of generics.

And it isn't so that the complexity of Scala's type system is inevitable - the basics are just as easy as Java, and you're not forced to use the more advanced features.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Scala's type system is not trivial (there's a very nice explanation on Programming Scala: The Scala type system ), but is powerful and expressive.
On the other hand, is no surprise that Guido (creator of Python) and Steve (who pushes JavaScript as the "Next Big Language") came against Scala's type system: they're promoters of dynamic typing languages, clearly they would not like a static typing one!
I'm pretty sure that some fans of Haskell would consider Scala's type system "not complex enough"

Software Surgeon
I agree. Here's the link: http://aspose.com/file-tools
subject: Scala type system
It's not a secret anymore!