English 中文(简体)
To use or not to use Scala for new Java projects? [closed]
原标题:
  • 时间:2009-11-14 12:18:41
  •  标签:
  • java
  • scala

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java?

EDIT: And, do you think Google s Noop, Fan or Scala can take the leadership from Java in the near future, which one have chance in your opinion?

最佳回答

Don t forget that you can use it alongside Java. i.e. you can make use of compiled .classes and .jars within a Scala-scripted environment.

So you may want to encode the lower-levels of your solution in Java and then wrap these in Scala to provide a more flexible and agile solution (in terms of rewriting business logic at a higher level).

Something to consider is who else is going to look after this and maintain it. For all of Scala s hype, relatively few people can code in it (as of Nov 2009), and you may have to hire people in the future to look after it. Looking for Scala people will mean you re looking in a much smaller pool of candidates (some may want to learn Scala on the job, but there s still a start-up cost)

问题回答

Here are the pros and cons of Scala relative to Java IMHO:

Pros:

  • Much more concise syntax for idioms common in modern Java code
  • Closures
  • More powerful type system including mixins
  • Pattern matching
  • Great REPL, 2.8 will even have tab-completion

In summary: You get a lot more functionality with a lot less code than Java

Cons:

  • IDE support is still of alpha or beta quality, although IDEA has the best support currently
  • The standard library is not immune to changes with each new version (2.8 will have backwards incompatible changes)
  • The standard library had significant bugs at least as recently as a year ago (when I found one in the JSON support)

I think Scala will be ready for major production use in 6-8 months, but I wouldn t bet my project on it today.

Don forget that it s a relatively small piece of Twitter, notably the message queues, which are written in Scala. From what I understand, the front-end is still Ruby-on-Rails.

That said, I migrated to scala under a year ago: I haven t looked back. Furthermore:

  • there is a large pool of graduates who are very interested in coming to work in a scala shop
  • the fact that scala is built to run on a JVM means that Java developers get a head-start in the language (if you re interested I could expand on why this is so).

A particular issue with Scala is that as a scalable language, it has levels of features of varying degrees of accessibility to the average developer. Using it at as a scripting language for the JVM is one thing, developing a domain-specific language using functional programming is another.

One advantage of Scala is that you can build it alongside Java in the same project. Both Maven (see luigi-prog s comment) and simple build tool have fairly simple hooks that will build everything in one go.

Another way is to take existing unit tests, switch the implementation, see the difference.

Daniel Spiewak had a few nice entries on the gotchas of Java-Scala interop.

I have been using Scala in the workplace for the past year, and I d say it s about a 3-month learning curve to become fairly proficient. This is with a fairly small group of typical Java people. There s a lot of volatility yet in terms of conventions and standards, so expect to do some revision on any project every few months.

I don t think you can search for Scala programmers just yet. But you can find lots of Java programmers who are interested in learning Scala.

If I were to guess, Scala and Clojure might be the front runners for supplanting Java. I wouldn t expect a major shift until 2012 at the earliest. Scala probably leads in momentum - there are several books in multiple languages now.

If you are considering using Java and Scala in a single project environment, I would suggest using Maven as a project dependency system. Here is the code I use to generate my scala projects:

mvn archetype:generate -DarchetypeCatalog=http://scala-tools.org/

Here is some usage information for using maven with Scala. If you use maven as the compiler, you can have both java and Scala source files in the same package with no extra configuration. It just works.

Here is a talk hosted by LinkedIn. Its a Panel with Scala, Twitter, and Scala lift web framework (which I use). If you are still deciding whether to use Scala id suggest watching it.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签