Gosu provides some additional library support beyond the standard Java libraries
First, a bit of philosophy:
Java has most of the functionality a developer would want. Sometimes the APIs for this functionality are insane. As an example, writing text to a file is something I have to look up almost every time, and I've been coding in Java for a decade. To address these situations Gosu will typically offer a simpler alternative, usually built in to the obvious Java class via enhancements. Other times the API Java has is fine and Gosu won't offer anything beyond that.
Gosu is not an attempt to reinvent the world. The core Java libraries are very solid and, with a bit of touching up and leveraging some of Gosu's language features, these libraries can be both simple and more powerful.
Because of this, there are not many user facing classes in the Gosu API and they are somewhat sporadic, addressing
corners of the standard Java API that we were unhappy with. There is not a new collections framework, for example.
ArrayList
and HashMap
have served us well, and there is no reason to retire them. Instead,
Gosu makes Java developers more productive with these classes by adding functionality to them.
All that being said, here are some highlights from the gw.*
packages:
gw.lang.cli.CommandLineAccess
This class allows you to access the arguments passed in to your gosu program. It can also be used to reflectively
populate a Gosu class with the arguments that were passed in. You can look at the other classes in
gw.lang.cli
to see how to set up class to accept command line arguments.
gw.lang.reflect.TypeSystem
This is class offers some static methods as entry points into the Gosu Type System, for example looking up types by name.
gw.util.AutoMap
This class wraps a map and will automatically create a value in the map for a key miss. You can convert a regular map
to an AutoMap
easily:
var map = { "foo" -> "bar", "doh" -> "rey" } // creates a regular HashMap<String, String> var autoMap = map.toAutomap( \ s -> 'There is no value for "${s}"' ) // convert it to an AutoMap print( autoMap["blah"] ) // prints "There is no value for "blah"
gw.util.concurrent.LazyVar
This class gives you a thread-safe way to implement a lazy variable by passing in a simple initialization block:
var lazyValue = LazyVar.create( \-> expensiveFunction() ) ... var actualValue = lazyValue.get()This can be used to make startup of your gosu system faster. Our experience suggests it should be used judiciously.
gw.util.Gosu*Util
These classes provide functionality around some common areas (e.g. Arrays, Exceptions, Escaping Strings.) Typically, in Gosu, the functionality on these classes is exposed via Enhancements, but they can still be useful in any Java code you are forced to write.
gw.util.Shell
This class tries to make working with the host OS relatively painless, allowing you to execute command line scripts, etc. without a lot of work