开发者

How to tackle Scala source incompatibilities in 2.8.0?

There are a few cases of source incompatibilities with Scala 2.8.0. For example, creating an anonymous Seq once required defining the abstract def elements : Iterator[A], which is now called def iterator : Iterator[A].

To me, a "brute force" solution is to create two branches that align to the different major scala versions.

Are there general techniques s开发者_StackOverflow中文版o that code like this will compile under both systems?

// Note: this code resembles techniques used by xml.NodeSeq
trait FooSeq extends Seq[ Foo ] {
   def internal : Seq[ Foo ] 
   def elements = internal.elements
   def iterator = internal.iterator // Only compiles in 2.8
                                    // need to remove for 2.7.X
}


There are a few cases where usage is simply different and you must change. But in almost all cases--such as the elements code above--the 2.7 style is simply deprecated in 2.8, not gone altogether. If you're okay leaving your 2.8 users with deprecation warnings (edit: if they compile your code, otherwise you'll just have the warnings yourself), just implement the new features in terms of the old:

def iterator = internal.elements

Otherwise, I would recommend what you call the brute force solution. Use a sufficiently clever VCS so that you don't actually have to write much code twice (Git, Bazaar, Mercurial) and branch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