introduction to jvm languages and fantom (very brief)

36
Introduction to JVM Languages and Fantom @jph98

Upload: jph98

Post on 17-Jul-2015

82 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Introduction to JVM languages and Fantom (very brief)

Introduction to JVM Languages

and Fantom

@jph98

Page 2: Introduction to JVM languages and Fantom (very brief)

Welcom

e...

Page 3: Introduction to JVM languages and Fantom (very brief)

What I’ll Cover

JVM languages and a brief history

Where Fantom fits into the JVM language

landscape

Characteristics of the Fantom and a few

examples

Page 4: Introduction to JVM languages and Fantom (very brief)

JVM Languages

Page 5: Introduction to JVM languages and Fantom (very brief)

Java

Source Code

JIT Compiler

x86 Native Code

JIT Compiler

x86_64 Native Code

Bytecode

Compiler Compiler

Fantom

Source Code

JVM JVM

Page 6: Introduction to JVM languages and Fantom (very brief)

Why do we need JVM languages?

More expressive, dynamic, functional

Reduce amount of “boiler plate” code

A way of modernising and pushing the

language forward

Page 7: Introduction to JVM languages and Fantom (very brief)

Da Vinci Machine Project

Project to extend the JVM for supporting other

languages:

- Tail call optimisation

- Interface injection

- Dynamic invocation

- Continuations

Page 8: Introduction to JVM languages and Fantom (very brief)

Language Categories

General purpose languages focusing on a

specific paradigm

Languages translated from other languages

Paradigm specific or multi paradigm languages

Page 9: Introduction to JVM languages and Fantom (very brief)

Quiz

Anybody care to guess how many JVM

languages there are?

Page 10: Introduction to JVM languages and Fantom (very brief)

2007

Clojure

JVM Language History

1997

Jython/JPython

1998

Bluedragon/CFML

2000

Beanshell

2001

JRuby

Processing

Judoscript

2003

Groovy

Gosu

Scala

2008

Ioke

2011

Kotlin

Ceylon

Xtend

Page 11: Introduction to JVM languages and Fantom (very brief)

General Purpose Languages

Functional Languages (e.g. Frege)

Dynamically Typed Languages (e.g. JRuby)

Multi Paradigm Languages (e.g. Scala)

Page 12: Introduction to JVM languages and Fantom (very brief)

Languages Translated to the JVM

Ada

JGNAT

Go JGo

Lisp

CLforJava

JS

Nashorn

Pascal Free

Pascal

Prolog JLog

Python Jython

R

Renjin

REXX Netrexx

Ruby JRuby

Scheme Bigloo

Tcl Jacl

Page 13: Introduction to JVM languages and Fantom (very brief)

Specific Purpose Languages

Parallel Programming

- Ateji (Commercial)

- Chapel (Developed by Cray)

- X10 (Developed by IBM)

Visualisation and animation

- Processing

Page 14: Introduction to JVM languages and Fantom (very brief)

CLR Languages (CLI)

.NET CLR also has a number of languages:

Boo (Python esque) P# (Prolog)

IKVM (Java)

Phalanger (PHP)

IronRuby

IronPython

Page 15: Introduction to JVM languages and Fantom (very brief)
Page 16: Introduction to JVM languages and Fantom (very brief)

Overview

Originally called Fan, created by Brian Frank

and Andy Frank

Academic Free License

I’m covering this as an alternative to the

standard Scala, Clojure yada yada...

Page 17: Introduction to JVM languages and Fantom (very brief)

Intent

Provide a language that compiles to:

- JVM (Java) - JavaFFI

- CLR (.NET) - DotnetFFI

- Browser (Javascript) -

Produces fcode (intermediate CLR/JVM/JSVM)

code

Page 18: Introduction to JVM languages and Fantom (very brief)

Ecosystem Overview

Focus on providing elegant API’s

Provides a REPL

Modules in the form of Pods

Desktop (FWT) and web (Webmod)

Page 19: Introduction to JVM languages and Fantom (very brief)

Characteristics

Object Oriented, Functional

Static and Dynamic Typing (Choice of)

64 bit Float, Int, Decimal + Str, Bool

Duration, Uri, Slot, Range, List, Map

Page 20: Introduction to JVM languages and Fantom (very brief)

Fantom Language Features

Page 21: Introduction to JVM languages and Fantom (very brief)

Classes

Public and abstract

Can also be Final, Const or Internal

Example...

Page 22: Introduction to JVM languages and Fantom (very brief)

Mixins

Like interfaces, but with method

implementations. Public defender methods.

Can group a number of slots together for reuse

Can’t contain state, you need to provide own

Page 23: Introduction to JVM languages and Fantom (very brief)

Mixing Static and Dynamic

person.addAddress(“New Bond House”);

person->addAddress(“New Bond House”);

Page 24: Introduction to JVM languages and Fantom (very brief)

Reducing Boilerplate Code

Concise in places, optional setters/getters

Null safe fields, elvis operator

Page 25: Introduction to JVM languages and Fantom (very brief)

Accessors, optional sets/gets

Accessors: class Person {

Str name

Int age

}

Page 26: Introduction to JVM languages and Fantom (very brief)

Null Check Operators (Elvis)

name ?: “No name specified”

Variables can also be marked nullable or non-nullable

Page 27: Introduction to JVM languages and Fantom (very brief)

Closures

Closure can be thought of as a function that

can be stored in a variable

Can access variables in same scope as defined

Useful for event handling

Page 28: Introduction to JVM languages and Fantom (very brief)

Closure Examples

10.times |i| {

echo(i)

}

10.times {

echo(it)

}

Page 29: Introduction to JVM languages and Fantom (very brief)

Closure Examples

Str first := “Bart”

Str last := “Simpson”

f := |->Str| { return first + “ “ + last }

Page 30: Introduction to JVM languages and Fantom (very brief)

Actor Concurrency System

Works around a message passing model

Actor is responsible for specific tasks

Lets take a look at a counter example...

Page 31: Introduction to JVM languages and Fantom (very brief)

Concurrency with Actors

pool := ActorPool()

["one", "two", "three", "four"].each {

a := Actor(pool) |Str name| {

echo("Thread $name says Hello World!")

}

a.send(it)

}

Page 32: Introduction to JVM languages and Fantom (very brief)

FFI - Foreign Function Interface

JavaFFI - Java type system into Fantom

DotnetFFI - not available yet

Use native classes to provide functionality

Page 33: Introduction to JVM languages and Fantom (very brief)

DSL’s - Domain Specific Languages

StrDSL

RegexDSL

Can write your own using the DslPlugin

Page 34: Introduction to JVM languages and Fantom (very brief)

Conclusions

Impressive set of features for the language

Some useful constructs to avoid boilerplate

code

Main focus in Java and JS. Looking for .NET

contributors for the DotNetFFI.

Page 35: Introduction to JVM languages and Fantom (very brief)

Conclusions

There’s a lot more to cover here in terms of

learning…

Where are the JVM languages going?

Java 8, Java 9… inclusions...

Page 36: Introduction to JVM languages and Fantom (very brief)

Questions?

http://wiki.colar.net/fan_cheat_sheet