Hey all,I've talked to some of you already about this, but I've been rethinking the Scala port of GeoScript. The current implementation is kind of modeled on the Python implementation, and kind of not. It's also something that I started while pretty new to the Scala language and perhaps not the best representation of idiomatic Scala. In the meantime, some new language features have been added and I've learned a lot, so I've been thinking about a GeoScript Scala 2.0* (*: Well actually there is no GeoScript Scala 1.0, so I'll probably just bump to 0.8 ;)
The big thing on my mind is that while Scala can be terse and "script-y", it is not a dynamically typed language and perhaps simply trying to match the Python API 1:1 is not the best way to design a GeoTools wrapper. In particular, I think that having static types means that the Scala version of GeoScript can have even tighter integration than other GeoScript languages with existing GeoTools code, but its compiled nature means that it's not the most natural fit for (for example) a JSR223 based GeoServer extension module. Dynamic extensions to GeoTools software are of course possible with Scala, but I think in the immediate term it's going to be a better fit to focus on the ways in which Scala is a "better Java" including a compile/static analysis phase before deployment.So over the next while (and this may take a while as GeoScript is pretty much a back-burner project for me) I'll be reviewing and rewriting the GeoScript Scala module.
In the interest of having a consistent design philosophy, I've tried to enumerate here the principles I'm trying to stick to, this time around :)
- Use GeoTools types. It should be pretty rare to need to define custom types, and GeoScript users should very rarely find themselves declaring variables or methods whose types aren't in the GeoTools API. Scala provides the following features that help us "enrich" the interface of existing types, adding methods and abstractions without needing to modify third-party code:
- type aliases http://docs.scala-lang.org/tutorials/tour/abstract-types.html
- implicit conversions to effectively add methods to existing types http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-6
- implicit conversions to emulate Haskell typeclasses http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html . There was also a good talk on this topic at this year's NEScala conference: http://nescala.org/#t-10646327 (video and slides)
- Provide immutable alternatives to the various mutable APIs in GeoTools. The Scala collections library does an excellent job of demonstrating how mutable and immutable alternatives can be provided with common APIs. With GeoTools the implementation is often fundamentally mutable so things will probably not be flawless here, but we can provide immutable alternatives to most operations based on copying. The Style Combinators API (which has already been adopted by other GeoScript dialects due to its terseness) is an excellent example of how this sort of thing can look.
- Embrace Scala supporting libraries. For example, I'm planning on implementing Arbitrary instances for Filter, Expression, Schema, and Feature to support testing with ScalaCheck. https://github.com/rickynils/scalacheck/wiki/User-Guide . These could also be used to test Java code (potentially even core GeoTools code.)
I've taken some steps in this direction on the "tutorial" branch already (https://github.com/dwins/geoscript.scala/tree/tutorial going through the Python/JavaScript tutorials for inspiration on the functionality that should be covered.) Feel free to let me know if you have any questions or ideas.
--David Winslow--
You received this message because you are subscribed to the GeoScript mailing list.
To post to this group, send email to geos...@googlegroups.com
To unsubscribe from this group, send email to geoscript+...@googlegroups.com
Visit this group at http://groups.google.com/group/geoscript or see http://geoscript.org
--David Winslow--
package org.geoscript package object layer { type Layer = org.geotools.feature.simple.SimpleFeatureType def Layer(schema: Schema) = createMemoryDataStoreAndFeatureTypeSomehow() }
import org.geoscript.layer._ val l: Layer = Layer(Schema(...))