SlideShare une entreprise Scribd logo
1  sur  60
| Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8
                                                           reserved. |


Wednesday, October 5, 11
The Not Java That's Not Scala:
       Alternatives for EE Development
       Justin Lee, Oracle
            | Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8
                                                           reserved. |


Wednesday, October 5, 11
Introduction
           Who am I?
           Using Java since 1996
           GlassFish and Grizzly team member
            websockets
           Basement Coder
           Used various languages over the years
             python, c, c++, scala, ...



Wednesday, October 5, 11
Introduction
       Who am I not?
       A Scala hater
       A language geek
       Compiler jockey




Wednesday, October 5, 11
Why Not Java?
          Java is 15+ years old now
             Long time since the last release
                Pace of change is geological
          Verbosity
          The shine has worn off
          It's not cool!
          It's “enterprisey”
          it doesn't have my favorite feature!

Wednesday, October 5, 11
Why Not Scala?
          Lots of advanced features that are not readily accessible
           to “Average Joes”
          “Academics are driving the bus” - James Gosling
          Complexity - real and perceived
          new fangled features
          esoteric features
          rampant feature abuse: trait **->**->** {implicit def **->**-
           >**[A, F[_, _], B](a: F[A, B]): *->*->*[A, F, B] = new *->*-
           >*[A, F, B] {val value = a}}

Wednesday, October 5, 11
So What's Missing?
              Closures
              Syntax Cleanups
              Succinctness
               Typing/Inference
              Generics
              Concurrency




Wednesday, October 5, 11
So What's Missing?
          Functional programming
          Mutability
          Null Handling
          Extendability
                Extension methods
                Mixins
          Modularity


Wednesday, October 5, 11
So … what would you suggest?
          Suggest is a strong word but...
          Fantom
          Gosu
          New to me, too, to one degree or another




Wednesday, October 5, 11
Fantom (Formerly known as Fan)
          http://fantom.org
          Familiar Syntax
          Functional
          Static and Dynamic Typing
          “Modern” concurrency facilities
          Portable
             compile to JavaScript and SWT both



Wednesday, October 5, 11
Fantom - Portability
          Fcode
          JVM (of course)
          .Net (partial)
          JavaScript




Wednesday, October 5, 11
Fantom
          Literals
                maps: [1:"one", 2:"two"] , empty [:]
                lists: [0, 1, 2], empty [,]
                URIs: `/dir/file.txt`
                Types: Int#
                Slots: Int#plus




Wednesday, October 5, 11
Fantom
      public class Person {
          private String name;

          private int age;
          public Person(String s, int x) { name = s; age = x; }
          public String getName() { return name; }
          public void setName(String x) { name = x; }

          public int getAge() { return age; }
          public void setAge(int x) { checkAge(age); age = x; }
          int yearsToRetirement(int retire) { return (retire == -1 ? 65 : retire) - age }
      }
