This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.7 vs 2.8 gotcha

5 replies
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
I don't know if there's anyone keeping track of these, but a recent question reminded me of a difference on Scala 2.8, in case someone _is_ keeping track of them. :-)
A lot of collections/methods that used to ask for an A => Ordered[A] now ask for an Ordering[A]. It usually doesn't have any impact, but it might require change in places where A <% Ordered[A] is being used, as this implicit is not enough to satisfy the Ordering[A] that might be required on called methods/instantiated classes.

--
Daniel C. Sobral

I travel to the future all the time.
Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: 2.7 vs 2.8 gotcha
I'd really love a Scala 2.7.7 homebrew-collection to 2.8.0 migration kit with fluffy bunnies and hand-holding.

On Tue, Mar 30, 2010 at 9:09 PM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
I don't know if there's anyone keeping track of these, but a recent question reminded me of a difference on Scala 2.8, in case someone _is_ keeping track of them. :-)
A lot of collections/methods that used to ask for an A => Ordered[A] now ask for an Ordering[A]. It usually doesn't have any impact, but it might require change in places where A <% Ordered[A] is being used, as this implicit is not enough to satisfy the Ordering[A] that might be required on called methods/instantiated classes.

--
Daniel C. Sobral

I travel to the future all the time.



--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: 2.7 vs 2.8 gotcha
Paul Phillips committed some bunnies in the form of -Xmigration (I think that's the option). They aren't exactly fluffy, though, but there is some hand-holding included.
But, mostly, it's rather hard to know what may cause difficulty for people without them telling us in first place. :-) Chicken and egg, thingy.

On Tue, Mar 30, 2010 at 4:37 PM, Viktor Klang <viktor [dot] klang [at] gmail [dot] com> wrote:
I'd really love a Scala 2.7.7 homebrew-collection to 2.8.0 migration kit with fluffy bunnies and hand-holding.

On Tue, Mar 30, 2010 at 9:09 PM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
I don't know if there's anyone keeping track of these, but a recent question reminded me of a difference on Scala 2.8, in case someone _is_ keeping track of them. :-)
A lot of collections/methods that used to ask for an A => Ordered[A] now ask for an Ordering[A]. It usually doesn't have any impact, but it might require change in places where A <% Ordered[A] is being used, as this implicit is not enough to satisfy the Ordering[A] that might be required on called methods/instantiated classes.

--
Daniel C. Sobral

I travel to the future all the time.



--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall

Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang



--
Daniel C. Sobral

I travel to the future all the time.
ewilligers
Joined: 2008-08-20,
User offline. Last seen 3 years 17 weeks ago.
Re: 2.7 vs 2.8 gotcha

Viktor Klang wrote:
> I'd really love a Scala 2.7.7 homebrew-collection to 2.8.0 migration kit
> with fluffy bunnies

Hi Victor,

Here's my homebrew migration kit.

Please accept this free voucher for all the fluffy bunnies in rural
Australia. http://en.wikipedia.org/wiki/Rabbits_in_Australia

Happy Easter,
Eric.

> *** Explicitly import from outer packages ***
>
> Suppose we have
> package a
> class B
>
> Change
> package a.c
> class D extends B
> to
> package a.c
> import a.B
> class D extends B
> or
> package a
> package c
> class D extends B
>
>
>
> *** Use fully qualified package name when importing from outer
package ***
>
> Suppose we have
> package a.b
> object O { val x = 1 }
>
> Change
> package a.b.c
> import b.O.x
>
> to
> package a.b.c
> import a.b.O.x
>
>
>
> *** When explicitly specifying type parameters in container method
calls, add new type parameters ***
>
> Change
> list.map[Int](f)
> to
> list.map[Int, List[Int]](f)
>
> Change
> map.transform[Value](g)
> to
> map.transform[Value, Map[Key, Value]](g)
>
>
>
> *** Create sorted map using Ordering instead of conversion to Ordered ***
>
> [scalac] found : (String) => Ordered[String]
> [scalac] required: Ordering[String]
> [scalac] TreeMap[String, Any](map.toList:
_*)(stringToCaseInsensitiveOrdered _)
>
>
>
> *** Import the implicit conversions that replace scala.collection.jcl ***
>
>
>
> *** Immutable Map .update becomes .updated ***
>
>
>
> *** Migrate from newly deprecated List methods -- elements remove
sort List.flatten(someList) List.fromString(someList, sep) List.make ***
> Use List methods diff iterator filterNot sortWith
someList.flatten someList.split(sep) List.fill
>
>
>
> *** Migrate from newly deprecated Map methods keys values ***
> Use Map methods keysIterator valuesIterator
>
>
>
>
>
>
> *** classpath when using scala.tools.nsc.Settings ***
>
> http://thread.gmane.org/gmane.comp.lang.scala/18245/focus=18247
> settings.classpath.value = System.getProperty("java.class.path")
>
>
>
> *** Avoid error: _ must follow method; cannot follow (Any) => Boolean ***
>
> Replace
> list.filter(that.f _)
> with
> list.filter(that f _)
> or
> list.filter(that.f(_))
>
>
>
>
> *** Migrate from deprecated Enumeration methods iterator map ***
> Use Enumeration methods values.iterator values.map
>
>
>
> *** Migrate from deprecated Iterator.fromValues(a, b, c, d) ***
> Use Iterator(a, b, c, d)
>
>
>
> *** Avoid deprecated type Collection ***
> Use Iterable instead
>
>
> *** Change initialisation order ***
>
> Suppose we have
> trait T {
> val v
> val w = v + v
> }
>
> Replace
> class C extends T {
> val v = "v"
> }
> with
> class C extends {
> val v = "v"
> } with T
>
>
> *** Avoid unneeded 'val' in for (val x <- ...) ***
>
>
>
> *** Avoid trailing commas ***
>
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re: 2.7 vs 2.8 gotcha
Great stuff, though the "val" is older than 2.7. :-) Could you add it as an answer to http://stackoverflow.com/questions/1243794/what-are-the-biggest-differences-between-scala-2-8-and-scala-2-7?
By the way, keys and values are not deprecated anymore, I think.

