Fantom
Fantom is  boring <ul><li>- Brian frank </li></ul>BY DESIGN creator of fantom (along with andy frank)
It’s about damn time We had a boring language
Java Let’s start with
Another language? Why do we need
Java was looking great in 1995
In 2011, still beautiful just a little old
Java Better? What would you change to make
Lets keep the compiler
THE LITTLE CHANGES
Remove semi-colens  <ul><li>int a = 0  ;  </li></ul><ul><li>int b = 2  ; </li></ul>int a = 0 int b = 2
String interpolation <ul><li>String event = “jug”; </li></ul><ul><li>String host = “Raj”; </li></ul>Sop(“Welcome to ‘“ + e...
Type inference <ul><li>String event = “Jug Meeting” </li></ul>event = “Jug Meeting”
Multiline strings <ul><li>String query = &quot;&quot;&quot; </li></ul><ul><li>select * from users where  </li></ul><ul><ul...
echo <ul><li>System.out.println(“hi”) </li></ul>echo(“hi”)
Everything’s an object <ul><li>3.toString() </li></ul><ul><li>3.times{  </li></ul><ul><li>echo(“hi”) </li></ul><ul><li>} <...
Non null-able fields <ul><li>Int a = 3  </li></ul><ul><li>Int? b = 3  </li></ul><ul><li>a = null //compiler error </li></ul>
Less noisy ‘list’ syntax  <ul><li>User[] users = new User[] </li></ul><ul><li>//Array style index access </li></ul><ul><li...
Less noisy ‘Map’ syntax  <ul><li>String:User map = String:User[:] </li></ul><ul><li>map[“steve”] = new User(); </li></ul><...
Accessor methods <ul><li>class Person{ </li></ul><ul><li>String name; </li></ul><ul><li>Int age { set { … }  get{…} } </li...
default param values <ul><li>Void printMyLang(Str lang = “java”){ </li></ul><ul><li>System.out.println(lang); </li></ul><u...
THE NOT-SO-LITTLE CHANGES
BETTER MODULARIZATION
Which jar? android-1.1.jar guava.jar com.google.utils.Activity jscomp.jar tales.jar
Which pod? tales.pod email.pod tales::Activity web.pod sys.pod
What are we giving up? <ul><li>Unique classes in pod </li></ul><ul><li>- No two “Utilities” class in a pod </li></ul><ul><...
easy reflection <ul><li>class Article{ </li></ul><ul><li>public String test(Str name){ </li></ul><ul><li>… . </li></ul><ul...
Readable serialization <ul><li>String str =  </li></ul><ul><li>“““ acme::Article </li></ul><ul><li>{ </li></ul><ul><li>tit...
STATIC AND DYNAMIC TYPING
Always compile Sometimes compile, Sometimes Don’t Never compile
Static and dynamic <ul><li>user := new User() </li></ul><ul><li>user.doSomething(“”); //Checked by compiler </li></ul><ul>...
MIXINS
interface with implementation <ul><li>mixin Audio </li></ul><ul><li>{ </li></ul><ul><li>abstract Int getVolume(); </li></u...
Pass around methods <ul><li>prefix :=  |Str name->Str| { return “Hi $name” } </li></ul><ul><li>suffix  :=  |Str name->Str|...
<ul><li>Just like threads.  </li></ul><ul><li>but no shared state </li></ul>ACTORS
BETTER APIS
<ul><li>Calendar </li></ul><ul><li>- Weird c like constants </li></ul><ul><li>- Months are zero based, Weekdays are 1 base...
BORING?
TALES
What’s a framework?
Current state of Tales
<ul><ul><li>Without tales you will need to know atleast </li></ul></ul><ul><ul><li>HTML, css </li></ul></ul><ul><ul><li>Ja...
Embrace HTML
What we will not have <ul><ul><li>// Create a 4 by 4 grid layout. </li></ul></ul><ul><ul><li>GridLayout grid = new GridLay...
What we will Definitely not have  <ul><ul><li><%for(int i=0;i<20; i++){%> </li></ul></ul><ul><ul><li>hello <%=name%>  </li...
What we will not even have <ul><ul><li><c:forEach var=&quot;i&quot; begin=&quot;1&quot; end=&quot;20&quot; step=&quot;1&qu...
What we will have <ul><ul><li>//template </li></ul></ul><ul><ul><li>Hello <div talesId=”name” /> </li></ul></ul><ul><ul><l...
What we will have(2) <ul><ul><li>//template </li></ul></ul><ul><ul><li><div talesId=”name” /> </li></ul></ul><ul><ul><li>/...
EMBRACE JAVASCRIPT
What we will not have <ul><ul><li>TextBox box = new TextBox(&quot;&quot;); </li></ul></ul><ul><ul><li>Link l = new Link(&q...
Encapsulate & compile <ul><ul><li>class  Alerter{ </li></ul></ul><ul><ul><li>Void sayHi(Str? taskName){ </li></ul></ul><ul...
Simpler than DWR Ajax <ul><ul><li>class  TaskPage : Page{ </li></ul></ul><ul><ul><li>Void addTask(Str? taskName){ </li></u...
Embrace Fantom
FIX AND GO
Dependency injection & AOP <ul><ul><li>Bind{type=UserService#; toType=”UserServiceImpl”}, </li></ul></ul><ul><ul><li>Bind{...
Embrace HTTP
REST
Stateful and Scalable <ul><ul><li>//During a Page Load </li></ul></ul><ul><ul><li>//Set values per page </li></ul></ul><ul...
Embrace SQL
Part ORM Part Data-mapping <ul><ul><li>//This is valid </li></ul></ul><ul><ul><li>User u := User{id = 1}.one </li></ul></u...
Upcoming SlideShare
Loading in …5
×

Fantom and Tales

1,200 views

Published on

Presentation at JUG-chennai on Fantom and Tales

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,200
On SlideShare
0
From Embeds
0
Number of Embeds
261
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Fantom and Tales

  1. 1. Fantom
  2. 2. Fantom is boring <ul><li>- Brian frank </li></ul>BY DESIGN creator of fantom (along with andy frank)
  3. 3. It’s about damn time We had a boring language
  4. 4. Java Let’s start with
  5. 5. Another language? Why do we need
  6. 6. Java was looking great in 1995
  7. 7. In 2011, still beautiful just a little old
  8. 8. Java Better? What would you change to make
  9. 9. Lets keep the compiler
  10. 10. THE LITTLE CHANGES
  11. 11. Remove semi-colens <ul><li>int a = 0 ; </li></ul><ul><li>int b = 2 ; </li></ul>int a = 0 int b = 2
  12. 12. String interpolation <ul><li>String event = “jug”; </li></ul><ul><li>String host = “Raj”; </li></ul>Sop(“Welcome to ‘“ + event + “’ by “ + host) Sop(“Welcome to ‘$event’ by $host “)
  13. 13. Type inference <ul><li>String event = “Jug Meeting” </li></ul>event = “Jug Meeting”
  14. 14. Multiline strings <ul><li>String query = &quot;&quot;&quot; </li></ul><ul><li>select * from users where </li></ul><ul><ul><ul><li>company=‘microsoft’ and userid </li></ul></ul></ul><ul><ul><ul><li>in(select id from usersalary </li></ul></ul></ul><ul><ul><ul><li>where sal > 200000000) </li></ul></ul></ul><ul><li>&quot;&quot;&quot; </li></ul>String query = “select * from users where” + “ company=‘microsoft’ and ” + “ userid in(select id from usersalary” + “ where sal > 200000000)”
  15. 15. echo <ul><li>System.out.println(“hi”) </li></ul>echo(“hi”)
  16. 16. Everything’s an object <ul><li>3.toString() </li></ul><ul><li>3.times{ </li></ul><ul><li>echo(“hi”) </li></ul><ul><li>} </li></ul>
  17. 17. Non null-able fields <ul><li>Int a = 3 </li></ul><ul><li>Int? b = 3 </li></ul><ul><li>a = null //compiler error </li></ul>
  18. 18. Less noisy ‘list’ syntax <ul><li>User[] users = new User[] </li></ul><ul><li>//Array style index access </li></ul><ul><li>users[0] = new User(); </li></ul><ul><li>//List style auto grow and stuff </li></ul><ul><li>users.add(new User()); </li></ul>
  19. 19. Less noisy ‘Map’ syntax <ul><li>String:User map = String:User[:] </li></ul><ul><li>map[“steve”] = new User(); </li></ul><ul><li>map[“woz”] = new User(); </li></ul>Map<String, User> map = new HashMap<String, User>(); map.put(“steve”, new User()); map.put(“woz”, new User());
  20. 20. Accessor methods <ul><li>class Person{ </li></ul><ul><li>String name; </li></ul><ul><li>Int age { set { … } get{…} } </li></ul><ul><li>} </li></ul><ul><li>Person p = new Person(); </li></ul><ul><li>p.name = “Kaushik”; </li></ul><ul><li>p.age = 20; </li></ul>
  21. 21. default param values <ul><li>Void printMyLang(Str lang = “java”){ </li></ul><ul><li>System.out.println(lang); </li></ul><ul><li>} </li></ul><ul><li>printMyLang(); //prints “java” </li></ul><ul><li>printMyLang(“fantom”); //prints “fantom” </li></ul>
  22. 22. THE NOT-SO-LITTLE CHANGES
  23. 23. BETTER MODULARIZATION
  24. 24. Which jar? android-1.1.jar guava.jar com.google.utils.Activity jscomp.jar tales.jar
  25. 25. Which pod? tales.pod email.pod tales::Activity web.pod sys.pod
  26. 26. What are we giving up? <ul><li>Unique classes in pod </li></ul><ul><li>- No two “Utilities” class in a pod </li></ul><ul><li>Unique method name in a class </li></ul><ul><li>- No method overloading </li></ul>
  27. 27. easy reflection <ul><li>class Article{ </li></ul><ul><li>public String test(Str name){ </li></ul><ul><li>… . </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>Obj obj := Article() </li></ul><ul><li>Str title := Atricle#.method(“test”).invoke(obj) </li></ul>
  28. 28. Readable serialization <ul><li>String str = </li></ul><ul><li>“““ acme::Article </li></ul><ul><li>{ </li></ul><ul><li>title = &quot;Something&quot; </li></ul><ul><li>viewCount = 123 </li></ul><ul><li>}””” </li></ul><ul><li>Article a = str.in.readObj </li></ul>
  29. 29. STATIC AND DYNAMIC TYPING
  30. 30. Always compile Sometimes compile, Sometimes Don’t Never compile
  31. 31. Static and dynamic <ul><li>user := new User() </li></ul><ul><li>user.doSomething(“”); //Checked by compiler </li></ul><ul><li>user->doSomething(“”); //Checked by runtime </li></ul><ul><li>if dynamic method not present, a trap() implementation is called to do “meta” programming </li></ul>
  32. 32. MIXINS
  33. 33. interface with implementation <ul><li>mixin Audio </li></ul><ul><li>{ </li></ul><ul><li>abstract Int getVolume(); </li></ul><ul><li>Void incrementVolume() { volume += 1 } </li></ul><ul><li>Void decrementVolume() { volume -= 1 } </li></ul><ul><li>} </li></ul><ul><li>class Television : Audio </li></ul><ul><li>{ </li></ul><ul><li>override Int getVolume(){return 0;} </li></ul><ul><li>} </li></ul>
  34. 34. Pass around methods <ul><li>prefix := |Str name->Str| { return “Hi $name” } </li></ul><ul><li>suffix := |Str name->Str| { return “$name, Hello”} </li></ul><ul><ul><li>sayWelcome(prefix) </li></ul></ul><ul><ul><li>sayWelcome(suffix) </li></ul></ul><ul><ul><li>Void sayWelcome(|Str->Str| code){ </li></ul></ul><ul><ul><li>log(“going to say welcome”) </li></ul></ul><ul><ul><li>code(“Kaushik”) </li></ul></ul><ul><ul><li>log(“Said welcome”) </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>3.times{ </li></ul></ul><ul><ul><li>echo(“hi”) </li></ul></ul><ul><ul><li>} </li></ul></ul>
  35. 35. <ul><li>Just like threads. </li></ul><ul><li>but no shared state </li></ul>ACTORS
  36. 36. BETTER APIS
  37. 37. <ul><li>Calendar </li></ul><ul><li>- Weird c like constants </li></ul><ul><li>- Months are zero based, Weekdays are 1 based </li></ul><ul><li>IO </li></ul><ul><li>- Over 60 classes </li></ul><ul><ul><ul><li>- In fantom most functionalities in 4 classes File, Buf, Instream, OutStream </li></ul></ul></ul>DATE AND IO
  38. 38. BORING?
  39. 39. TALES
  40. 40. What’s a framework?
  41. 41. Current state of Tales
  42. 42. <ul><ul><li>Without tales you will need to know atleast </li></ul></ul><ul><ul><li>HTML, css </li></ul></ul><ul><ul><li>JavaScript </li></ul></ul><ul><ul><li>Fantom </li></ul></ul><ul><ul><li>SQL </li></ul></ul>Tales is Boring <ul><ul><li>With tales you will need to know only </li></ul></ul><ul><ul><li>HTML, css </li></ul></ul><ul><ul><li>JavaScript </li></ul></ul><ul><ul><li>Fantom </li></ul></ul><ul><ul><li>SQL </li></ul></ul>
  43. 43. Embrace HTML
  44. 44. What we will not have <ul><ul><li>// Create a 4 by 4 grid layout. </li></ul></ul><ul><ul><li>GridLayout grid = new GridLayout(4, 4); </li></ul></ul><ul><ul><li>grid.addStyleName(&quot;example-gridlayout&quot;); </li></ul></ul><ul><ul><li>// Fill out the first row using the cursor. </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&quot;R/C 1&quot;)); </li></ul></ul><ul><ul><li>for (int i = 0; i < 3; i++) { </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&quot;Col &quot; + (grid.getCursorX() + 1))); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>// Fill out the first column using coordinates. </li></ul></ul><ul><ul><li>for (int i = 1; i < 4; i++) { </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&quot;Row &quot; + i), 0, i); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>// Add some components of various shapes. </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&quot;3x1 button&quot;), 1, 1, 3, 1); </li></ul></ul><ul><ul><li>grid.addComponent(new Label(&quot;1x2 cell&quot;), 1, 2, 1, 3); </li></ul></ul><ul><ul><li>InlineDateField date = new InlineDateField(&quot;A 2x2 date field&quot;); </li></ul></ul><ul><ul><li>date.setResolution(DateField.RESOLUTION_DAY); </li></ul></ul><ul><ul><li>grid.addComponent(date, 2, 2, 3, 3); </li></ul></ul>
  45. 45. What we will Definitely not have <ul><ul><li><%for(int i=0;i<20; i++){%> </li></ul></ul><ul><ul><li>hello <%=name%> </li></ul></ul><ul><ul><li><%}%> </li></ul></ul>
  46. 46. What we will not even have <ul><ul><li><c:forEach var=&quot;i&quot; begin=&quot;1&quot; end=&quot;20&quot; step=&quot;1&quot; varStatus=&quot;status&quot;> </li></ul></ul><ul><ul><li><c:out value=&quot;${i}&quot; /> </li></ul></ul><ul><ul><li></c:forEach> </li></ul></ul>
  47. 47. What we will have <ul><ul><li>//template </li></ul></ul><ul><ul><li>Hello <div talesId=”name” /> </li></ul></ul><ul><ul><li>//fantom </li></ul></ul><ul><ul><li>add(label->name(“kaushik”)) </li></ul></ul><ul><ul><li>//output </li></ul></ul><ul><ul><li>Hello <div>kaushik</div> </li></ul></ul>
  48. 48. What we will have(2) <ul><ul><li>//template </li></ul></ul><ul><ul><li><div talesId=”name” /> </li></ul></ul><ul><ul><li>//fantom </li></ul></ul><ul><ul><li>User[] users := User{}.list </li></ul></ul><ul><ul><li>add(repeater->name(users)|User user|{ </li></ul></ul><ul><ul><li>text->value(user.name) </li></ul></ul><ul><ul><li>}) </li></ul></ul><ul><ul><li>//output </li></ul></ul><ul><ul><li><div>name1</div> </li></ul></ul><ul><ul><li><div>name2</div> </li></ul></ul><ul><ul><li><div>name3</div> </li></ul></ul><ul><ul><li><div>name4</div> </li></ul></ul>
  49. 49. EMBRACE JAVASCRIPT
  50. 50. What we will not have <ul><ul><li>TextBox box = new TextBox(&quot;&quot;); </li></ul></ul><ul><ul><li>Link l = new Link(&quot;click me&quot;); </li></ul></ul><ul><ul><li>Label a = new Label(&quot;&quot;); </li></ul></ul><ul><ul><li>add(box); </li></ul></ul><ul><ul><li>add(l); </li></ul></ul><ul><ul><li>add(a); </li></ul></ul><ul><ul><li>link.addActionListener(new ActionListener(){ </li></ul></ul><ul><ul><li>public void actionPerformed(ActionEven e){ </li></ul></ul><ul><ul><li>a.setText(box.getVal()); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>}); </li></ul></ul><ul><ul><li>//because this is easy too.. </li></ul></ul><ul><ul><li>$(&quot;#link&quot;).click(function(){ </li></ul></ul><ul><ul><li>$(&quot;#label&quot;).text($(&quot;#box&quot;).val()); </li></ul></ul><ul><ul><li>}); </li></ul></ul>
  51. 51. Encapsulate & compile <ul><ul><li>class Alerter{ </li></ul></ul><ul><ul><li>Void sayHi(Str? taskName){ </li></ul></ul><ul><ul><ul><ul><li>client<| </li></ul></ul></ul></ul><ul><ul><ul><ul><li>alert(taskName); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>|> </li></ul></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul><ul><ul><li>.. </li></ul></ul><ul><ul><li>a. sayHi(2); //Will not compile </li></ul></ul>
  52. 52. Simpler than DWR Ajax <ul><ul><li>class TaskPage : Page{ </li></ul></ul><ul><ul><li>Void addTask(Str? taskName){ </li></ul></ul><ul><ul><ul><ul><li>client<| </li></ul></ul></ul></ul><ul><ul><ul><ul><li>if(!taskName){alert(“No task name”); return;} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>params[“name”] = taskName; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>|> </li></ul></ul></ul></ul><ul><ul><ul><ul><li>server{ </li></ul></ul></ul></ul><ul><ul><ul><ul><li>taskService.addTask(params[“name”]); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>client<| </li></ul></ul></ul></ul><ul><ul><ul><ul><li> alert(“Task added”); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>|> </li></ul></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  53. 53. Embrace Fantom
  54. 54. FIX AND GO
  55. 55. Dependency injection & AOP <ul><ul><li>Bind{type=UserService#; toType=”UserServiceImpl”}, </li></ul></ul><ul><ul><li>Bind{name = “noOfRows”; toValue=5} </li></ul></ul><ul><ul><li>class UserPage{ </li></ul></ul><ul><ul><li>@inject UserService userService; </li></ul></ul><ul><ul><li>@inject noOfRows </li></ul></ul><ul><ul><li>} </li></ul></ul>
  56. 56. Embrace HTTP
  57. 57. REST
  58. 58. Stateful and Scalable <ul><ul><li>//During a Page Load </li></ul></ul><ul><ul><li>//Set values per page </li></ul></ul><ul><ul><li>page[“captcha-val”] = “dixleo” </li></ul></ul><ul><ul><li>//During another request from that page </li></ul></ul><ul><ul><li>Str captchaVal = page[“captcha-val”] </li></ul></ul>
  59. 59. Embrace SQL
  60. 60. Part ORM Part Data-mapping <ul><ul><li>//This is valid </li></ul></ul><ul><ul><li>User u := User{id = 1}.one </li></ul></ul><ul><ul><li>User[] users := User{company = “oracle”}.list </li></ul></ul><ul><ul><li>//This is too.. </li></ul></ul><ul><ul><li>User[] users := User{}.queryList(“select id, name from users”) </li></ul></ul><ul><ul><li>//you can even externalize your queries </li></ul></ul><ul><ul><li>Class BlogSql{ </li></ul></ul><ul><ul><li>Str userSql := “select id, name from users” </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>//And get it injected </li></ul></ul><ul><ul><li>@inject Sql blogSql </li></ul></ul><ul><ul><li>User[] users := User{}.queryList(blogSql->userSql) </li></ul></ul>

×