Channels ▼
RSS

Design

Language of the Month: Gosu


Open Type System

Even with all its features, Gosu would not exist today if it were not for its innovative type system. Earlier, I mentioned that Gosu is the language that unifies the configuration of our very large-scale applications. By this I mean that Gosu brings together a host of otherwise disparate domains under one language. For example, our Gosu classes, web UI components, XSD models, OR entities, Java classes, and various other stores of information are all represented as first-class types in Gosu. Does this mean we do a bunch of code generation? No. How then do these types find their way into our type system?

Metatypes are abstractions in Gosu's type system. Unlike other languages, Gosu is not limited to a single, rigid, metatype definition. For instance, Java's metatype is the Class class. If you need to plug into Java's type system, you've got one option: generate code that can be compiled to a Java class. Gosu's metatype and type loader are pure interfaces. So, instead of a closed system of concrete classes, Gosu's type system is open, with public interfaces anyone can implement. Our base language includes type loaders and metatype definitions for all forms of Gosu classes (classes, interfaces, enums, programs, and templates). But internally, these types are no more significant to Gosu's compiler than the ones we built to access entities, XSDs, or Java classes.

So what does it mean, for example, when I say XSDs are first-class types? Leveraging the open type system, we've implemented a type loader and metatype to represent XSDs as types in Gosu. For example, say you have an XSD file, location.xsd, that defines element types relating to a location. You put this file in your class path somewhere. Now, you can reference its element types in Gosu as if they were real Gosu types, because they are real Gosu types! For instance, the expression xsd.location.Address is a legal type reference corresponding to the Address element defined in the XSD. The attributes of elements are exposed as properties on the corresponding type. No code generation is done behind the scenes — it's all statically typed.

There's a lot more to discuss regarding the open type system and its capabilities, but I hope I've provided enough to pique your interest. Some folks are already at work. For instance, Ronin, an MVC web framework for Gosu, together with Tosa, a zero-configuration OR layer, leverage Gosu and metatypes to provide an impressive framework. If you're interested in building something nontrivial with Gosu, I highly recommend giving this framework a go.

Tooling

It's difficult to talk about the benefits of a new language without having a tooling conversation. One reason Gosu is statically typed is because tooling is so vitally important to us, both as a company and as programmers with a keen interest in productivity. It is not some dogmatic attempt at stoking the dynamic-versus-static fire. It should come as no surprise, then, that we've been busy building IDE plugins for Gosu.

IntelliJ IDEA and Eclipse are the most popular Java IDEs on the market, so we set out to build full-featured plugins in both. Our Eclipse plugin has been generally available since the release of Gosu in November of last year. If Eclipse is your IDE, give the Gosu plugin a spin.

At Guidewire, we use IntelliJ IDEA as our primary IDE (Gosu was built using IntelliJ). I've personally used both Eclipse and IntelliJ extensively and have never been disappointed with IntelliJ — it is rock solid. We are currently working on revising our IntelliJ plugin and it should be generally available soon. Install the "Gosu" plugin directly from IntelliJ's Project Settings dialog.

I should mention that the Gosu core language bundles a simple code editor with some tooling built in. For instance, it supports syntax highlighting, parser feedback, code completion, and navigation. You can also directly execute programs you write from inside the editor. It's ideal for experimenting with Gosu or writing very small projects.

Conclusion

Now that Gosu has been properly introduced, you might feel compelled to learn more on your own. You can check out all the details at gosu-lang.org. Experiment with it, kick the tires, involve it in your next project — and let us know what you think. We're working hard to make Gosu the catalyst for your next innovation.


— Scott McKinney is the creator and architect of Gosu and works on Gosu and Gosu-based tools at Guidewire.

Video presentation on Gosu (at the Java Language Summit 2011)


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video