Upload
steve-eynon
View
45
Download
0
Embed Size (px)
Citation preview
Steve Eynon
• Assembler• Visual Basic• Java (13+ years!)• Javascript• Ruby• C#• Fantom!
Full Stack, web application, developer
- Tedious- Limited- Complicated- Anti-Agile- Dangerous- Ugly
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
Fantom: URI Literalurl := `http://fantom-lang.org/download`
url.scheme // --> httpurl.host // --> fantom-lang.orgurl.name // --> download
ID ‘36’ vs URI `myApp:/pages/36`
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!
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
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• 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
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
Honourable Mentions• Default method parameters• Everything is an Object• Nullable types• No checked exceptions• Simple reflection• Dynamic programming• Human readable object serialisation• Markdown documentation• …
WebsitesFanny the Fantom
fanny.fantomfactory.org
Fantomfantom.org
fantom-lang.orgwww.fantomfactory.org