Your SlideShare is downloading. ×
0
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Fantom and Tales
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Fantom and Tales

1,058

Published on

Presentation at JUG-chennai on Fantom and Tales

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,058
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Fantom
  • 2. Fantom is boring <ul><li>- Brian frank </li></ul>BY DESIGN creator of fantom (along with andy frank)
  • 3. It’s about damn time We had a boring language
  • 4. Java Let’s start with
  • 5. Another language? Why do we need
  • 6. Java was looking great in 1995
  • 7. In 2011, still beautiful just a little old
  • 8. Java Better? What would you change to make
  • 9. Lets keep the compiler
  • 10. THE LITTLE CHANGES
  • 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. 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. Type inference <ul><li>String event = “Jug Meeting” </li></ul>event = “Jug Meeting”
  • 14. Multiline strings <ul><li>String query = &amp;quot;&amp;quot;&amp;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 &gt; 200000000) </li></ul></ul></ul><ul><li>&amp;quot;&amp;quot;&amp;quot; </li></ul>String query = “select * from users where” + “ company=‘microsoft’ and ” + “ userid in(select id from usersalary” + “ where sal &gt; 200000000)”
  • 15. echo <ul><li>System.out.println(“hi”) </li></ul>echo(“hi”)
  • 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. 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. 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. 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&lt;String, User&gt; map = new HashMap&lt;String, User&gt;(); map.put(“steve”, new User()); map.put(“woz”, new User());
  • 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. 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. THE NOT-SO-LITTLE CHANGES
  • 23. BETTER MODULARIZATION
  • 24. Which jar? android-1.1.jar guava.jar com.google.utils.Activity jscomp.jar tales.jar
  • 25. Which pod? tales.pod email.pod tales::Activity web.pod sys.pod
  • 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. 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. Readable serialization <ul><li>String str = </li></ul><ul><li>“““ acme::Article </li></ul><ul><li>{ </li></ul><ul><li>title = &amp;quot;Something&amp;quot; </li></ul><ul><li>viewCount = 123 </li></ul><ul><li>}””” </li></ul><ul><li>Article a = str.in.readObj </li></ul>
  • 29. STATIC AND DYNAMIC TYPING
  • 30. Always compile Sometimes compile, Sometimes Don’t Never compile
  • 31. Static and dynamic <ul><li>user := new User() </li></ul><ul><li>user.doSomething(“”); //Checked by compiler </li></ul><ul><li>user-&gt;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. MIXINS
  • 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. Pass around methods <ul><li>prefix := |Str name-&gt;Str| { return “Hi $name” } </li></ul><ul><li>suffix := |Str name-&gt;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-&gt;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. <ul><li>Just like threads. </li></ul><ul><li>but no shared state </li></ul>ACTORS
  • 36. BETTER APIS
  • 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. BORING?
  • 39. TALES
  • 40. What’s a framework?
  • 41. Current state of Tales
  • 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. Embrace HTML
  • 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(&amp;quot;example-gridlayout&amp;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(&amp;quot;R/C 1&amp;quot;)); </li></ul></ul><ul><ul><li>for (int i = 0; i &lt; 3; i++) { </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&amp;quot;Col &amp;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 &lt; 4; i++) { </li></ul></ul><ul><ul><li>grid.addComponent(new Button(&amp;quot;Row &amp;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(&amp;quot;3x1 button&amp;quot;), 1, 1, 3, 1); </li></ul></ul><ul><ul><li>grid.addComponent(new Label(&amp;quot;1x2 cell&amp;quot;), 1, 2, 1, 3); </li></ul></ul><ul><ul><li>InlineDateField date = new InlineDateField(&amp;quot;A 2x2 date field&amp;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. What we will Definitely not have <ul><ul><li>&lt;%for(int i=0;i&lt;20; i++){%&gt; </li></ul></ul><ul><ul><li>hello &lt;%=name%&gt; </li></ul></ul><ul><ul><li>&lt;%}%&gt; </li></ul></ul>
  • 46. What we will not even have <ul><ul><li>&lt;c:forEach var=&amp;quot;i&amp;quot; begin=&amp;quot;1&amp;quot; end=&amp;quot;20&amp;quot; step=&amp;quot;1&amp;quot; varStatus=&amp;quot;status&amp;quot;&gt; </li></ul></ul><ul><ul><li>&lt;c:out value=&amp;quot;${i}&amp;quot; /&gt; </li></ul></ul><ul><ul><li>&lt;/c:forEach&gt; </li></ul></ul>
  • 47. What we will have <ul><ul><li>//template </li></ul></ul><ul><ul><li>Hello &lt;div talesId=”name” /&gt; </li></ul></ul><ul><ul><li>//fantom </li></ul></ul><ul><ul><li>add(label-&gt;name(“kaushik”)) </li></ul></ul><ul><ul><li>//output </li></ul></ul><ul><ul><li>Hello &lt;div&gt;kaushik&lt;/div&gt; </li></ul></ul>
  • 48. What we will have(2) <ul><ul><li>//template </li></ul></ul><ul><ul><li>&lt;div talesId=”name” /&gt; </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-&gt;name(users)|User user|{ </li></ul></ul><ul><ul><li>text-&gt;value(user.name) </li></ul></ul><ul><ul><li>}) </li></ul></ul><ul><ul><li>//output </li></ul></ul><ul><ul><li>&lt;div&gt;name1&lt;/div&gt; </li></ul></ul><ul><ul><li>&lt;div&gt;name2&lt;/div&gt; </li></ul></ul><ul><ul><li>&lt;div&gt;name3&lt;/div&gt; </li></ul></ul><ul><ul><li>&lt;div&gt;name4&lt;/div&gt; </li></ul></ul>
  • 49. EMBRACE JAVASCRIPT
  • 50. What we will not have <ul><ul><li>TextBox box = new TextBox(&amp;quot;&amp;quot;); </li></ul></ul><ul><ul><li>Link l = new Link(&amp;quot;click me&amp;quot;); </li></ul></ul><ul><ul><li>Label a = new Label(&amp;quot;&amp;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>$(&amp;quot;#link&amp;quot;).click(function(){ </li></ul></ul><ul><ul><li>$(&amp;quot;#label&amp;quot;).text($(&amp;quot;#box&amp;quot;).val()); </li></ul></ul><ul><ul><li>}); </li></ul></ul>
  • 51. Encapsulate &amp; 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&lt;| </li></ul></ul></ul></ul><ul><ul><ul><ul><li>alert(taskName); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>|&gt; </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. 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&lt;| </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>|&gt; </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&lt;| </li></ul></ul></ul></ul><ul><ul><ul><ul><li> alert(“Task added”); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>|&gt; </li></ul></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  • 53. Embrace Fantom
  • 54. FIX AND GO
  • 55. Dependency injection &amp; 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. Embrace HTTP
  • 57. REST
  • 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. Embrace SQL
  • 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-&gt;userSql) </li></ul></ul>

×