On Tue, Mar 30, 2010 at 8:36 PM, Eric Willigers <ewilligers [at] gmail [dot] com> wrote:
Viktor Klang wrote:
I'd really love a Scala 2.7.7 homebrew-collection to 2.8.0 migration kit with fluffy bunnies

Hi Victor,

Here's my homebrew migration kit.

Please accept this free voucher for all the fluffy bunnies in rural Australia. http://en.wikipedia.org/wiki/Rabbits_in_Australia

Happy Easter,
Eric.


> *** Explicitly import from outer packages ***
>
> Suppose we have
>  package a
>  class B
>
> Change
>  package a.c
>  class D extends B
> to
>  package a.c
>  import a.B
>  class D extends B
> or
>  package a
>  package c
>  class D extends B
>
>
>
> *** Use fully qualified package name when importing from outer package ***
>
> Suppose we have
>  package a.b
>  object O { val x = 1 }
>
> Change
>  package a.b.c
>  import b.O.x
>
> to
>  package a.b.c
>  import a.b.O.x
>
>
>
> *** When explicitly specifying type parameters in container method calls, add new type parameters ***
>
> Change
>  list.map[Int](f)
> to
>  list.map[Int, List[Int]](f)
>
> Change
>  map.transform[Value](g)
> to
>  map.transform[Value, Map[Key, Value]](g)
>
>
>
> *** Create sorted map using Ordering instead of conversion to Ordered ***
>
>   [scalac]  found   : (String) => Ordered[String]
>   [scalac]  required: Ordering[String]
>   [scalac]         TreeMap[String, Any](map.toList: _*)(stringToCaseInsensitiveOrdered _)
>
>
>
> *** Import the implicit conversions that replace scala.collection.jcl ***
>
>
>
> *** Immutable Map  .update  becomes  .updated ***
>
>
>
> *** Migrate from newly deprecated List methods  --  elements  remove sort  List.flatten(someList)  List.fromString(someList, sep)  List.make  ***
> Use List methods  diff  iterator  filterNot  sortWith someList.flatten  someList.split(sep)  List.fill
>
>
>
> *** Migrate from newly deprecated Map methods  keys  values  ***
> Use  Map methods  keysIterator  valuesIterator
>
>
>
>
>
>
> *** classpath when using scala.tools.nsc.Settings ***
>
> http://thread.gmane.org/gmane.comp.lang.scala/18245/focus=18247
>  settings.classpath.value = System.getProperty("java.class.path")
>
>
>
> *** Avoid error: _ must follow method; cannot follow (Any) => Boolean ***
>
> Replace
>  list.filter(that.f _)
> with
>  list.filter(that f _)
> or
>  list.filter(that.f(_))
>
>
>
>
> *** Migrate from deprecated Enumeration methods  iterator  map ***
> Use Enumeration methods  values.iterator  values.map
>
>
>
> *** Migrate from deprecated  Iterator.fromValues(a, b, c, d) ***
> Use  Iterator(a, b, c, d)
>
>
>
> *** Avoid deprecated type Collection ***
> Use Iterable instead
>
>
> *** Change initialisation order ***
>
> Suppose we have
>  trait T {
>    val v
>    val w = v + v
>  }
>
> Replace
>  class C extends T {
>    val v = "v"
>  }
> with
>  class C extends {
>    val v = "v"
>  } with T
>
>
> *** Avoid unneeded 'val' in   for (val x <- ...) ***
>
>
>
> *** Avoid trailing commas ***
>
>
>






--
Daniel C. Sobral

I travel to the future all the time.
Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 3 days ago.
Re: Re: 2.7 vs 2.8 gotcha
On Tue, Mar 30, 2010 at 4:36 PM, Eric Willigers <ewilligers [at] gmail [dot] com> wrote:
> *** When explicitly specifying type parameters in container method calls, add new type parameters ***

You might find it easier/more succinct to specify the expected type.
> Change
>  list.map[Int](f)
> to
>  list.map[Int, List[Int]](f)

list.map(f) : List[Int]
> Change
>  map.transform[Value](g)
> to
>  map.transform[Value, Map[Key, Value]](g)

map.transform(g) : Map[Key, Value]
--j 

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland