Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 66 jvm languages Scripting experimenting and learning Programs are effectively scripts That is to say Gosu is both a comprehensive generalpurpose static language and a concise scripting language As Ill demonstrate shortly Gosus powerful type inference capabilities its syntax and the enhancements to Javas runtime library implement this dual mission One aspect that really qualifies Gosu as a scripting language is that it executes directly from source compilation to class files is optional When running from source Gosu compiles and loads classes on demand There is no performance penalty aside from the one time price of compilation to conventional bytecode In addition to scripting programs also promote learning and experimentation To leverage this ability our fullfeatured IntelliJ IDE plugin also provides a Scratchpad editor for quickly cranking out and executing experimental code You can even execute Scratchpad scripts against a running project in the debugger without interrupting execution at a breakpoint Class format Gosu is foremost an imperative object oriented language with classes interfaces structures annotations enums programs templates functions and enhancements all as first class types In addition Gosus type system is uniquely designed for customization you can plug in your own first class types Ill cover more of the type system as I go but first lets have a look at the basic format of a Gosu class package example uses java util List class SampleClass extends SampleBaseClass implements SampleInterface var _ sampleField List String construct param List String function sampleFunction param String property get SamplePropertry int class SampleInnerClass As you can see the main diference between Gosu and Java syntax is the Pascal style declarations where the name precedes the type for example var name Type Choosing this style mostly came from the desire for more consistent syntax where a variables type can be inferred Were also happy with the Pascal style for achieving consistency with generic declarations and in our view for providing better overall readability After a quick scan of the code youll notice some similarities with Java The package statement is the same and the uses statement is the equivalent of Javas import Inheritance with extends and implements is the same The var keyword declares fields theyre private by default Classes constructors functions and properties are public by default Semicolons are extinct that is theyre optional but discouraged Whitespace is insignificant as well newlines have no meaning except to us humans Some Features Gosus feature set is much too broad to cover in a single article Instead lets look at some features that will pique your interest Properties Think of properties as a formalization of Javas getter and setter methods Gosu also provides shortcuts with properties to eliminate boilerplate code For instance heres how you can declare a mutable property for a field var _ names List String as Names A primary difference between a get set pair of methods and a property is that you reference a property consistently as a single identifier not via separate method calls property get Names List String return names copy returns a copy
You must have JavaScript enabled to view digital editions.