41
Fantom The Developers Choice SlimerDude aka Steve Eynon

Fantom - The Developer's Choice!

Embed Size (px)

Citation preview

Fantom The Developers Choice

SlimerDude aka

Steve Eynon

Fantomis a

Future ProofNext Generation

Language

Fantom vs Java

VS.

Steve Eynon

• Assembler• Visual Basic• Java (13+ years!)• Javascript• Ruby• C#• Fantom!

Full Stack, web application, developer

- Tedious- Limited- Complicated- Anti-Agile- Dangerous- Ugly

FantomThe Developers Choice!

Contents4. Literals3. Core API2. Concurrency1. Language Sugar0. X-Platform Development

4. Literals

Fantom is a Forward Thinking

Language

Java: Integer Numbers byte – 8 bitsshort – 16 bits char – 16 bits int – 32 bits long – 64 bits

No performance gain in using fewer bits!

Plus morein C# !!

Fantom: Integer Number Int – 64 bits

Job done.

64 bits gives +/- 292 years of Nano seconds!

1ms = 1,000,000 ns

Java: Number Literals Onlyint countdown = 10;print("This spaceship will self destruct in " + countdown);

10!10 what?

Units are important!

Fantom: Duration Literalcountdown := 10minecho("This spaceship will self destruct in ${countdown}")

Duration choices:10ns, 10ms, 10sec, 10min, 10hr, 10day

We’re gonna make it!

Fantom: URI Literalurl := `http://fantom-lang.org/download`

url.scheme // --> httpurl.host // --> fantom-lang.orgurl.name // --> download

ID ‘36’ vs URI `myApp:/pages/36`

3. Core API

Fantom's Concise and Sane APIis a

Developer's Dream!

Java Collection FrameworkCollectionSetSortedSetListQueueDeque

45 classes in total!

Just the Interfaces!

Java Collection Framework

http://javaultimate.com/java/collection_introduction.htm

Java’s ListSimple View!

Fantom Collection Classsys::List

• Supports Generics• Functional w closures• All the methods you need

• Easy to remember• Easy to use

Job done.

Java Streamsjava.io package has 80 classes!

Fantom Streamssys::InStreamsys::OutStream

• Functional• All the methods you need

• Easy to remember• Easy to use

Read Text File : JavaFileReader fr = new FileReader("file.txt")BufferedReader br = new BufferedReader(fr);try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } String everything = sb.toString();} finally { br.close();}

http://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java

14 lines of code!

Read Text File : Fantomtext := File(`file.txt`).readAllStr

Job done.

Character Encoding“There Ain't No Such Thing As Plain Text.”

- Joel Spolsky

But UTF-8 is pretty darn close!

In Fantom, everything is UTF-8 by default!

http://www.joelonsoftware.com/articles/Unicode.html

2. Concurreny

Fantom uses Actors and the

Message Processing Model

Java: Mutable State

DataThread 1

Thread 2

Thread 3

Java: Mutable State• Difficult to implement safely

Threads, Locks, Semaphores, Synchronisation, Mutual exclusion, Memory barriers, Java's borked JSR133, Broken double locking mechanisms...

• Mutable state“All state is evil!” - functional programming

• Error proneSee above & 60 classes in “java.util.concurrent”

• Not scalableMore threads = more blocking / synchronising

Fantom: Msg Processing

Actor 1

Actor 2

Actor 3

Msg

MsgMsg

Fantom: Msg Processing• Easy to implement

Actors (threads) pass messages to each other4 classes in “concurrent” pod

• Immutable messagesCompiler enforces immutable messages – Actors have no access to mutable state

• SafeSee above

• ScalableUse more Actors to process multiple jobs

1. Language Sugar

Fantom’s Language Sugar

makes it a joy to program!

Java Getters / Settersprivate String greeting;

public String getGreeting() { return "Hello " + greeting + "!";}public void setGreeting(String greeting) { this.greeting = greeting.trim();}

myClass.greeting = "Mum";VsmyClass.setGreeting("Mum");

Fantom Field Accessors

Str greeting2 { get { "Hello ${&greeting}!" } set { &greeting = it.trim }}

Str greeting2 { private set} Read only field

Str greeting1 Standard field

Java SyntaxStringBuilder sb = new StringBuilder();Repeat, repeat, repeat…

Fantom Syntaxsb := StrBuf()Unique loose type inference.

Fantom SyntaxAnimal

Cat Dog

Void eat(Cat cat) { ... }

cat := Cat()dog := Dog()animal := dog as Animal

eat(cat) ✔eat(dog) ✗ -> Compile Erreat(animal) ? -> Runtime Err

Fantom Code Visibility

Internal to Pod

Private to Class

Public to Application

Honourable Mentions• Default method parameters• Everything is an Object• Nullable types• No checked exceptions• Simple reflection• Dynamic programming• Human readable object serialisation• Markdown documentation• …

0. Cross-Platform

Fantomfor

X-Platform Development

Browser Screenshots

Fanny the Fantom Game

Same code runs in a browser and as a desktop application!

WebsitesFanny the Fantom

fanny.fantomfactory.org

Fantomfantom.org

fantom-lang.orgwww.fantomfactory.org

Fantom The Developers Choice

SlimerDude aka

Steve Eynon

Fantom The Developers Choice

SlimerDude aka

Steve Eynon

Fantom The Developers Choice

SlimerDude aka

Steve Eynon

Fantom The Developers Choice

SlimerDude aka

Steve Eynon