Slide 1

Slide 1 text

Golo, the Tiny Language that gives super powers

Slide 2

Slide 2 text

Philippe Charrière > Technical “evangelist” & CSO @Clever_Cloud > Core committer for the eclipse/golo-lang project U@k33g_org / O @k33g

Slide 3

Slide 3 text

What is Golo?

Slide 4

Slide 4 text

A dynamic language for the JVM Built from the first day with invokedynamic Light (~700 kb) and fast (in a dynamic context) A research project by Julien Ponge http://golo-lang.org @jponge

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

https://jaxenter.com/pirates-of-jvm-golo-interview-132561.html

Slide 7

Slide 7 text

Why such a title? “The Tiny Language that gives super powers”

Slide 8

Slide 8 text

Thanks to Golo… I learned to read the Java doc I progressed in Java (I wasn’t a Java Ninja) I learned how to participate in an opensource project I do things I didn’t do before

Slide 9

Slide 9 text

Agenda We will not have enough time to “do the whole” of Golo

Slide 10

Slide 10 text

we are going to talk about: Golo’s simplicity some Golo’s specificities Functional Programming Golo ❤ Java Augmenting Golo

Slide 11

Slide 11 text

I use it for Source code generators Quick web applications Learning and POC

Slide 12

Slide 12 text

Golo’s Simplicity Quick landscape

Slide 13

Slide 13 text

Golo install Download Golo: http://golo-lang.org/download/ Unzip it export GOLO_HOME=~/golo-lang export PATH=$GOLO_HOME/bin:$PATH export PATH=~/:$PATH

Slide 14

Slide 14 text

Golo install You can build Golo git clone git@github.com:eclipse/golo-lang.git ./gradlew installDist

Slide 15

Slide 15 text

My first “hello world!”

Slide 16

Slide 16 text

Hello world module hello.world function main = |args| { println("Hello ") }

Slide 17

Slide 17 text

Hello world module hello.world function main = |args| { println("Hello ") }

Slide 18

Slide 18 text

Hello world module hello.world function main = |args| { println("Hello ") }

Slide 19

Slide 19 text

Hello world module hello.world function main = |args| { println("Hello ") }

Slide 20

Slide 20 text

How to run Golo code?

Slide 21

Slide 21 text

Run some Golo Code Several ways

Slide 22

Slide 22 text

Run some Golo Code: Compile and Run golo compile --output classes helloworld.golo golo run --module hello.world

Slide 23

Slide 23 text

Run some Golo Code: Maven or Gradle projects golo new hello --type maven --profile app mvn package mvn exec:java

Slide 24

Slide 24 text

Run some Golo Code: Maven or Gradle projects golo new hello --type maven --profile lib mvn package

Slide 25

Slide 25 text

Run some Golo Code My favorite way

Slide 26

Slide 26 text