Wednesday, October 5, 11
Fantom
      class Person {
          Str name
          new make(String s, Int x) { name = s; age = x; }
          Int age { set { checkAge(it); &age = it }
          Int yearsToRetirement(Int retire := 65) { return retire - age }
      }




Wednesday, October 5, 11
Fantom
      Inheritance and Mixins:
      class Foo {
                                               class Bob : Foo, Bar {
          virtual Void bar() { echo("foo") }
                                                   override baz := 10
      }
                                                   override Void bar() { echo("bob") }
      mixin Bar {
                                               }
          abstract Int baz

          Void yep(Int x) { baz = x }
      }




Wednesday, October 5, 11
Fantom
      Closures
      ["red", "yellow", "orange"].each |Str color| { echo(color) }
      10.times |Int i| { echo(i) }
      10.times |i| { echo(i) }
      10.times { echo(it) }
      files = files.sort |a, b| { a.modified <=> b.modified }
      Functions
      add := |Int a, Int b->Int| { return a + b }
      nine := add(4, 5)

Wednesday, October 5, 11
Fantom
      Dynamic typing
      obj->foo             // obj.trap("foo", [,])
      Nullable Types
      Str // never stores null
      Str? // might store null




Wednesday, October 5, 11
Fantom
      Immutability
      const class Point{
          new make(Int x, Int y) { this.x = x; this.y = y }
          const Int x
          const Int y
      }
      const static Point origin := Point(0, 0)
      stooges := [“Moe”,”Larry”,”Curly”].toImmutable

Wednesday, October 5, 11
Fantom
      Concurrency
      // spawn actor which aynchronously increments an Int msg
      actor := Actor(group) |Int msg->Int| { msg + 1 }


      // send some messages to the actor and block for result
      5.times echo(actor.send(it).get)




Wednesday, October 5, 11
Fantom
      Standard Libraries
      // get file over HTTP
      WebClient(`http://fantom.org`).getStr
      // get tomorrow's date
      Date.today + 1day // date literals
      // compute HTTP Basic auth string
      res.headers["Authorization"] = "Basic " + "$user:$pass".toBuf.toBase64




Wednesday, October 5, 11
Fantom
      Modularity and Meta-Programming
      // find pods available for installation in project "Cool Proj"
      repo := Repo.makeForUri(`http://my-fantom-repo/`)
      pods := repo.query(Str<|"* proj.name=="Cool Proj"|>)
      pods.each |p| { echo("$p.name $p.version $p.depends") }




Wednesday, October 5, 11
Fantom
      Modularity and Meta-Programming
      // find all types installed in system which subclass Widget
      Pod.list.each |pod| {
          pod.types.each |type| {
              if (type.fits(Widget#)) echo(type.qname)
          }
      }




Wednesday, October 5, 11
Fantom
      Modularity and Meta-Programming
      // find pods available for installation in project "Cool Proj"
      repo := Repo.makeForUri(`http://my-fantom-repo/`)
      pods := repo.query(Str<|"* proj.name=="Cool Proj"|>)
      pods.each |p| { echo("$p.name $p.version $p.depends") }




Wednesday, October 5, 11
Fantom
      Modularity and Meta-Programming
      // find pods available for installation in project "Cool Proj"
      repo := Repo.makeForUri(`http://my-fantom-repo/`)
      pods := repo.query(Str<|"* proj.name=="Cool Proj"|>)
      pods.each |p| { echo("$p.name $p.version $p.depends") }




Wednesday, October 5, 11
Fantom
       DSLs
          embed other languages in your fantom code
          similar to CDATA sections in XML
          AnchorType <|...|>
          echo(Str <|now is the time for all good men
           to come to the aid of their country.|>)
          Regex <|^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$|>



Wednesday, October 5, 11
Fantom
      class RegexDslPlugin : DslPlugin {
        new make(Compiler c) : super(c) {}
        override Expr compile(DslExpr dsl) {
          regexType := ns.resolveType("sys::Regex")
          fromStr := regexType.method("fromStr")
          args := [Expr.makeForLiteral(dsl.loc, ns, dsl.src)]
          return CallExpr.makeWithMethod(dsl.loc, null, fromStr, args)
        }
      }
      // register in indexed props in build script
      index = ["compiler.dsl.sys::Regex": "compiler::RegexDslPlugin"]


Wednesday, October 5, 11
Fantom - Portability
      @Js
      class Demo {
          Void main() {
              // dumps to your browser's JS console
              10.times |x| { echo("x: $x")
          }
      }


Wednesday, October 5, 11
Fantom - Tales
  @Js class ClickClickJs {                 class Routes{
    Void main() {                            Route[] routes := Route[
                                               Route{map="/clickclick";
      Jq.ready {                           to="ClickClick";}
        Jq("#click").click|cur, event| {     ]
          Win.cur.alert("Click Click")     }
          event.preventDefault
        }
      }
    }
  }

Wednesday, October 5, 11
Fantom - Draft
      const class MyMod : DraftMod {
        new make() {
            pubDir = `...`.toFile
            router = Router {
                routes = [ Route("/", "GET", #index),
                 Route("/echo/{name}/{age}", "GET", #echo)   ]
            }
        }
Wednesday, October 5, 11
Fantom - Draft
      Void index() {
           res.headers["Content-Type"] = "text/plain"

           res.out.printLine("Hi there!")
       }
       Void echo(Str:Str args) {
           name := args["name"]

           age := args["age"].toInt
           res.headers["Content-Type"] = "text/plain"
           res.out.printLine("Hi $name, you are $age years old!")
       }
Wednesday, October 5, 11
Fantom - Resources
          http://fantom.org #fantom on irc.freenode.net
          http://www.talesframework.org/
          Draft Mini Web Framework https://bitbucket.org/
           afrankvt/draft/wiki/Home
          http://spectreframework.org/
          Twitter
                @afrankvt
                @briansfrank



Wednesday, October 5, 11
Gosu
          http://gosu-lang.org
          Again, familiar syntax
          Statically typed
          Enhancements
          Closures
          Simplified generics
          Open Type System



Wednesday, October 5, 11
Gosu
          == Object equality
          === Instance equality
          >, <, etc. works with java.lang.Comparable
          Standard logical operators
          Null Safety
            print( x?.length ) // prints "null"
          var zeroToTenInclusive = 0..10



Wednesday, October 5, 11
Gosu - Properties!
      public class MyJavaPersonClass {
       String _name;
                                            var p = new MyJavaPersonClass()
          public String getName() {         p.Name = "Joe"
            return _name;                   print( "The name of this person is ${p.Name}")
          }

          public void setName(String s) {
            _name = s;
          }
      }




Wednesday, October 5, 11
Gosu
    uses java.util.List
    class SampleClass {
     var _names : List<String> // a private class variable, which is a list of Strings

        construct( names : List<String> ) { _names = names }

        function printNames( prefix : String ) {
          for( n in _names ) { print( prefix + n ) }
        }

        property get Names() : List<String> { return _names }
    }




Wednesday, October 5, 11
Gosu
    var c = new SampleClass({"joe", "john", "jack"})
    c.printNames("* ")
    * joe
    * john
    * jack
    print( c.Names )
    [joe, john, jack]




Wednesday, October 5, 11
Gosu
    uses java.util.List
    class SampleClass {
     var _names : List<String>

        construct( names : List<String> ) { _names = names }

        function printNames( prefix : String ) {
          for( n in _names ) { print( prefix + n ) }
        }

        property get Names() : List<String> { return _names }
    }




Wednesday, October 5, 11
Gosu
    uses java.util.List
    class SampleClass {
     var _names : List<String> as Names

        construct( names : List<String> ) { _names = names }

        function printNames( prefix : String ) {
          for( n in _names ) { print( prefix + n ) }
        }
    }




Wednesday, October 5, 11
Gosu
    uses java.util.List
    class SampleClass {
     var _names : List<String> as readonly Names
        construct( names : List<String> ) { _names = names }
        function printNames( prefix : String) {
          for( n in _names ) { print( prefix + n ) }
        }
    }




Wednesday, October 5, 11
Gosu
    uses java.util.List
    class SampleClass {
     var _names : List<String> as readonly Names
        construct( names : List<String> ) { _names = names }
        function printNames( prefix : String = "> ") {
          for( n in _names ) { print( prefix + n ) }
        }
    }




Wednesday, October 5, 11
Gosu
    class MyRunnable implements Runnable {
     delegate _runnable represents Runnable

        construct() {
          _runnable = new Runnable() {
            override function run() { print("Hello, Delegation") }
          }
        }
        property get Impl() : Runnable { return _runnable }
        property set Impl( r : Runnable ) { _runnable = r }
    }




Wednesday, October 5, 11
Gosu
    class MyRunnable implements Runnable {
     delegate _runnable represents Runnable

        construct() {
          _runnable = new Runnable() {
            override function run() { print("Hello, Delegation") }
          }
        }
        property get Impl() : Runnable { return _runnable }
        property set Impl( r : Runnable ) { _runnable = r }
    }

    var x = new MyRunnable()
    x.Impl = new Runnable() {
      override function run() { print("Hello, Delegation 2") }
    }


Wednesday, October 5, 11
Gosu - Donkey Patching
    Extensions

    enhancement MyStringEnhancement : String {
      function printMe() {
        print( this )
      }
    }

    "Hello Enhancements".printMe()

    Enhancements are statically dispatched which means they cannot
      be used to implement interfaces or to achieve polymorphism


Wednesday, October 5, 11
Gosu
      Enhancements

         String: rightPad(), leftPad(), center(), toDate(), toBoolean()
         File: read(), write(), eachLine()

      Closures (Blocks)
             var listOfStrings = {"This", "is", "a", "list"}
             var longStrings = listOfStrings.where( s -> s.length>2)
             print( longStrings.join(", ") )

             var r : Runnable
             r = -> print("This block was converted to a Runnable")



Wednesday, October 5, 11
Gosu
    Now for the fun part.




Wednesday, October 5, 11
Gosu
    Now for the fun part.

    XML marshalling!




Wednesday, October 5, 11
Gosu
    Now for the fun part.

    XML marshalling!

    JAXB is “great” and all but it can be … painful.




Wednesday, October 5, 11
Gosu
    Now for the fun part.

    XML marshalling!

    JAXB is “great” and all but it can be … painful.

    Gosu has great alternative.




Wednesday, October 5, 11
Gosu
    Now for the fun part.

    XML marshalling!

    JAXB is “great” and all but it can be … painful.

    Gosu has great alternative.

    But first <shudder/> an XSD...




Wednesday, October 5, 11
Gosu
    <?xml version="1.0"?>
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Person">
       <xs:complexType>
         <xs:sequence>
          <xs:element name="firstname" type="xs:string"/>
          <xs:element name="lastname" type="xs:string"/>
          <xs:element name="age" type="xs:int"/>
         </xs:sequence>
       </xs:complexType>
      </xs:element>
     </xs:schema>


Wednesday, October 5, 11
Gosu
    var bob = new myapp.example.Person()
    bob.Age = 32
    bob.Firstname = "Bob"
    bob.Lastname = "Loblaw"
    bob.print()




Wednesday, October 5, 11
Gosu
    var bob = new myapp.example.Person()
    bob.Age = 32
    bob.Firstname = "Bob"
    bob.Lastname = "Loblaw"
    bob.print()

    What about WSDL?




Wednesday, October 5, 11
Gosu
    var bob = new myapp.example.Person()
    bob.Age = 32
    bob.Firstname = "Bob"
    bob.Lastname = "Loblaw"
    bob.print()

    // weather.wsdl
    var x = new myapp.weather()
    var forecast = x.GetCityForecastByZIP("95816")
    print( forecast.ForecastResult.Forecast.map(  f -> f.Description ).join("n") )




Wednesday, October 5, 11
Gosu
    Feature Literals

       var sub = String#substring(int) // class reference
       print( sub.invoke( "Now is the time for all good men", 2 ) )

       // instance reference
           var sub = "Now is the time for all good men"#substring(int)
           print( sub.invoke( 2 ) )




Wednesday, October 5, 11
Gosu
    Feature Literals

       var sub = String#substring(int) // class reference
       print( sub.invoke( "Now is the time for all good men", 2 ) )

       // instance reference
           var sub = "Now is the time for all good men"#substring(2)
           print( sub.invoke() )




Wednesday, October 5, 11
Gosu
    Feature Literals

       var sub = String#substring(int) // class reference
       print( sub.invoke( "Now is the time for all good men", 2 ) )

       // instance reference
           var sub = "Now is the time for all good men"#substring(2)
           print( sub.invoke() )
       var component = new Component(foo#Bar#Bob)



Wednesday, October 5, 11
Gosu - Ronin
    <%@ extends ronin.RoninTemplate %>
    <%@ params(name : String) %>
    <html>
      <body>
         Hello ${name}!
      </body>
    </html>
Wednesday, October 5, 11
Gosu - Ronin
     package controller
      uses ronin.*
      class Main extends RoninController {
        function hello(name : String) {
          view.Hello.render(writer, name)
      }
    }
Wednesday, October 5, 11
Gosu
         http://www.gosu-lang.org
         Web framework http://ronin-web.org/
         ORM: http://ronin-web.org/Tosa.html
         Build tool: Aardvark http://vark.github.com/
         JVM Language Summit: http://medianetwork.oracle.com/
          media/show/17005
         Twitter: @carson_gross
         IRC: #gosulang @ irc.freenode.net




Wednesday, October 5, 11
Justin Lee, Oracle
       http://antwerkz.com
       @evanchooly
       http://github.com/evanchooly
       http://www.basementcoders.com
            | Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8
                                                           reserved. |


Wednesday, October 5, 11

Contenu connexe

Tendances

[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...EnlightenmentProject
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+Romain Dorgueil
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Ken Kousen
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Carlo Sciolla
 
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)Romain Dorgueil
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1Lin Yo-An
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)benwaine
 
Javascript development done right
Javascript development done rightJavascript development done right
Javascript development done rightPawel Szulc
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better JavaNils Breunese
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)benwaine
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlinvriddhigupta
 
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan s.r.o.
 
Stetl for INSPIRE Data Transformation
Stetl for INSPIRE Data TransformationStetl for INSPIRE Data Transformation
Stetl for INSPIRE Data TransformationJust van den Broecke
 

Tendances (19)

Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
 
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
Tales@tdc
Tales@tdcTales@tdc
Tales@tdc
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
 
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
Simple ETL in Python 3.5+ - PolyConf Paris 2017 - Lightning Talk (10 minutes)
 
Noboxing plugin
Noboxing pluginNoboxing plugin
Noboxing plugin
 
Happy Go Programming Part 1
Happy Go Programming Part 1Happy Go Programming Part 1
Happy Go Programming Part 1
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)
 
Javascript development done right
Javascript development done rightJavascript development done right
Javascript development done right
 
Pl/Python
Pl/PythonPl/Python
Pl/Python
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Kotlin: a better Java
Kotlin: a better JavaKotlin: a better Java
Kotlin: a better Java
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)
 
Introduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in KotlinIntroduction to kotlin and OOP in Kotlin
Introduction to kotlin and OOP in Kotlin
 
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
 
Stetl for INSPIRE Data Transformation
Stetl for INSPIRE Data TransformationStetl for INSPIRE Data Transformation
Stetl for INSPIRE Data Transformation
 

Similaire à The Not Java That's Not Scala

Scala Implicits - Not to be feared
Scala Implicits - Not to be fearedScala Implicits - Not to be feared
Scala Implicits - Not to be fearedDerek Wyatt
 
Best practices in Java and Swing
Best practices in Java and SwingBest practices in Java and Swing
Best practices in Java and SwingAshberk
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Matt Aimonetti
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4Jan Berdajs
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFDror Bereznitsky
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesDebasish Ghosh
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java DevelopersChristoph Pickl
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 

Similaire à The Not Java That's Not Scala (20)

Clojure night
Clojure nightClojure night
Clojure night
 
XQuery Design Patterns
XQuery Design PatternsXQuery Design Patterns
XQuery Design Patterns
 
Scala Implicits - Not to be feared
Scala Implicits - Not to be fearedScala Implicits - Not to be feared
Scala Implicits - Not to be feared
 
Best practices in Java and Swing
Best practices in Java and SwingBest practices in Java and Swing
Best practices in Java and Swing
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
Effective Scala @ Jfokus
Effective Scala @ JfokusEffective Scala @ Jfokus
Effective Scala @ Jfokus
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4
 
06 data
06 data06 data
06 data
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
 
Meet Couch DB
Meet Couch DBMeet Couch DB
Meet Couch DB
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Scaling DevOps
Scaling DevOpsScaling DevOps
Scaling DevOps
 
Moose
MooseMoose
Moose
 
Just Kotlin
Just KotlinJust Kotlin
Just Kotlin
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 

Dernier

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Dernier (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

The Not Java That's Not Scala

  • 1. | Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8 reserved. | Wednesday, October 5, 11
  • 2. The Not Java That's Not Scala: Alternatives for EE Development Justin Lee, Oracle | Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8 reserved. | Wednesday, October 5, 11
  • 3. Introduction  Who am I?  Using Java since 1996  GlassFish and Grizzly team member  websockets  Basement Coder  Used various languages over the years  python, c, c++, scala, ... Wednesday, October 5, 11
  • 4. Introduction  Who am I not?  A Scala hater  A language geek  Compiler jockey Wednesday, October 5, 11
  • 5. Why Not Java?  Java is 15+ years old now  Long time since the last release  Pace of change is geological  Verbosity  The shine has worn off  It's not cool!  It's “enterprisey”  it doesn't have my favorite feature! Wednesday, October 5, 11
  • 6. Why Not Scala?  Lots of advanced features that are not readily accessible to “Average Joes”  “Academics are driving the bus” - James Gosling  Complexity - real and perceived  new fangled features  esoteric features  rampant feature abuse: trait **->**->** {implicit def **->**- >**[A, F[_, _], B](a: F[A, B]): *->*->*[A, F, B] = new *->*- >*[A, F, B] {val value = a}} Wednesday, October 5, 11
  • 7. So What's Missing?  Closures  Syntax Cleanups  Succinctness  Typing/Inference  Generics  Concurrency Wednesday, October 5, 11
  • 8. So What's Missing?  Functional programming  Mutability  Null Handling  Extendability  Extension methods  Mixins  Modularity Wednesday, October 5, 11
  • 9. So … what would you suggest?  Suggest is a strong word but...  Fantom  Gosu  New to me, too, to one degree or another Wednesday, October 5, 11
  • 10. Fantom (Formerly known as Fan)  http://fantom.org  Familiar Syntax  Functional  Static and Dynamic Typing  “Modern” concurrency facilities  Portable  compile to JavaScript and SWT both Wednesday, October 5, 11
  • 11. Fantom - Portability  Fcode  JVM (of course)  .Net (partial)  JavaScript Wednesday, October 5, 11
  • 12. Fantom  Literals  maps: [1:"one", 2:"two"] , empty [:]  lists: [0, 1, 2], empty [,]  URIs: `/dir/file.txt`  Types: Int#  Slots: Int#plus Wednesday, October 5, 11
  • 13. Fantom public class Person { private String name; private int age; public Person(String s, int x) { name = s; age = x; } public String getName() { return name; } public void setName(String x) { name = x; } public int getAge() { return age; } public void setAge(int x) { checkAge(age); age = x; } int yearsToRetirement(int retire) { return (retire == -1 ? 65 : retire) - age } } Wednesday, October 5, 11
  • 14. Fantom class Person { Str name new make(String s, Int x) { name = s; age = x; } Int age { set { checkAge(it); &age = it } Int yearsToRetirement(Int retire := 65) { return retire - age } } Wednesday, October 5, 11
  • 15. Fantom Inheritance and Mixins: class Foo { class Bob : Foo, Bar { virtual Void bar() { echo("foo") } override baz := 10 } override Void bar() { echo("bob") } mixin Bar { } abstract Int baz Void yep(Int x) { baz = x } } Wednesday, October 5, 11
  • 16. Fantom Closures ["red", "yellow", "orange"].each |Str color| { echo(color) } 10.times |Int i| { echo(i) } 10.times |i| { echo(i) } 10.times { echo(it) } files = files.sort |a, b| { a.modified <=> b.modified } Functions add := |Int a, Int b->Int| { return a + b } nine := add(4, 5) Wednesday, October 5, 11
  • 17. Fantom Dynamic typing obj->foo // obj.trap("foo", [,]) Nullable Types Str // never stores null Str? // might store null Wednesday, October 5, 11
  • 18. Fantom Immutability const class Point{ new make(Int x, Int y) { this.x = x; this.y = y } const Int x const Int y } const static Point origin := Point(0, 0) stooges := [“Moe”,”Larry”,”Curly”].toImmutable Wednesday, October 5, 11
  • 19. Fantom Concurrency // spawn actor which aynchronously increments an Int msg actor := Actor(group) |Int msg->Int| { msg + 1 } // send some messages to the actor and block for result 5.times echo(actor.send(it).get) Wednesday, October 5, 11
  • 20. Fantom Standard Libraries // get file over HTTP WebClient(`http://fantom.org`).getStr // get tomorrow's date Date.today + 1day // date literals // compute HTTP Basic auth string res.headers["Authorization"] = "Basic " + "$user:$pass".toBuf.toBase64 Wednesday, October 5, 11
  • 21. Fantom Modularity and Meta-Programming // find pods available for installation in project "Cool Proj" repo := Repo.makeForUri(`http://my-fantom-repo/`) pods := repo.query(Str<|"* proj.name=="Cool Proj"|>) pods.each |p| { echo("$p.name $p.version $p.depends") } Wednesday, October 5, 11
  • 22. Fantom Modularity and Meta-Programming // find all types installed in system which subclass Widget Pod.list.each |pod| { pod.types.each |type| { if (type.fits(Widget#)) echo(type.qname) } } Wednesday, October 5, 11
  • 23. Fantom Modularity and Meta-Programming // find pods available for installation in project "Cool Proj" repo := Repo.makeForUri(`http://my-fantom-repo/`) pods := repo.query(Str<|"* proj.name=="Cool Proj"|>) pods.each |p| { echo("$p.name $p.version $p.depends") } Wednesday, October 5, 11
  • 24. Fantom Modularity and Meta-Programming // find pods available for installation in project "Cool Proj" repo := Repo.makeForUri(`http://my-fantom-repo/`) pods := repo.query(Str<|"* proj.name=="Cool Proj"|>) pods.each |p| { echo("$p.name $p.version $p.depends") } Wednesday, October 5, 11
  • 25. Fantom DSLs  embed other languages in your fantom code  similar to CDATA sections in XML  AnchorType <|...|>  echo(Str <|now is the time for all good men to come to the aid of their country.|>)  Regex <|^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$|> Wednesday, October 5, 11
  • 26. Fantom class RegexDslPlugin : DslPlugin { new make(Compiler c) : super(c) {} override Expr compile(DslExpr dsl) { regexType := ns.resolveType("sys::Regex") fromStr := regexType.method("fromStr") args := [Expr.makeForLiteral(dsl.loc, ns, dsl.src)] return CallExpr.makeWithMethod(dsl.loc, null, fromStr, args) } } // register in indexed props in build script index = ["compiler.dsl.sys::Regex": "compiler::RegexDslPlugin"] Wednesday, October 5, 11
  • 27. Fantom - Portability @Js class Demo { Void main() { // dumps to your browser's JS console 10.times |x| { echo("x: $x") } } Wednesday, October 5, 11
  • 28. Fantom - Tales @Js class ClickClickJs { class Routes{ Void main() { Route[] routes := Route[ Route{map="/clickclick"; Jq.ready { to="ClickClick";} Jq("#click").click|cur, event| { ] Win.cur.alert("Click Click") } event.preventDefault } } } } Wednesday, October 5, 11
  • 29. Fantom - Draft const class MyMod : DraftMod { new make() { pubDir = `...`.toFile router = Router { routes = [ Route("/", "GET", #index), Route("/echo/{name}/{age}", "GET", #echo) ] } } Wednesday, October 5, 11
  • 30. Fantom - Draft Void index() { res.headers["Content-Type"] = "text/plain" res.out.printLine("Hi there!") } Void echo(Str:Str args) { name := args["name"] age := args["age"].toInt res.headers["Content-Type"] = "text/plain" res.out.printLine("Hi $name, you are $age years old!") } Wednesday, October 5, 11
  • 31. Fantom - Resources  http://fantom.org #fantom on irc.freenode.net  http://www.talesframework.org/  Draft Mini Web Framework https://bitbucket.org/ afrankvt/draft/wiki/Home  http://spectreframework.org/  Twitter  @afrankvt  @briansfrank Wednesday, October 5, 11
  • 32. Gosu  http://gosu-lang.org  Again, familiar syntax  Statically typed  Enhancements  Closures  Simplified generics  Open Type System Wednesday, October 5, 11
  • 33. Gosu  == Object equality  === Instance equality  >, <, etc. works with java.lang.Comparable  Standard logical operators  Null Safety print( x?.length ) // prints "null"  var zeroToTenInclusive = 0..10 Wednesday, October 5, 11
  • 34. Gosu - Properties! public class MyJavaPersonClass { String _name; var p = new MyJavaPersonClass() public String getName() { p.Name = "Joe" return _name; print( "The name of this person is ${p.Name}") } public void setName(String s) { _name = s; } } Wednesday, October 5, 11
  • 35. Gosu uses java.util.List class SampleClass { var _names : List<String> // a private class variable, which is a list of Strings construct( names : List<String> ) { _names = names } function printNames( prefix : String ) { for( n in _names ) { print( prefix + n ) } } property get Names() : List<String> { return _names } } Wednesday, October 5, 11
  • 36. Gosu var c = new SampleClass({"joe", "john", "jack"}) c.printNames("* ") * joe * john * jack print( c.Names ) [joe, john, jack] Wednesday, October 5, 11
  • 37. Gosu uses java.util.List class SampleClass { var _names : List<String> construct( names : List<String> ) { _names = names } function printNames( prefix : String ) { for( n in _names ) { print( prefix + n ) } } property get Names() : List<String> { return _names } } Wednesday, October 5, 11
  • 38. Gosu uses java.util.List class SampleClass { var _names : List<String> as Names construct( names : List<String> ) { _names = names } function printNames( prefix : String ) { for( n in _names ) { print( prefix + n ) } } } Wednesday, October 5, 11
  • 39. Gosu uses java.util.List class SampleClass { var _names : List<String> as readonly Names construct( names : List<String> ) { _names = names } function printNames( prefix : String) { for( n in _names ) { print( prefix + n ) } } } Wednesday, October 5, 11
  • 40. Gosu uses java.util.List class SampleClass { var _names : List<String> as readonly Names construct( names : List<String> ) { _names = names } function printNames( prefix : String = "> ") { for( n in _names ) { print( prefix + n ) } } } Wednesday, October 5, 11
  • 41. Gosu class MyRunnable implements Runnable { delegate _runnable represents Runnable construct() { _runnable = new Runnable() { override function run() { print("Hello, Delegation") } } } property get Impl() : Runnable { return _runnable } property set Impl( r : Runnable ) { _runnable = r } } Wednesday, October 5, 11
  • 42. Gosu class MyRunnable implements Runnable { delegate _runnable represents Runnable construct() { _runnable = new Runnable() { override function run() { print("Hello, Delegation") } } } property get Impl() : Runnable { return _runnable } property set Impl( r : Runnable ) { _runnable = r } } var x = new MyRunnable() x.Impl = new Runnable() { override function run() { print("Hello, Delegation 2") } } Wednesday, October 5, 11
  • 43. Gosu - Donkey Patching Extensions enhancement MyStringEnhancement : String { function printMe() { print( this ) } } "Hello Enhancements".printMe() Enhancements are statically dispatched which means they cannot be used to implement interfaces or to achieve polymorphism Wednesday, October 5, 11
  • 44. Gosu Enhancements  String: rightPad(), leftPad(), center(), toDate(), toBoolean()  File: read(), write(), eachLine() Closures (Blocks) var listOfStrings = {"This", "is", "a", "list"} var longStrings = listOfStrings.where( s -> s.length>2) print( longStrings.join(", ") ) var r : Runnable r = -> print("This block was converted to a Runnable") Wednesday, October 5, 11
  • 45. Gosu Now for the fun part. Wednesday, October 5, 11
  • 46. Gosu Now for the fun part. XML marshalling! Wednesday, October 5, 11
  • 47. Gosu Now for the fun part. XML marshalling! JAXB is “great” and all but it can be … painful. Wednesday, October 5, 11
  • 48. Gosu Now for the fun part. XML marshalling! JAXB is “great” and all but it can be … painful. Gosu has great alternative. Wednesday, October 5, 11
  • 49. Gosu Now for the fun part. XML marshalling! JAXB is “great” and all but it can be … painful. Gosu has great alternative. But first <shudder/> an XSD... Wednesday, October 5, 11
  • 50. Gosu <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="age" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Wednesday, October 5, 11
  • 51. Gosu var bob = new myapp.example.Person() bob.Age = 32 bob.Firstname = "Bob" bob.Lastname = "Loblaw" bob.print() Wednesday, October 5, 11
  • 52. Gosu var bob = new myapp.example.Person() bob.Age = 32 bob.Firstname = "Bob" bob.Lastname = "Loblaw" bob.print() What about WSDL? Wednesday, October 5, 11
  • 53. Gosu var bob = new myapp.example.Person() bob.Age = 32 bob.Firstname = "Bob" bob.Lastname = "Loblaw" bob.print() // weather.wsdl var x = new myapp.weather() var forecast = x.GetCityForecastByZIP("95816") print( forecast.ForecastResult.Forecast.map( f -> f.Description ).join("n") ) Wednesday, October 5, 11
  • 54. Gosu Feature Literals var sub = String#substring(int) // class reference print( sub.invoke( "Now is the time for all good men", 2 ) ) // instance reference var sub = "Now is the time for all good men"#substring(int) print( sub.invoke( 2 ) ) Wednesday, October 5, 11
  • 55. Gosu Feature Literals var sub = String#substring(int) // class reference print( sub.invoke( "Now is the time for all good men", 2 ) ) // instance reference var sub = "Now is the time for all good men"#substring(2) print( sub.invoke() ) Wednesday, October 5, 11
  • 56. Gosu Feature Literals var sub = String#substring(int) // class reference print( sub.invoke( "Now is the time for all good men", 2 ) ) // instance reference var sub = "Now is the time for all good men"#substring(2) print( sub.invoke() ) var component = new Component(foo#Bar#Bob) Wednesday, October 5, 11
  • 57. Gosu - Ronin <%@ extends ronin.RoninTemplate %> <%@ params(name : String) %> <html> <body> Hello ${name}! </body> </html> Wednesday, October 5, 11
  • 58. Gosu - Ronin package controller uses ronin.* class Main extends RoninController { function hello(name : String) { view.Hello.render(writer, name) } } Wednesday, October 5, 11
  • 59. Gosu  http://www.gosu-lang.org  Web framework http://ronin-web.org/  ORM: http://ronin-web.org/Tosa.html  Build tool: Aardvark http://vark.github.com/  JVM Language Summit: http://medianetwork.oracle.com/ media/show/17005  Twitter: @carson_gross  IRC: #gosulang @ irc.freenode.net Wednesday, October 5, 11
  • 60. Justin Lee, Oracle http://antwerkz.com @evanchooly http://github.com/evanchooly http://www.basementcoders.com | Copyright © 2011, Oracle and/or it’s affiliates. All rights Insert Information Protection Policy Classification from Slide 8 reserved. | Wednesday, October 5, 11