Gosu Programming Language

Learn Gosu, the ubiquitous open-source programming language used in hundreds of P&C enterprises around the globe.

What is Gosu?

Gosu logo

Gosu is the open-source programming language used in 700+ P&C core implementations, hundreds of third-party P&C apps, and in the work of tens of thousands of P&C consultants and developers. A powerful and easy-to-use object-oriented language, Gosu combines the best features of Java, including:

  • Compatibility with existing Java libraries
  • Significant improvements like blocks and powerful type inference
  • These features change the way you write code.

Now you can write readable, powerful, and type-safe type code built on top of the Java platform. Many of the configuration and integration points in the base configuration of Guidewire use Gosu classes or expressions. To integrate with external systems, you can use native web service and XML support built directly into the language. You can work with XSD types or external APIs like native objects. For these reasons and more startups and some of the largest and most complex companies all around the world use Gosu every day in their production servers for their most business-critical systems.

Gosu is a general-purpose programming language built on top of the Java Virtual Machine (JVM). Because Gosu uses the JVM, Gosu has the following characteristics:

  • Java compatible, so you can use Java types, extend Java types, and implement Java interfaces
  • Object-orientation
  • Easy to learn, especially for programmers familiar with Java
  • Imperative paradigm

As well as the many features that Gosu shares with Java, Gosu includes the following additional features:

  • Static typing, which helps you find errors at compile time
  • Type inference, which simplifies your code and preserves static typing
  • Blocks, which are in-line functions that you can pass around as objects. Some languages call these closures or lambda expressions
  • Enhancements, which add functions and properties to other types, even Java types. Gosu includes built-in enhancements to common Java classes, some of which add features that are unavailable in Java (such as blocks)
  • Generics, which abstracts the behavior of a type to work with multiple types of objects. The Gosu generics implementation is 100% compatible with Java, and adds further powerful improvements
  • JSON support and dynamic typing
  • Structural types, which relate classes to one another based on shared characteristics rather than interfaces or inheritance
  • Dimension types, which include a unit as well as a valu.
  • Composition, which delegates the implementation of an interface to another class
  • Transactions for database integrity
  • XML/XSD support
  • Web service (SOAP) support
  • String templates
  • Concurrency
  • Checksums

Gosu Key Features

Control Flow

Gosu has all the common control flow structures, including improvements on the Java versions. Below are some common uses and examples.

if statements

for loop

Intervals

switch statement

Blocks

Gosu supports in-line functions that you can pass around as objects, which are called blocks. Other languages call blocks closures or lambda expressions. Blocks are useful as method parameters, in which the method’s implementation generalizes a task or algorithm but callers provide code to implement the details of the task. For example, Gosu adds many useful methods to Java collections classes that take a block as a parameter. That block could return an expression, such as a condition against which to test each item, or could represent an action to perform on each item. Below are some common uses and examples.

Block example

The following Gosu code makes a list of strings, sorts the list by string length, and then iterates across the result list to print each item in order. 

Block shortcut

If an anonymous inner class implements an interface that has exactly one method, you can use a Gosu block to implement the interface. The Gosu block is an alternative to using an explicit anonymous class. You can use a Gosu block for interfaces that are defined in either Gosu or Java. For example:

Enhancements

Gosu provides a feature called enhancements, which supports adding functions and properties to other types. Enhancements are especially powerful for enhancing native Java types, and types defined in other people’s code. For example, Gosu includes built-in enhancements on collection classes and interfaces, such as java.util.List, that improve power and readability of collections code. For example, the following code takes a list of String objects, and uses a block to sort the list by the length of each String. The code then uses another block in the iteration across the result list to print each item:

The sortBy and each methods in this example are Gosu enhancement methods on the List interface. Both methods return the result list, which makes them useful for chaining methods in series.

Gosu Classes and Properties

Gosu supports object-oriented programming using classes, interfaces and polymorphism. Also, Gosu is fully compatible with Java types, so Gosu types can extend Java types, or implement Java interfaces. At the top of a class file, use the package keyword to declare the package of this class. A package defines a namespace. To import specific classes or package hierarchies for later use in the file, add lines with the uses keyword. This is equivalent to the Java import statement. Gosu supports exact type names, or hierarchies with the * wildcard symbol:

Uses Keyword

Classes and Constructors 

Calling Classes

Related Information

Gosu Language Tutorials

In addition to the resources from the official Gosu language project, Guidewire offers a variety of resources to help developers explore and learn GOSU.

Gosu Reference Guide

Guidewire supplies a full Gosu reference guide within our Documentation site. The Gosu Reference Guide covers Gosu Programming Language end-to-end from basics like operators and expressions, to advanced topics like how to work with XML and JSON in Gosu. You must be logged in to our Documentation site to access the guide below.

Gosu Education Courses

Our Guidewire Education team has also created both instructor-led and self-study courses to help you understand the fundamentals of using Gosu in Guidewire applications. There are two courses that represent a good starting point for developers who would like to learn Gosu: InsuranceSuite 10.0 and 9.0 Developer Fundamentals and Introduction to Object-Oriented Programming Using Gosu

Related Information