Run Golo code as a script golo golo --classpath libs/*.jar --files imports/*.golo main.golo

Slide 27

Slide 27 text

Run Golo code as a script golo golo --classpath libs/*.jar --files imports/*.golo main.golo

Slide 28

Slide 28 text

Run Golo code as a script golo golo --classpath libs/*.jar --files imports/*.golo main.golo

Slide 29

Slide 29 text

Run Golo code as a script golo golo --classpath libs/*.jar --files imports/*.golo main.golo

Slide 30

Slide 30 text

Modules & Functions

Slide 31

Slide 31 text

Modules & Functions # my.lib.golo module my.lib function hello = |name| { return "Hello " + name } # short version function hi = |name| -> "Hi " + name # main.golo module myApp import my.lib function main = |args| { let name = "Baby Groot" println(hello(name)) println(hi(name)) }

Slide 32

Slide 32 text

Modules & Functions # my.lib.golo module my.lib function hello = |name| { return "Hello " + name } # short version function hi = |name| -> "Hi " + name # main.golo module myApp import my.lib function main = |args| { let name = "Baby Groot" println(hello(name)) println(hi(name)) }

Slide 33

Slide 33 text

Modules & Functions # my.lib.golo module my.lib function hello = |name| { return "Hello " + name } # short version function hi = |name| -> "Hi " + name # main.golo module myApp import my.lib function main = |args| { let name = "Baby Groot" println(hello(name)) println(hi(name)) }

Slide 34

Slide 34 text

Modules & Functions # my.lib.golo module my.lib function hello = |name| { return "Hello " + name } # short version function hi = |name| -> "Hi " + name # main.golo module myApp import my.lib function main = |args| { let name = "Baby Groot" println(hello(name)) println(hi(name)) }

Slide 35

Slide 35 text

Lambdas

Slide 36

Slide 36 text

Lambdas module lambdas function main = |args| { let add = |a, b| { return a + b } # compact version let addOne = |value| -> value + 1 println( add(40, 2) ) # 42 println( addOne(41) ) # 42 }

Slide 37

Slide 37 text

Lambdas module lambdas function main = |args| { let add = |a, b| { return a + b } # compact version let addOne = |value| -> value + 1 println( add(40, 2) ) # 42 println( addOne(41) ) # 42 }

Slide 38

Slide 38 text

Lambdas module lambdas function main = |args| { let add = |a, b| { return a + b } # compact version let addOne = |value| -> value + 1 println( add(40, 2) ) # 42 println( addOne(41) ) # 42 }

Slide 39

Slide 39 text

lambda -> lambda

Slide 40

Slide 40 text

Lambdas module lambdas function main = |args| { let something = |a, b| { return |value| -> (a + b) / value } println( something(40,44)(2) ) # 42 }

Slide 41

Slide 41 text

Lambdas module lambdas function main = |args| { let something = |a, b| -> |value| -> (a + b) / value println( something(40,44)(2) ) # 42 }

Slide 42

Slide 42 text

Lambdas module lambdas function main = |args| { let something = |a, b| { return |value| -> (a + b) / value } println( something(40,44)(2) ) # 42 }

Slide 43

Slide 43 text

Lambdas module lambdas function main = |args| { let something = |a, b| { return |value| -> (a + b) / value } let divideSum = something(40,44) println( divideSum(2) ) # 42 }

Slide 44

Slide 44 text

Some control & loop constructions

Slide 45

Slide 45 text

Control Structures

Slide 46

Slide 46 text

Control structures module control function main = |args| { let fourtyTwo = 42 if fourtyTwo is 42 { println("") } else { println("") } }

Slide 47

Slide 47 text

Control structures module control function main = |args| { let isEqualTo42 = |value| { case { when value is 42 { return " good" } when value > 42 { return " too big" } otherwise { return " too little" } } } println(isEqualTo42(42)) # good println(isEqualTo42(24)) # too little println(isEqualTo42(84)) # too big }

Slide 48

Slide 48 text

Loop Structures

Slide 49

Slide 49 text

Loop structures module loops function main = |args| { var counter = 0 while (counter < 4) { counter = counter + 1 } println(counter) # 4 }

Slide 50

Slide 50 text

Loop structures module loops function main = |args| { foreach item in [1, 2, 3, 4, 5] { if item < 3 { println(item) } } foreach item in [1, 2, 3, 4, 5] when item < 3 { println(item) } }

Slide 51

Slide 51 text

Loop structures with a guard module loops function main = |args| { foreach item in [1, 2, 3, 4, 5] { if item < 3 { println(item) } } foreach item in [1, 2, 3, 4, 5] when item < 3 { println(item) } }

Slide 52

Slide 52 text

Java types

Slide 53

Slide 53 text

Java types module javatypes function main = |args| { let vegetables = java.util.LinkedList() # no new keyword vegetables: add("") # colon notation vegetables: add("") vegetables: add("") println(vegetables) # [, , ] let mixedSalad = vegetables : stream() : map( |ingredient| -> java.lang.String.join(ingredient, ingredient, ingredient) ) : reduce("", |acc, next| -> acc + next) println(mixedSalad) # } # dot notation

Slide 54

Slide 54 text

Java types module javatypes function main = |args| { let vegetables = java.util.LinkedList() # no new keyword vegetables: add("") # colon notation vegetables: add("") vegetables: add("") println(vegetables) # [, , ] let mixedSalad = vegetables : stream() : map( |ingredient| -> java.lang.String.join(ingredient, ingredient, ingredient) ) : reduce("", |acc, next| -> acc + next) println(mixedSalad) # } # dot notation

Slide 55

Slide 55 text

Java types module javatypes function main = |args| { let vegetables = java.util.LinkedList() # no new keyword vegetables: add("") # colon notation vegetables: add("") vegetables: add("") println(vegetables) # [, , ] let mixedSalad = vegetables : stream() : map( |ingredient| -> java.lang.String.join(ingredient, ingredient, ingredient) ) : reduce("", |acc, next| -> acc + next) println(mixedSalad) # } # dot notation

Slide 56

Slide 56 text

Simpler way: Collection literals module javatypes function main = |args| { let vegetables = list["", "", ""] let mixedSalad = vegetables : map(|ingredient| -> "": join(ingredient,ingredient,ingredient)) : reduce("", |acc, next| -> acc + next) println(mixedSalad) # } java.util.LinkedList()

Slide 57

Slide 57 text

Simpler way: Collection literals module javatypes function main = |args| { let vegetables = list["", "", ""] let mixedSalad = vegetables : map(|ingredient| -> ingredient: join(ingredient,ingredient)) : reduce("", |acc, next| -> acc + next) println(mixedSalad) # }

Slide 58

Slide 58 text

Simpler way: Collection literals Collection Java type Syntax Tuple gololang.Tuple tuple[1, 2, 3], or simply [1, 2, 3] Array java.lang.Object[] array[1, 2, 3] List java.util.LinkedList list[1, 2, 3] Vector java.util.ArrayList vector[1, 2, 3] Set java.util.LinkedHashSet set[1, 2, 3] Map java.util.LinkedHashMap map[[1, "a"], [2, "b"]] Range gololang.Range [1..10], ['a'..'f']

Slide 59

Slide 59 text

Golo’s Specificities

Slide 60

Slide 60 text

no class with Golo❗

Slide 61

Slide 61 text

DynamicObjects

Slide 62

Slide 62 text

DynamicObject module clark function main = |args| { let clark = DynamicObject() : firstName("Clark"): lastName("Kent") : define("hello", |this| { println("Hello, I'm " + this: firstName()) return this }) : define("say", |this, message| { println(message) return this }) clark: hello(): say("hi!") # Hello, I'm Clark\n hi! clark: firstName("CLARK") clark: hello() # Hello, I'm CLARK clark: define("yo", |this| -> println("yo!")) }

Slide 63

Slide 63 text

DynamicObject module clark function main = |args| { let clark = DynamicObject() : firstName("Clark"): lastName("Kent") : define("hello", |this| { println("Hello, I'm " + this: firstName()) return this }) : define("say", |this, message| { println(message) return this }) clark: hello(): say("hi!") # Hello, I'm Clark\n hi! clark: firstName("CLARK") clark: hello() # Hello, I'm CLARK clark: define("yo", |this| -> println("yo!")) }

Slide 64

Slide 64 text

DynamicObject module clark function main = |args| { let clark = DynamicObject() : firstName("Clark"): lastName("Kent") : define("hello", |this| { println("Hello, I'm " + this: firstName()) return this }) : define("say", |this, message| { println(message) return this }) clark: hello(): say("hi!") # Hello, I'm Clark\n hi! clark: firstName("CLARK") clark: hello() # Hello, I'm CLARK clark: define("yo", |this| -> println("yo!")) }

Slide 65

Slide 65 text

Mixin of DynamicObjects module krypton function main = |args| { # set the kind of the DynamicObject let clark = DynamicObject("Kryptonian"): name("Clark") let kara = DynamicObject("Kryptonian"): name("Kara") let powers = DynamicObject(): define("fly", |this| -> println("")) clark: mixin(powers) kara: mixin(powers) clark: fly() # kara: fly() # }

Slide 66

Slide 66 text

Less dynamic but powerful: Structures

Slide 67

Slide 67 text

Structures module doeFamiliy struct human = { firstName, lastName } function main = |args| { # simple constructor let jane = human("Jane", "Doe") # constructor, then setters let john = human(): firstName("John"): lastName("Doe") println("hello we are " + jane: firstName() + " " + jane: lastName() + " and " + john: firstName() + " " + john: lastName() ) println(jane oftype doeFamiliy.types.human.class) # true }

Slide 68

Slide 68 text

Structures module doeFamiliy struct human = { firstName, lastName } function main = |args| { # simple constructor let jane = human("Jane", "Doe") # constructor, then setters let john = human(): firstName("John"): lastName("Doe") println("hello we are " + jane: firstName() + " " + jane: lastName() + " and " + john: firstName() + " " + john: lastName() ) println(jane oftype doeFamiliy.types.human.class) # true }

Slide 69

Slide 69 text

Augmenting Structure

Slide 70

Slide 70 text

Structures & Augmentations module doeFamiliy struct human = { firstName, lastName } augment human { function hello = |this| { println(this: firstName() + ": Hello!") } function hello = |this, message| { println(this: firstName() + ": Hello! " + message) } } function main = |args| { let jane = human("Jane", "Doe") jane: hello() # Jane: Hello! jane: hello("How are you doing?") # Jane: Hello! How are you doing? }

Slide 71

Slide 71 text

Structures & Augmentations module doeFamiliy struct human = { firstName, lastName } augment human { function hello = |this| { println(this: firstName() + ": Hello!") } function hello = |this, message| { println(this: firstName() + ": Hello! " + message) } } function main = |args| { let jane = human("Jane", "Doe") jane: hello() # Jane: Hello! jane: hello("How are you doing?") # Jane: Hello! How are you doing? }

Slide 72

Slide 72 text

Structures & named Augmentations module doeFamiliy struct human = { firstName, lastName } struct dog = { name } augmentation eat = { function eat = |this, something| -> println("I'm eating " + something) } augment human with eat augment dog with eat function main = |args| { let jane = human("Jane", "Doe") let cookie = dog("Cookie") jane: eat("") # I'm eating cookie: eat("") # I'm eating }

Slide 73

Slide 73 text

Promises

Slide 74

Slide 74 text

Golo translation from Java module http # synchronous method function getContent = |uri| { let obj = java.net.URL(uri) # URL obj let connection = obj: openConnection() # HttpURLConnection connection: setRequestMethod("GET") let responseCode = connection: getResponseCode() let responseMessage = connection: getResponseMessage() let responseText = java.util.Scanner( connection: getInputStream(), "UTF-8" ): useDelimiter("\\A"): next() # String responseText return responseText }

Slide 75

Slide 75 text

Synchronous version module demo_sync import http function main = |args| { let googleContent = getContent("http://www.google.com") println(googleContent) let goloContent = getContent("http://golo-lang.org/") println(goloContent) }

Slide 76

Slide 76 text

Synchronous -> Asynchronous with promises module demo_async import http import gololang.Async function main = |args| { # define a promise let getAsyncContent = |uri| -> promise(): initializeWithinThread(|resolve, reject| { try { let content = getContent(uri) resolve(content) } catch(error) { reject(error) } }) # call the promise getAsyncContent("http://www.google.com") : onSet(|result| { # if success println(result) }) : onFail(|error| { # if failed println(error: message()) }) } lambdas as parameters

Slide 77

Slide 77 text

Synchronous -> Asynchronous with promises module demo_async import http import gololang.Async function main = |args| { # define a promise let getAsyncContent = |uri| -> promise(): initializeWithinThread(|resolve, reject| { try { let content = getContent(uri) resolve(content) } catch(error) { reject(error) } }) # call the promise getAsyncContent("http://www.google.com") : onSet(|result| { # if success println(result) }) : onFail(|error| { # if failed println(error: message()) }) } resolve reject

Slide 78

Slide 78 text

Golo & Functional Programming

Slide 79

Slide 79 text

NPE Java -> Optional Haskell -> Maybe Golo -> Option

Slide 80

Slide 80 text

NPE module nomore_npe struct buddy = { id, avatar } function main = |args| { let buddies = list[buddy(1, ""), buddy(2, ""), buddy(3, "")] # println(buddies: find(|buddy| -> buddy: id(): equals(3)): avatar()) # java.lang.NullPointerException println(buddies: find(|buddy| -> buddy: id(): equals(4)): avatar()) }

Slide 81

Slide 81 text

Option() / Some / None function main = |args| { let buddies = list[buddy(1, ""), buddy(2, ""), buddy(3, "")] let getBuddy = |id| -> Option( buddies: find(|buddy| -> buddy: id(): equals(id)) ) let maybePanda = getBuddy(2) let maybeNobody = getBuddy(4) println( maybePanda ) # Optional[struct buddy{id=2, avatar=}] println( maybeNobody ) # Optional.empty println( maybePanda: isSome() ) # true println( maybeNobody: isNone() ) # true println( maybePanda: orElse(buddy(0, "")) ) # struct buddy{id=2, avatar=} println( maybeNobody: orElse(buddy(0, "")) ) # struct buddy{id=0, avatar=} }

Slide 82

Slide 82 text

Option() / Some / None function main = |args| { let buddies = list[buddy(1, ""), buddy(2, ""), buddy(3, "")] let getBuddy = |id| -> Option( buddies: find(|buddy| -> buddy: id(): equals(id)) ) let maybePanda = getBuddy(2) let maybeNobody = getBuddy(4) println( maybePanda ) # Optional[struct buddy{id=2, avatar=}] println( maybeNobody ) # Optional.empty println( maybePanda: isSome() ) # true println( maybeNobody: isNone() ) # true println( maybePanda: orElse(buddy(0, "")) ) # struct buddy{id=2, avatar=} println( maybeNobody: orElse(buddy(0, "")) ) # struct buddy{id=0, avatar=} }

Slide 83

Slide 83 text

Option() / Some / None function main = |args| { let buddies = list[buddy(1, ""), buddy(2, ""), buddy(3, "")] let getBuddy = |id| -> Option( buddies: find(|buddy| -> buddy: id(): equals(id)) ) let maybePanda = getBuddy(2) let maybeNobody = getBuddy(4) println( maybePanda ) # Optional[struct buddy{id=2, avatar=}] println( maybeNobody ) # Optional.empty println( maybePanda: isSome() ) # true println( maybeNobody: isNone() ) # true println( maybePanda: orElse(buddy(0, "")) ) # struct buddy{id=2, avatar=} println( maybeNobody: orElse(buddy(0, "")) ) # struct buddy{id=0, avatar=} }

Slide 84

Slide 84 text

Option() / either() function main = |args| { let buddies = list[buddy(1, ""), buddy(2, ""), buddy(3, "")] let getBuddy = |id| -> Option( buddies: find(|buddy| -> buddy: id(): equals(id)) ) getBuddy(2) : either( |buddy| { println("Hello "+ buddy: avatar()) }, # Hello { println(" ouch❗") } ) }

Slide 85

Slide 85 text

Result and Error

Slide 86

Slide 86 text

Result / Error module nomore_error import gololang.Errors function main = |args| { let divide = |a, b| { try { return Result(a/b) } catch(e) { return Error(e: message()) } } println( divide(84, 2) ) # Result.value[42] println( divide(84, 0) ) # Result.error[ java.lang.RuntimeException: / by zero] }

Slide 87

Slide 87 text

Result / Error / trying() / either() module nomore_error import gololang.Errors function main = |args| { let divide = |a, b| -> trying({ return a/b }) divide(84, 0): either( |result| -> println(": " + result), |error| -> println(": " + error: message()) # : / by zero ) }

Slide 88

Slide 88 text

Result / Error / trying() / either() module nomore_error import gololang.Errors function main = |args| { let divide = |a, b| -> trying({ return a/b }) divide(84, 0): either( |result| -> println(": " + result), |error| -> println(": " + error: message()) # : / by zero ) }

Slide 89

Slide 89 text

Golo ❤ Java

Slide 90

Slide 90 text

Golo ❤ Java package acme; import java.lang.String; import java.lang.System; public class Toon { private String name; public String getName() { return name; } public void setName(String value) { name = value; } public Toon(String name) { this.name = name; } public static Toon getInstance(String name) { return new Toon(name); } public void hug(Toon toon) { System.out.println("I ❤ " + toon.name); } } module toons import acme function main = |args| { let buster = Toon("Buster") # no new buster: name("Buster Bunny") println(buster: name()) let elmira = Toon.getInstance("elmira") elmira: hug(buster) }

Slide 91

Slide 91 text

Golo ❤ Java package acme; import java.lang.String; import java.lang.System; public class Toon { private String name; public String getName() { return name; } public void setName(String value) { name = value; } public Toon(String name) { this.name = name; } public static Toon getInstance(String name) { return new Toon(name); } public void hug(Toon toon) { System.out.println("I ❤ " + toon.name); } } module toons import acme function main = |args| { let buster = Toon("Buster") # no new buster: name("Buster Bunny") println(buster: name()) let elmira = Toon.getInstance("elmira") elmira: hug(buster) }

Slide 92

Slide 92 text

Golo ❤ Java package acme; import java.lang.String; import java.lang.System; public class Toon { private String name; public String getName() { return name; } public void setName(String value) { name = value; } public Toon(String name) { this.name = name; } public static Toon getInstance(String name) { return new Toon(name); } public void hug(Toon toon) { System.out.println("I ❤ " + toon.name); } } module toons import acme function main = |args| { let buster = Toon("Buster") # no new buster: name("Buster Bunny") println(buster: name()) let elmira = Toon.getInstance("elmira") elmira: hug(buster) }

Slide 93

Slide 93 text

and …

Slide 94

Slide 94 text

Golo ✨⚡ Java module toons import acme augment acme.Toon { function hey = |this, message| { println(this: name() + ": " + message) } } function main = |args| { let buster = Toon("Buster") buster: hey("I'm a ") }

Slide 95

Slide 95 text

Golo and the other frameworks

Slide 96

Slide 96 text

Golo Adapters to extend & inherit at runtime

Slide 97

Slide 97 text

RxJava with Java // defining the source Observable observable = Observable.interval(1, TimeUnit.SECONDS); // defining the observer Observer observer = new Observer() { @Override public void onSubscribe(Disposable disposable) { System.out.println(" subscribed"); } @Override public void onNext(Long value) { System.out.println(" " + value); } @Override public void onError(Throwable throwable) { System.out.println(" error"); } @Override public void onComplete() { System.out.println(" completed"); } }; // connecting the observer to source observable.subscribe(observer); java.lang.Thread.sleep(5000);

Slide 98

Slide 98 text

RxJava with Golo # defining the source let observable = Observable.interval(1_L, java.util.concurrent.TimeUnit.SECONDS()) # defining the observer let ObserverAdapter = Adapter(): interfaces(["io.reactivex.Observer"]) : implements("onSubscribe", |this, disposable| { println(" subscribed") }) : implements("onNext", |this, value| { println(" " + value) }) : implements("onError", |this, error| { println(" error") }) : implements("onComplete", |this| { println(" completed") }) let observer = ObserverAdapter: newInstance() # connecting the observer to source observable: subscribe(observer) sleep(5000_L) subscribed 0 1 2 3 4 http://golo-lang.org/documentation/next/index.html#_adapters_helper

Slide 99

Slide 99 text

Simplification with Golo

Slide 100

Slide 100 text

Java web application with Vert-x int httpPort = 8080; Vertx vertx = Vertx.vertx(); HttpServer server = vertx.createHttpServer(); Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/about").handler(routingContext -> { routingContext.response() .putHeader("content-type", "application/json;charset=UTF-8") .end((new JsonObject().put("about", " hello from Golo")).toString()); }); router.post("/hello").handler(routingContext -> { String name = routingContext.getBodyAsJson().getString("name"); routingContext.response() .putHeader("content-type", "application/json;charset=UTF-8") .end((new JsonObject().put("message", " Hello " + name)).toString()); }); server.requestHandler(router::accept).listen(httpPort);

Slide 101

Slide 101 text

A few augmentations later…

Slide 102

Slide 102 text

Simplify Vert-x let httpPort = 8080 let server = createHttpServer() let router = getRouter() router: get("/about", |context| { context: response(): djson(): about(" hello from Golo"): send() }) router: post("/hello", |context| { let data = context: dbody() let name = data: name() context: response(): djson(): message(" Hello " + name): send() }) startHttpServer(server, router, httpPort, "/*")

Slide 103

Slide 103 text

some of the augmentations augment io.vertx.ext.web.Router { function get = |this, uri, handler| { return this: get(uri): handler(handler) } function post = |this, uri, handler| { return this: post(uri): handler(handler) } } augment io.vertx.core.http.HttpServerResponse { function djson = |this| { this: putHeader("content-type", "application/json;charset=UTF-8") let d = DynamicObject() d: define("send", |self| { this: end(JSON.stringify(self), "UTF-8") }) return d } } augment io.vertx.ext.web.RoutingContext { function dbody = |this| -> JSON.toDynamicObjectFromJSONString(this: getBodyAsString()) }

Slide 104

Slide 104 text

Simplify Vert-x - Functional way let httpPort = Integer.parseInt(System.getenv(): get("PORT") orIfNull "8080") let server = createHttpServer() let router = getRouter() router: get("/about", |context| { context: response(): djson(): about(" hello from Golo"): send() }) router: post("/hello", |context| { trying({ let data = context: dbody() return data: name() }) : either( |name| -> context: response(): djson(): message(" Hello " + name): send(), |error| -> context: response(): djson(): error(" " + error: message()): send() ) }) startHttpServer(server, router, httpPort, "/*")

Slide 105

Slide 105 text

the source code https://github.com/golo-x/golo-x-web

Slide 106

Slide 106 text

I do some “IOT” with Golo

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

http://pi4j.com/ struct led = { pin, board } augment led { function toggle = |this| -> this: pin(): toggle() function off = |this| -> this: pulse(300_L, true) function name = |this| -> this: pin(): name() function blink = |this, howManyTimes, delay| -> (howManyTimes * 2): times(|index| { Thread.sleep(delay) this: toggle() }) function worker = |this, task| -> this: board(): workerEnvironment(): spawn(|message| { task(this, message) }) } function Led = |board, gpio, name, state| { let pin = digitalOutputPin(board, gpio, name, state): provision() return led(pin, board) }

Slide 109

Slide 109 text

http://pi4j.com/ struct led = { pin, board } augment led { function toggle = |this| -> this: pin(): toggle() function off = |this| -> this: pulse(300_L, true) function name = |this| -> this: pin(): name() function blink = |this, howManyTimes, delay| -> (howManyTimes * 2): times(|index| { Thread.sleep(delay) this: toggle() }) function worker = |this, task| -> this: board(): workerEnvironment(): spawn(|message| { task(this, message) }) } function Led = |board, gpio, name, state| { let pin = digitalOutputPin(board, gpio, name, state): provision() return led(pin, board) }

Slide 110

Slide 110 text

http://pi4j.com/ let greenLED = Led(breadBoard, GPIO_05(), "MyGreenLED", HIGH()) let greenWorker = greenLED: worker(|led, times| { println(led: name() + " is blinking ") led: blink(times,500_L) # howmanytimes, delay led: off() }) router: get("/blink/:led", |context| { let selectedLed = context: request(): param("led") match { when selectedLed: equals("red") then redWorker: send(5) when selectedLed: equals("green") then greenWorker: send(5) when selectedLed: equals("blue") then greenWorker: send(5) otherwise raise(" Huston!") } # … })

Slide 111

Slide 111 text

Arduino & Firmata4j

Slide 112

Slide 112 text

Firmata Firmata is a generic protocol for communicating with microcontrollers from software on a host computer

Slide 113

Slide 113 text

https://github.com/kurbatov/firmata4j # firmata4j let myArduino = device(): port("/dev/cu.usbmodem1411") let redLed = myArduino: getLedInstance("red", 13) redLed: switchOn() redLed: blink(1000_L) redLed: blink(1000_L) redLed: blink(1000_L) redLed: blink(1000_L)

Slide 114

Slide 114 text

a language to learn and try IOT the benefit of the entire Java Ecosystem easy experiments https://github.com/golo-x/golo-x-mqtt

Slide 115

Slide 115 text

Augmenting Golo

Slide 116

Slide 116 text

I am a superhero I’m not a real Java Developer I ❤ JavaScript and Node But I made (accepted) PR on the Golo project

Slide 117

Slide 117 text

It’s very easy to add features to Golo 3 ways Java Golo Invokedynamic

Slide 118

Slide 118 text

It’s very easy to add features to Golo 3 ways Java Golo Invokedynamic

Slide 119

Slide 119 text

the Golo project https://github.com/eclipse/golo-lang

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Demo

Slide 123

Slide 123 text

Thank you very much to you and codeeur

Slide 124

Slide 124 text

One more thing: https://tech.io

Slide 125

Slide 125 text

The end. Any Questions? (not too hard)