17
A Shallow Survey of Alternative Languages on the JVM Charles Anderson March 2013

A Shallow Survey of Alternative Languages on the JVM

Embed Size (px)

DESCRIPTION

TBA

Citation preview

Page 1: A Shallow Survey of Alternative Languages on the JVM

A Shallow Survey of Alternative Languages on the JVM

Charles AndersonMarch 2013

Page 2: A Shallow Survey of Alternative Languages on the JVM

Introduction

● Survey a few languages on the JVM○ Some philosophy of those languages

● Discuss the value of the Java Platform● These concepts are applicable to other VM-

based platforms - e.g., Microsoft

Page 3: A Shallow Survey of Alternative Languages on the JVM

The Java Language

● Been around for almost 20 years● Verbose● Slow to execute● Slow to start-up● Slow to evolve● Very widely used

Page 4: A Shallow Survey of Alternative Languages on the JVM

Ported Languages

● A language that was originally implemented elsewhere - probably C/C++

● Common examples include : JRuby, Jython, Jacl

● Others (from Wikipedia): Ada, Fortran, Cobol, Go, etc.

Page 5: A Shallow Survey of Alternative Languages on the JVM

Why?

● Because I can● Research● Easier than writing to bare metal or C

○ C is portable assembly○ Java is the new C?

● To leverage the Java Platform

Page 6: A Shallow Survey of Alternative Languages on the JVM

The Java Platform

● Java the language● Java libraries - To Leverage Enterprise

Synergies of Multi-vendor, Standards-compliant, Powerpoint slide decks

● Java Virtual Machine○ Performance - JIT○ Garbage collection○ Threading

● Tools● There's a reason Twitter moved a lot of their

system to the JVM

Page 7: A Shallow Survey of Alternative Languages on the JVM

Best of Both Worlds

● Get to write in a cool, "new" language (e.g. Ruby) without leaving the benefits of the Java Platform

● Many such languages include a REPL● You can use cool frameworks (e.g.

Cucumber or web apps) with your Java code

Page 8: A Shallow Survey of Alternative Languages on the JVM

Issues with Ported Languages

● Owe allegiance to the mother language○ Leads to impedance mismatches - e.g., JRuby

● Usually, can call into Java easily, but can run into problems with other combinations - e.g., inheritance

● Performance - improving (invoke dynamic)

Page 9: A Shallow Survey of Alternative Languages on the JVM

New Languages: Groovy

● Starting from Java, add cool stuff, cut down on boilerplate - easy transition for Java programmers

● Strives to be compatible with Java/Platform● Cool playground for future features of the

Java language - e.g., closures● http://groovy.codehaus.org/

Page 10: A Shallow Survey of Alternative Languages on the JVM

Java or Groovy?

class Book {private String title;Book (String theTitle) {

title = theTitle;}String getTitle() {

return title}

}

Page 11: A Shallow Survey of Alternative Languages on the JVM

Stupid Pet Tricksprintln ‘Hello World’

class MyBean implements Serializable {String myProp

}

Thread.start { /* some code */ }

coll.each { item-> /* some code */ }

coll.findAll { it % 2 == 0 }.each{ ... }

new File(‘foo.txt’).eachLine { println it }

Page 12: A Shallow Survey of Alternative Languages on the JVM

New Languages: Mirah

● Start with Ruby and move back towards Java○ static typing and type inference○ no attempt at Ruby compatibility - no Rails○ macros and meta-programming

● Very immature - v. 0.1 recently release● http://www.mirah.org/

Page 13: A Shallow Survey of Alternative Languages on the JVM

Little Sample of Mirah

def printN(str:String, n:int) n.times do puts str endend

Page 14: A Shallow Survey of Alternative Languages on the JVM

New Languages: Scala

● Let's create a brand new language● A hybrid of object-oriented and functional

○ Functional is important for multi-core● Statically typed with a "dynamic" feel● Still very compatible with Java/Platform● http://www.scala-lang.org/

Page 15: A Shallow Survey of Alternative Languages on the JVM

Samples of Scala

class Point (var x:int, var y:int)

employees.sort (_.age > _.age)

val s = for (x <- 1 to 25 if x*x > 50) yield 2*x

Page 16: A Shallow Survey of Alternative Languages on the JVM

Other New Languages

● Clojure - LISP, functional● Koitlin - compiles to Java or JavaScript

(from JetBrains/IntelliJ)● Ceylon from RedHat

Page 17: A Shallow Survey of Alternative Languages on the JVM

Conclusion

● You don't have to program in Java to get the benefit of the Java Platform

● Classic Trojan horse strategy - testing or other "utility" programming○ not production○ not performance critical○ more productive testing means more real code○ just a jar file