Build

GosuThe Language of P&C

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

Overview

Gosu

P&C Innovation: Built with Gosu

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

Related Info

Use Case
Integration developers are the life blood of innovation. Start your journey here to learn how to connect anything to Guidewire.
Blog
Welcome to the new Guidewire developer blog. Start here to learn about new skills, features, and tools to help you master your projects.
Use Case
Configuration plays a critical role in enabling your business to move fast. Build product lines, workflows, and business logic that gives your company the edge.

Explore

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.

Gosu has the familiar if, else if, and else statements:


if (myRecord.Open and myRecord.MyChildList.length > 10) {
  // Some logic
} else if (not myRecord.Open) {
  // Some more logic
} else {
  // Yet more logic
}

Gosu permits the more readable English words for the Boolean operators: and, or, and not. Alternatively, you can use the symbolic versions from Java (&&, ||, and !).

The for loop in Gosu is similar to the Java 1.5 syntax:


for (ad in addressList) {
  print(ad.ID)
}

//If you need an index within the loop, use the following syntax to access the zero-based index:

for (ad in addressList index i) {
  print(ad.ID + " has index " + i)
}
Gosu has native support for intervals.


// a closed interval example
for (i in 1..10) {
  print(i)
}

// an open interval example
for (i in new ColorInterval("red", "blue")) {
  print(i)
}

The Gosu switch statement can test any type of object, with a special default case at the end:


var x = "b"

switch (x) {
  case "a":
    print("a")
    break
  case "b":
    print("b")
    break
  default:
    print("c")
}

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.

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:


var strings = { "aa", "ddddd", "c" }
strings.sortBy(\ str -> str.length).each(\ str -> { print(str) })

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:


_callbackHandler.execute(\ -> { /* Your Gosu statements here */ })

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:


strings.sortBy(\ str -> str.length).each(\ str -> print(str))

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 gw.example.MyClass      // Exact type
uses gw.example.queues.jms.* // Wildcard symbol * specifies a hierarchy


class ABC {
  construct(id : String) {
  }
}


var a = new ABC("My initialization string")

//Gosu improves on this basic pattern and introduces a standard compact syntax for property initialization during object creation. 
//For example, suppose you have the following Gosu code:
var myFileContainer = new my.company.FileContainer()
myFileContainer.DestFile = jarFile
myFileContainer.BaseDir = dir
myFileContainer.Update = true
myFileContainer.WhenManifestOnly = ScriptEnvironment.WHEN_EMPTY_SKIP
//After the first line, four more lines contain the object variable name, which is repeated information.
//You can use Gosu object initializers to simplify this code to only a couple of lines:
var myFileContainer = new my.company.FileContainer() { :DestFile = jarFile, :BaseDir = dir, 
  :Update = true, :WhenManifestOnly = ScriptEnvironment.WHEN_EMPTY_SKIP }
//You can also choose to list each initialization on its own line, which uses more lines but is more readable:
var myFileContainer = new my.company.FileContainer() { 
  :DestFile = jarFile, 
  :BaseDir = dir, 
  :Update = true,
  :WhenManifestOnly = ScriptEnvironment.WHEN_EMPTY_SKIP 
}

Related Info

API
Easily connect applications with Guidewire using RESTful APIs. Or build completely headless experiences for Guidewire.
Video
Guidewire's Laura Drabik and Ray Kreisel explain how leveraging Guidewire Cloud will reduce complexity and help you go faster.
Cross-Platform Tool
Create beautiful and engaging digital apps that run on Guidewire - the world's most trusted P&C platform with Guidewire Jutro.

Get Started

Learning Gosu

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 Guides

Guidewire supplies a full Gosu reference guide for BillingCenter, ClaimCenter, and PolicyCenter respectively. These reference guides cover Gosu end-to-end from basics like operators and expressions, to advanced topics like how to work with XML and JSON in Gosu.

Related Info

Use Case
Want to build beautiful and engaging digital experiences for Guidewire? This page has everything you need to get started.
Case Study
Aviva Italy Accelerates Digital Disruption. Four-month InsurancePlatform implementation enables insurer to quickly build a new insurance model.
Standard
Guidewire Cloud Standards are proven principles and practices that enable a successful Guidewire Cloud implementation journey.

Don’t see what you are looking for?