A great choice when considering the Internet of Things

Fantom: Designed as a “better Java” [Pirates of the JVM]


If you don’t believe in ghosts, perhaps you’ll have a change of heart when you see Fantom, our next choice for the Pirates of the JVM series. The island of Fantom lies not far from Kotlin in the waters of the Static Sea. Brian Frank wanted to create a “better Java” and so Fantom was born — we talked to him about the advantages and disadvantages of this language, its core principles and more.

Do you believe in ghosts? This is not a horror story, we promise. Why would you choose Fantom when there are so many languages in the JVM ecosystem? Brian and Andy Frank, its creators, revealed in a blog post detailing how this programming language came to being that during its design, they wanted to solve what they perceived were some real problems with Java and C#.

The primary reason we created Fantom is to write software that can seamlessly run on both the Java VM and the .NET CLR. The reality is that many software organizations are committed to one or the other of these platforms. Even dynamic languages like Python and Ruby are getting hosted on one of these VMs. Whether your business is in-house software or building software components to sell to other companies, you tend to pick one camp or the other. We built Fantom from the ground up to tackle portability between these VMs.

Click on the map to see the entire infographic

The creators claim that Fantom is “truly is the next generation programming language” but let’s allow Brian Frank to convince you to give it a try.


Fantom — Background information

JAXenter: What was your motivation for working with Fantom? What does Fantom have to offer that other languages fail to provide?

Brian Frank: Fantom was originally designed as a “better Java” back when 1.5 had just recently been released.  From the very start, Fantom was designed to target multiple runtimes: Java VM, .NET CLR, and JavaScript in browser (although CLR support never made it to production quality).  Perhaps the most distinguishing feature of Fantom is that the entire runtime library was designed from day 1 to be portable between these environments.  For example, working with Strings, Uris, DateTimes, etc all work 100% the same way in the Java VM and in the browser.

Fantom also supports a strong actor based concurrency model with immutability built into the type system.  The concurrency model provides guarantees that mutable state is never shared between threads.

JAXenter: Can you describe the core principles of the language?

Brian Frank: The core principle for Fantom was a language easily written and read by developers familiar with Java, but with first class support for immutability and functional programming.  Our primary focus has always been on an elegant and cross-platform runtime library.  Here are some simple examples:

// create HTTP basic base64 authorization header
// read file, parse each line as an Integer |Str line->Int| { line.toInt }
// immutable class
const Point
  new make(Int x, Int y) { this.x = x; this.y = y }
  const Int x
  const Int y

JAXenter: What would a typical program with Fantom look like?

Brian Frank: Fantom looks very much like Java, except the closure syntax uses a Ruby inspired style syntax of “|arg1, arg2->return|”.  We also designed some clever techniques to use closures for declarative programming.  Here is a snippet of code to manipulate the DOM with some CSS styling:

  // manipulate CSS of this element>border = "1px solid black">background = "#ddd"
  // add some child elements
  Elem("div") { it.text = "Hello world!" },
  Elem("div") { it.text = "Bit of DOM" },

JAXenter: For what kind of applications/use cases is Fantom well-suited? For which ones it is not?

Brian Frank: Fantom is a perfect solution for development of web applications where a single language is desired for both server and browser side code.  Fantom has been used to develop web-based visualization tools, websites, databases, and embedded IoT applications.  It is suited to the same domains where Java is suited.

What’s next for Fantom

JAXenter: What is the current state of the language?

Brian Frank: The language has been used in production for over a decade.  Most development these days is associated with the runtime libraries.

JAXenter: How about your plans for Fantom?

Brian Frank: Our plans for Fantom is to keep it a pragmatic language for cross-platform (JVM and browser) development.

JAXenter: How can people interested in Fantom get started?

Brian Frank: They can visit and explore the various documentation and resources for getting started.

Brian Frank is the designer of Fantom Language and president of SkyFoundry.

Don’t forget to check out the Pirates of the JVM series.


Pirates of the JVM — The series:


Are you familiar with all the programming languages from the JVM universe? Have you discovered them all?

If the answer is “no”, we’ll leave no stone unturned in the search for knowledge. Therefore, the Pirates of the JVM infographic is accompanied by a series of articles in which we put the spotlight on the languages you may or may not know.

Inline Feedbacks
View all comments