Fantom (programming language)

From Wikipedia, the free encyclopedia
  (Redirected from Fan (programming language))
Jump to: navigation, search
Fantom
Fantom-logo.png
Paradigm(s) multi-paradigm
Appeared in 2005[1]
Developer Brian Frank, Andy Frank
Stable release 1.0.62[2] (February 24, 2012; 13 days ago (2012-02-24))
Typing discipline static, dynamic
Influenced by C#, Java, Scala, Ruby, Erlang
License Academic Free License version 3.0[3]
Website www.fantom.org

Fantom is a general purpose object-oriented programming language that runs on the JRE, .NET CLR (this was discontinued), and JavaScript. The language supports functional programming through closures and concurrency through the Actor model. Fantom takes a "middle of the road" approach to its type system, blending together aspects of both static and dynamic typing. Like C# and Java, Fantom uses a curly brace syntax.

Contents

[edit] Typing

Fantom's type system is simple by design. All variables are statically typed, as they are in C# and Java. Fantom rejects generic types due to their complexity, but it does have a set of built-in generic types: List, Map, and Func. Fantom can also take on the feel of a dynamically typed language through dynamic calls and automatic downcasting. Fantom has an easy to use reflection API and metaprogramming capabilities.

Should you develop your applications for Java or .Net? If you code in Fantom, you can take your pick and even switch platforms midstream. That's because Fantom is designed from the ground up for cross-platform portability. The Fantom project includes not just a compiler that can output bytecode for either the JVM or the .Net CLI, but also a set of APIs that abstract away the Java and .Net APIs, creating an additional portability layer.[citation needed]

There are plans to extend Fantom's portability even further[citation needed]. A Fantom-to-JavaScript compiler is already available[citation needed], and future targets might include the LLVM compiler project[citation needed], the Parrot VM[citation needed], and Objective-C for iOS.

But portability is not Fantom's sole raison d'être. While it remains inherently C-like, it is also meant to improve on the languages that inspired it. It tries to strike a middle ground in some of the more contentious syntax debates, such as strong versus dynamic typing, or interfaces versus classes. It adds easy syntax for declaring data structures and serializing objects. And it includes support for functional programming and concurrency built into the language.

Fantom is open source under the Academic Free License 3.0 and is available for Windows and Unix-like platforms (including Mac OS X)". [4]

[edit] Pods

In Fantom, the unit of deployment is called a pod. Pods take on the role of namespaces, packages, and modules. They are stored as .pod files, which are zip files containing the FCode (the Fantom bytecode), the documentation, and resource files necessary to run the pod. A pod can define any number of types for use in other libraries and applications. A pod name fully qualifies a type name. For example, fwt::Widget is distinct from webapp::Widget. If a pod contains a type named Main, then it can be executed on the command line with: fan <podName>

The Fantom build system can package a set of Pods into a Jar archive through build::JarDist.

[edit] Fantom Widget Toolkit

Fantom ships with a standard windowing toolkit called the Fantom Widget Toolkit, or FWT for short.[5] Like Fantom, FWT was designed to be portable across several platforms. It is currently implemented on the JVM using the Standard Widget Toolkit as a backend. The Javascript implementation is backed by the canvas element and JavaFX, allowing FWT applications to be run in a web browser. There are plans for a CLR implementation using Windows Forms.

[edit] "Hello world" example

Here is the classic Hello world program written in Fantom:

// Hello from Fantom!
class HelloWorld
{
  static Void main()
  {
    echo("Hello, World!")
  }
}

[edit] Name change

The original name of the Fantom programming language was Fan, named after the neighborhood where the creators live in Richmond, Virginia. After gaining some popularity members of the community raised concerns about the searchability of the name. In November 2009[6], the name of the project was officially changed from Fan to Fantom.[7]

[edit] Other features

Fantom has other useful features:

  • Fantom supports imports of Java Classes and modules with some limitations[8]
  • Integer is 64-bit. It has no Long or Short like Java.
  • Serialization and deserialization of classes to/from strings.[9]

[edit] See also

[edit] References

[edit] External links

Personal tools
Namespaces

Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages