Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Next Generation Java Ceylon, Kotlin, Scala & Fantom im Überblick
Autor: dogmadic : http://www.sxc.hu/photo/436457
http://www.sxc.hu/photo/36128
Disclaimer
Next Generation JVM Languages 2 |
Java
Überblick
Next Generation JVM Languages 3 |
3.
Überblick
Next Generation JVM Languages 4 |
3.
Ist Java das neue Cobol?
–
–
–
–
–
Next Generation JVM Languages 5 | http://www.sxc.hu/photo/1389360
Ein BLick auf die .NET Plattform
l
l
–
–
l
–
–
–
–
–
Next Generation JVM Languages 6 |
The JVM at a glance
l
l
–
–
–
–
l
–
–
–
Next Generation JVM Languages 7 |
Das Java- Universum
Next Generation JVM Languages 8 |
3.
Überblick
Next Generation JVM Languages 9 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 10 |
Next Generation JVM Languages 11 |
Beginning Buzz-Word Bingo….
http://www.sxc.hu/photo/377913
Warum neue JVM Sprachen?
Next Generation JVM Languages 12 |
Von Lambdas und „1. Klasse“-Rechnen
Next Generation JVM Languages 13 |
Imperativ vs. Funktional: Beispiel #1 Quicksort
Next Generation JVM Languages 14 |
public void quicksort(int array[]) {
quicksort(array, 0, array.length - 1);
}
public void quicksort(int array[], int start, int end){
int i = start;
int k = end;
if (end - start >= 1) {
int pivot = array[start];
while (k > i) {
while (array[i] <= pivot && i <= end && k > i) i++;
while (array[k] > pivot && k >= start && k >= i) k--;
if (k > i) swap(array, i, k);
}
swap(array, start, k);
quicksort(array, start, k - 1);
quicksort(array, k + 1, end);
} else {
return;
}
}
public void swap(int array[], int index1, int index2) {
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
public void quicksort(int array[]) {
quicksort(array, 0, array.length - 1);
}
public void quicksort(int array[], int start, int end){
int i = start;
int k = end;
if (end - start >= 1) {
int pivot = array[start];
while (k > i) {
while (array[i] <= pivot && i <= end && k > i) i++;
while (array[k] > pivot && k >= start && k >= i) k--;
if (k > i) swap(array, i, k);
}
swap(array, start, k);
quicksort(array, start, k - 1);
quicksort(array, k + 1, end);
} else {
return;
}
}
public void swap(int array[], int index1, int index2) {
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
Imperativ vs. Funktional: Beispiel #1 Quicksort
Next Generation JVM Languages 15 |
Imperativ vs. Funktional: Beispiel #2
Next Generation JVM Languages 16 |
int sum = 0;
for (int i = 0; i < 150; i++)
{
if (i % 5 != 0)
sum += i;
}
int sum = Enumerable.Range(0, 150).Where(i => i % 5 != 0).Sum();
f1( f2( f3( f4())))
Objektorientierte vs. Funktionale Programmierung
Next Generation JVM Languages 17 |
OOP
Sammlung von Objekten
Zustandsbehaftet
Iterativ
Imperativer Ablauf
F P
Sammlung von Funktionen
Zustandlos & Unveränderlich
Rekursiv
Auswertung: Lazy
Warum neue JVM Sprachen?
Next Generation JVM Languages 18 |
Dynamic Typing
Next Generation JVM Languages 19 | Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Parsen und
Auflisten der Daten
import org.xml.sax.SAXException;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.IOException;
public class ParseXml {
public static void main(String[] args) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("src/languages.xml");
//print the "type" attribute
Element langs = doc.getDocumentElement();
System.out.println("type = " + langs.getAttribute("type"));
//print the "language" elements
NodeList list = langs.getElementsByTagName("language");
for(int i = 0 ; i < list.getLength();i++) {
Element language = (Element) list.item(i);
System.out.println(language.getTextContent());
}
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
}catch(SAXException se) {
se.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
Dynamic Typing
Next Generation JVM Languages 20 | Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Parsen und
Auflisten der
Daten
def langs = new XmlParser().parse("languages.xml")
println "type = ${langs.attribute("type")}"
langs.language.each{
println it.text()
}
Dynamic Typing
Next Generation JVM Languages 21 | Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Parsen und
Auflisten der
Daten
Warum neue JVM Sprachen?
Next Generation JVM Languages 22 |
List<String> languages = new LinkedList<String>();
languages.add("Java");
languages.add("Ruby");
languages.add("Python");
languages.add("Perl");
Schlankere Syntax : Listen befüllen
Next Generation JVM Languages 23 | Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
stuff = []
stuff << "Java", "Ruby", "Python"
Class Circle
private Coordinate center, float radius;
public void setCenter(Coordinate center){
this.center = center;
}
public Coordinate getCenter(){
return center;
}
public void setRadius(float radius){
this.radius = radius;
}
public Coordinate getRadius(){
return radius;
}
}
Schlankere Syntax : Getter/Setter
Next Generation JVM Languages 24 | Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
class Circle
attr_accessor :center, :radius
end
Warum neue JVM Sprachen?
Next Generation JVM Languages 25 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 26 |
java.lang.NullPointerException at com.sun.tools.javac.comp.Check.checkCompatibleConcretes(Check.java:1141)
at com.sun.tools.javac.comp.Check.checkCompatibleSupertypes(Check.java:1495)
at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2451)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2406)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2355)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:444)
at com.sun.tools.javac.main.Main.compile(Main.java:592)
at com.sun.tools.javac.main.Main.compile(Main.java:544)
at com.sun.tools.javac.Main.compile(Main.java:67)
at com.sun.tools.javac.Main.main(Main.java:52)
Next Generation JVM Languages 27 |
Die Null zügeln
l
l
Next Generation JVM Languages 28 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 29 |
Domain Specific Languages
l
Next Generation JVM Languages 30 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 31 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 32 |
Next Generation JVM Languages 33 |
Alternativen zur Threads & Co.
l
–
–
–
l
–
–
Next Generation JVM Languages 34 | http://www.sxc.hu/photo/515995
Warum neue JVM Sprachen?
Next Generation JVM Languages 35 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 36 |
Scripting
l
–
l
–
–
–
Next Generation JVM Languages 37 |
Warum neue JVM Sprachen?
Next Generation JVM Languages 38 |
Meta-Programmierung
l
–
–
–
l
l
–
–
Next Generation JVM Languages 39 |
Programmen, die sich oder andere P. als Daten behandeln und verändert.
Warum neue JVM Sprachen?
Next Generation JVM Languages 40 |
Dynamic & Weak Typing
l
l
Next Generation JVM Languages 41 |
“A programming language is said to be dynamically typed when the majority
of its type checking is performed at run-time as opposed to at compile-time.
In dynamic typing values have types, but variables do not […]” https://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing
[…] strong typing when it specifies one or more restrictions on how operations
involving values of different data types can be intermixed.
Weak typing means that a language implicitly converts (or casts) types when used. https://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing
Warum neue JVM Sprachen?
Next Generation JVM Languages 42 |
Überblick
Next Generation JVM Languages 43 |
3.
Auszug neuer JVM Sprachen
Next Generation JVM Languages 44 |
Inzwischen über 50-250 verschiedene Sprachen auf der JVM…
Anforderungen für den Industriellen Einsatz
–
–
–
–
Next Generation JVM Languages 45 |
[...] programming by larger groups of people or by smaller groups over
longer time periods [...] result in large, and hence complicated, programs
[...] place emphasis on partitioning work into modules with precisely-
specified interactions.
http://en.wikipedia.org/wiki/Programming_in_the_large_and_programming_in_the_small
Sprachen im industriellen Einsatz
–
–
Next Generation JVM Languages 46 |
Auszug neuer JVM Sprachen
Next Generation JVM Languages 47 |
Übersicht & Entwicklung JVM Sprachen
Next Generation JVM Languages 48 |
Statisch-typisierte JVM Sprachen im Überblick
Next Generation JVM Languages 49 |
Next Generation JVM Languages 50 |
http://www.flickr.com/photos/tonino62/2295302323/ .
Scala im Portrait
Next Generation JVM Languages 51 |
l
–
Scala im Portrait
Next Generation JVM Languages 52 |
l
–
l
–
–
Traits & Mixins
trait Similarity {
def isSimilar(x: Any): Boolean
def isNotSimilar(x: Any): Boolean = !isSimilar(x)
}
Next Generation JVM Languages 53 |
Extension Methods
l
l
Next Generation JVM Languages 54 |
Scala & Ko-/Kontravarianz
Next Generation JVM Languages 55 | http://www.sxc.hu/photo/330223
TL;DR Too long; didn‘t read
Scala im Portrait
Next Generation JVM Languages 56 |
l
–
l
–
–
l
–
–
Scala - Implicit Conversion
Next Generation JVM Languages 57 |
object MainClass {
def main(args: Array[String]) {
val b : B = new A()
}
}
object A {
implicit def aToB(a: A) : B = {
new B()
}
}
Next Generation JVM Languages 58 |
Pattern Matching = Switch/Instanceof++
Next Generation JVM Languages 59 |
Beherrschbarkeit?
Next Generation JVM Languages 60 |
http://bit.ly/LP2Spb
Erfahrungen
l–
–
–
l–
–
–
Next Generation JVM Languages 61 |
Erfahrungen
l–
–
–
l–
–
Next Generation JVM Languages 62 |
JVM Sprachen im Überblick (Features)
Next Generation JVM Languages 63 |
Scala Summary
l–
–
l
l––
–
Next Generation JVM Languages 64 |
Next Generation JVM Languages 65 | http://www.sxc.hu/photo/366158
Fantom
Fantom : Portabilität
l
l
–
–
–
Next Generation JVM Languages 66 |
„one portable system, graphics, and widget library
that just works everywhere”
Fantom im Portrait
l
–
–
l
–
–
l
–
–
–
–
Next Generation JVM Languages 67 |
Fantom : Quadratur der Kreise
l
l
l
obj.methode()
obj->methode()
l
l
Next Generation JVM Languages 68 |
Fantom : Multi-Threading
–
–
–
Next Generation JVM Languages 69 |
Fantom : Elegante APIs und Sprache
–
–
–
–
–
–
–
–
Next Generation JVM Languages 70 |
Fantom Hello World (Webapp)
Next Generation JVM Languages 71 |
using util
using web
using wisp
class WebHello : AbstractMain
{
@Opt { help = "http port" }
Int port := 8080
override Int run()
{
wisp := WispService
{
it.port = this.port
it.root = HelloMod()
}
return runServices([wisp])
}
}
const class HelloMod : WebMod
{
override Void onGet()
{
res.headers["Content-Type"] =
"text/plain; charset=utf-8"
res.out.print("hello world #4")
}
}
Fantom: Summary
l–
–
–
l
l–
–
–
Next Generation JVM Languages 72 |
JVM Sprachen im Überblick (Features)
Next Generation JVM Languages 73 |
Next Generation JVM Languages 74 |
http://bit.ly/LKM5YG
Ceylon im Portrait
–
–
–
–
–
Next Generation JVM Languages 75 |
„Ceylon’s goal is to design the language that Java would have been
if its designers had been able to predict the future.”
Ceylon: Code Example
Next Generation JVM Languages 76 |
doc "A component"
shared abstract class Component() {
OpenList<Callable<Void,Event>> observers =
OpenList<Callable<Void,Event>>();
shared void addObserver(void observe(Event event)) {
observers.append(observe);
}
shared void fire(Event event) {
for (void observe(Event event) in observers) {
observe(event);
}
}
}
…bisschen Spannendes hat Ceylon aber schon…
l
l
l
Next Generation JVM Languages 77 | http://www.sxc.hu/photo/732192
Nullables
Next Generation JVM Languages 78 |
Von Typen mit und ohne Charakter
Next Generation JVM Languages 79 |
Ceylon: Summary
l
l
–
–
–
–
–
–
Next Generation JVM Languages 80 |
JVM Sprachen im Überblick (Features)
Next Generation JVM Languages 81 |
Next Generation JVM Languages 82 | http://www.sxc.hu/photo/1339625
Kotlin im Portrait
l
–
–
–
–
–
Next Generation JVM Languages 83 |
“General-purpose language intended for industrial use”
Kotlin = Java++ bzw. Scala--
Kotlin Motivation & Hintergrund
l
–
–
–
–
Next Generation JVM Languages 84 |
“Although we’ve developed support for several JVM-targeted programming languages,
we are still writing all of our IntelliJ-based IDEs almost entirely in Java.
We want to become more productive by switching to a more expressive language.”
Next Generation JVM Languages 85 |
Kotlin Sprach-Features
–
–
Next Generation JVM Languages 86 |
Kotlin Sprach-Features
l
l
Next Generation JVM Languages 87 |
interface Collection<E> ... {
void addAll(Collection<? extends E> items);
}
abstract class Source<out T> {
fun nextT() : T
}
fun fill(dest : Array<in String>, value : String) {
// ...
}
Kotlin Sprach-Features
l
l
l
l
l
l
l
Next Generation JVM Languages 88 |
Kotlin: Online Demo
Next Generation JVM Languages 89 |
Kotlin Summary:
l
l
l
l
l
l
Next Generation JVM Languages 90 |
JVM Sprachen im Überblick (Features)
Next Generation JVM Languages 91 |
3.
Überblick
Next Generation JVM Languages 92 |
Blick über den Tellerrand
Next Generation JVM Languages 93 | http://www.sxc.hu/photo/1167119/
Resumee
Next Generation JVM Languages 94 | http://www.sxc.hu/photo/1022369
Anforderungen für den Industriellen Einsatz
–
–
–
–
Next Generation JVM Languages 95 |
Wertung JVM Sprachen für den Industrie-Einsatz
Next Generation JVM Languages 96 |
Resumée
l
l
l
l
–
–l
l
l
–
Next Generation JVM Languages 97 |
Next Generation JVM Languages 98 |
Resumée
Next Generation JVM Languages 99 | Autor: woodleywonderworks
http://www.flickr.com/photos/wwworks/4759535950/
Weiterführende Information
Scala: http://www.scala-lang.org/
Ceylon: http://ceylon-lang.org/
Kotlin: http://blog.jetbrains.com/kotlin/
Kotlin Demo: http://kotlin-demo.jetbrains.com/
Fantom vs. Kotlin http://fantom.org/sidewalk/topic/1581
Gosu: http://gosu-lang.org/
Search for a better Java:
http://blog.joda.org/2011/07/kotlin-and-search-for-
better-java_9066.html