McKinney Gosu2

download McKinney Gosu2

of 30

Transcript of McKinney Gosu2

  • 8/12/2019 McKinney Gosu2

    1/30

    Introduction to Gosu

    A New Language for the JVMfrom ---------------

    Scott McKinney

    Guidewire [email protected]

    www.gosu-lang.com

  • 8/12/2019 McKinney Gosu2

    2/30

    Todays Discussion

    Background Highlights Open Type System Language Features Tools Q&A

  • 8/12/2019 McKinney Gosu2

    3/30

    Background

    Guidewire Provide large scale, highly configurable applications Gosu enables unified configuration of customer facing resources:

    Rules, Workflows, Web pages, Messaging, Web-services, Tests, etc. Language History(2002 present)

    No statically typed, embeddable scripting language available Started small as a rule expression language Evolved slowly: Scripting!OOP!Open Type Sys!Bytecode

    Roots Influenced by Java, C#, EcmaScript, Ruby, Pascal Static type system an absolute requirement, esp. for tooling Ideals: Pragmatic, Versatile, Professional

  • 8/12/2019 McKinney Gosu2

    4/30

    Highlights

  • 8/12/2019 McKinney Gosu2

    5/30

  • 8/12/2019 McKinney Gosu2

    6/30

    Type Information

    Types

    Type Loaders

    Type System Type System

    TypeLoader 1 TypeLoader 2 . . . TypeLoader N

    Type 2Type 1 Type N. . .

    TypeInfo

    Type System Structure

    Open

    API

    Feature Information PropertyInfo MethodInfoConstructorInfo AnnotationInfo

  • 8/12/2019 McKinney Gosu2

    7/30

    Open API

    ITypeLoaderIType getType( String name )

    . . .

    IType

    ITypeInfo getTypeInfo()

    . . .

    ITypeInfo

    List getProperties()

    List getMethods()

    List getConstructors()

    . . .

    IMethodInfo

    IMethodCallHandler getCallHandler()

    . . .

    IMethodCallHandler

    Object handleCall( Object ctx, Object args )

    . . .

  • 8/12/2019 McKinney Gosu2

    8/30

    Included Types

    Gosu provides several kinds of types in the

    current open source release. These include:

    Classes, Interfaces, Enums Enhancements Programs Templates Blocks/Closures XSD / XML Web Services / WSDL Dynamic Type*

  • 8/12/2019 McKinney Gosu2

    9/30

    Language Features

  • 8/12/2019 McKinney Gosu2

    10/30

    Obligatory Hello World

    Brace for it

  • 8/12/2019 McKinney Gosu2

    11/30

    Hello World

    !"#$%& ()*++, -,"+./(0 Gosu runsPrograms

    No boilerplate class No main() method More on programs later> gosu Hello.gsp)*++, -,"+./

    1

    More on Command Line Gosu

    later

    Hello.gsp

  • 8/12/2019 McKinney Gosu2

    12/30

    Back to Langauge Features

  • 8/12/2019 McKinney Gosu2

    13/30

    Object Oriented

    Superset of Javas OO capabilities Fullycompatiblew/ Java

    Single class, multiple interface inheritiance

    Composition/Delegation support Properties Annotations Enhancements(add behavior to existing types) Anonymous types with variable capture

  • 8/12/2019 McKinney Gosu2

    14/30

    fields constructors methods properties inner types

    Class Structure

    !23425*.*6,

    78*892:2;7%#+;

    :2"?$26* @ A%"#$53,$8%"73%&0 ;;;

    B7$3%#,$B,,&0 ;;;

    !",!*"%C5*%D26*&0

    3+288E$$*" ;;;F

    !23425*keyword same as Java 78*8keyword = Java import 3+288public by default

  • 8/12/2019 McKinney Gosu2

    15/30

    Programs

    Gosu executesPrograms/Scripts No more boilerplateclass with static main() Can be a simple expressionor Can define any number of statements Can define functions and properties Can define classes, inner classes, and closures Type-safe access to command linearguments

  • 8/12/2019 McKinney Gosu2

    16/30

    Programs

    78*892:2G;8H#$5;I="26*

    78*892:2;2H%;J*3%2$5+*

    varframe = newMyFrame()

    showMyFrame()

    functionshowMyFrame() {

    frame.Visible = true

    }

    classMyFrame extendsJFrame{

    construct() {super( "Hello")

    DefaultCloseOperation = DISPOSE_ON_CLOSE

    Bounds = newRectangle( 100, 100, 100, 100 )

    }

    }

    Mix statementswith

    Functionsand Classes

  • 8/12/2019 McKinney Gosu2

    17/30

    Templates

    Are types e.g., 3,6;B,,;A,6*K*6!+2%* Support JSP/ASP-style syntax: LMN LMON *%3 Support P>syntax too Declare parameters: LMQ !2"268& G@ A%"#$5 0 M1 Can be used anywhere Are supported in String Literals

  • 8/12/2019 McKinney Gosu2

    18/30

    Templates

    LM 78*892:2;7%#+;R2%*M1

    LMQ !2"268&G @ A%"#$50 M1

    K*6!+2%* %*G%

    LM #B& G;)28S,$%*$%0 > M1E$:#8#T+* %*6!+2%* %*G%

    LM F M1

    LMUU 3,66*$% UUM1

    KV* !2"26 #8@ P>GF

    MyTemplate.gstWW J*$.*" .#"*3%+C %, A%"#$5

    :2"8%" O

    XCK*6!+2%*;"*$.*"K,A%"#$5& (V*++,(0

    WW J*$.*" %, H"#%*"

    XCK*6!+2%*;"*$.*"& ?H"#%*"N (V*++,(0

    WW Y6T*..*. #$ 2 A%"#$5 +#%*"2+

    :2"8%" O

    (KV* .2%* #8 P>$*HR2%*&0F(

    Usage:

  • 8/12/2019 McKinney Gosu2

    19/30

    Generics

    Reified!:2"B,, O $*H=,,LA%"#$51

    !"#$%& B,, !"#$%&=,,LA%"#$510 WW %"7*/

    Array-style Variance (no wildcards, easy to understand!):2"+ @

  • 8/12/2019 McKinney Gosu2

    20/30

    Enhancements

    !23425* .*6,

    *$V2$3*6*$%XC ;;; F

    F

    *;5;N

    :2"+#8% O >(\2832+(N (I2:2(N (],87(F

    +#8%;!"#$& ^ * U1 !"#$%& * 0 0

    Add methodsand properties to existing types (including Java) Look and feel like a class, implicit this reference Fully support generics Dont modify existing class;just type information Statically dispatched Cant add state no fieldsallowed

  • 8/12/2019 McKinney Gosu2

    21/30

    Closures/Blocks

    :2"+#8% O >(\2832+(N (I2:2(N (],87(F

    WW S,++*3%#,$8 H#%V T+,348 &2$. *$V2$3*6*$%80;;;

    :2"+#8%_ O +#8%;62!& ^ * U1 *;+*$5%V&0 0

    Anonymous functions declared inline Can be either expressions or statement listsArgument and return types inferredbased on contextTrue closures with captured variables Invoked like normal functions Covarianceon return types, contravarianceon argument types

    Lets turn a list of Strings into a list of their lengths . . .

    WW KV* .*3+2"2%#,$ 8#%* +,,48 +#4*@B7$3%#,$62!L`1& 62!!*"&*+% @ K0@` 0 @ ; ; ; F

  • 8/12/2019 McKinney Gosu2

    22/30

    Type Inference

    :2"+#8%_ @

  • 8/12/2019 McKinney Gosu2

    23/30

    Composition/Delegation

    Composition in Gosu

    WW A26!+* X#G#$ #$%*"B23*

    !7T+#3#$%*"B23*ES+#!T,2".\2"%

    >T,,+*2$ 32$S,!C&0a

    :,#. 3,!C&0a

    T,,+*2$ 32$\28%*&0a

    :,#. !28%*&0a; ; ;

    F

    3+288XC-#$.,H *G%*$.8-#$.,H #6!+*6*$%8ES+#!T,2".\2"%

    >

    .*+*52%*?3+#!T,2".\2"% "*!"*8*$%8ES+#!T,2".\2"%;;;

    F

    .*+*52%*keyword "*!"*8*$%8clause specifies interfaces, owning class must declare Compiler automatically dispatches to delegates implementation Otherwise behaves just like a field A single delegate can represent multiple interfaces

  • 8/12/2019 McKinney Gosu2

    24/30

    More Language Features

    Context sensitive eval()support (in a static language? really!) Using-statement supports RAII(Resource Acquisition Is Initialization) Map and Collection initializationsyntax Object initializersyntax Extensive interval supporte.g., 1..10 Enhanced switch-statement (any type, any expression) Smarter for-statement(handle more types, provides index) Associative arraysyntax for dynamic access to properties Null short-circuitin property access expressions No checked exceptions! Etc.

  • 8/12/2019 McKinney Gosu2

    25/30

    Tools!!!

    In our view:

    A professional, general purpose language is impractical without full-featuredIDE support

    The larger the project, the greater the pressure on tools Huge productivity gains via build-time type-safety, editor feedback, codecompletion, navigation, usage searching, and refactoringare not achievable

    without the ability to perform solid static analysis

    Good news:

    Gosus type system enables a rich set of static analysis tools Weve been busy

  • 8/12/2019 McKinney Gosu2

    26/30

    Eclipse Plug-in

    Full-Featured Syntax coloring Instant feedback as you type Code completion Code navigation Member Usage Search Type Usage Search Refactoring Hover text Structure views Occurrence highlighting Full featured debugger

  • 8/12/2019 McKinney Gosu2

    27/30

    Eclipse Plug-in

  • 8/12/2019 McKinney Gosu2

    28/30

    REPL Command Line

  • 8/12/2019 McKinney Gosu2

    29/30

  • 8/12/2019 McKinney Gosu2

    30/30

    Q&A