Your SlideShare is downloading. ×
0
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
Jazoon-2008.ppt
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

Jazoon-2008.ppt

666

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
666
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
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. A guide to modern languages and interesting concepts for the busy Java programmer Cedric Beust Google Jazoon 2008, Zurich
  • 2. About me <ul><li>Software engineer working at Google on the Android project </li></ul><ul><li>Creator of TestNG </li></ul><ul><li>Co author of &quot;Next Generation Testing in Java&quot; with Hani Suleiman </li></ul><ul><li>Really, really loves programming languages </li></ul>
  • 3. My goal <ul><li>&quot;Every programmer should learn at least one new language every year&quot; </li></ul><ul><li>To help you catch up on non-Java languages and innovative concepts... </li></ul><ul><li>… and show you that Java is in pretty good shape. </li></ul><ul><li>Answer the following question: </li></ul>
  • 4. <ul><li>What is the Next </li></ul><ul><li>Big </li></ul><ul><li>Language? </li></ul>
  • 5. Why I am doing this <ul><li>I love programming languages </li></ul><ul><li>… especially Java </li></ul><ul><li>Java is here to stay </li></ul>
  • 6. Menu <ul><li>1) Languages </li></ul><ul><li>Ruby </li></ul><ul><li>Scala </li></ul><ul><li>Groovy </li></ul><ul><li>Erlang </li></ul><ul><li>2) Java </li></ul><ul><li>Typing (dynamic, static, duck) </li></ul>
  • 7. Ruby (Yukihiro &quot;Matz&quot; Matsumoto) <ul><li>zippedFiles = </li></ul><ul><li>Dir.new(dir) </li></ul><ul><li>.entries </li></ul><ul><li>.sort </li></ul><ul><li>.reverse </li></ul><ul><li>.delete_if { |x| ! (x =~ /gz$/) } </li></ul>
  • 8. Ruby: why you should care <ul><li>Fully OO </li></ul><ul><li>Pleasant and regular syntax </li></ul><ul><li>Intuitive closure support </li></ul><ul><li>Ruby on Rails </li></ul>
  • 9. Ruby: why you shouldn't care too much <ul><li>Not statically typed </li></ul><ul><li>Slow </li></ul><ul><li>Open classes </li></ul><ul><li>Monkey patching </li></ul>
  • 10. Scala (Martin Odersky) <ul><li>A very interesting mix of Java and functional programming </li></ul><ul><li>Very solid type system </li></ul><ul><li>Here is a selection of noteworthy features </li></ul>
  • 11. Scala’s interesting features <ul><li>Closures </li></ul><ul><li>Pragmatic approach to functional programming </li></ul><ul><li>Universal accessors (no more fields!) </li></ul><ul><li>Option type (death to null!) </li></ul><ul><li>Generics </li></ul><ul><li>Class constructors: </li></ul><ul><li>class Person(name: String, age: int) { // ... } </li></ul>
  • 12. Scala’s case classes <ul><li>def printTerm(term: Term) { </li></ul><ul><li>term match { </li></ul><ul><li>case Var(n) => </li></ul><ul><li>print(n) </li></ul><ul><li> case Fun(x, b) => </li></ul><ul><li>print(&quot;^&quot; + x + “.”) </li></ul><ul><li>} </li></ul>
  • 13. Scala: what I don't like <ul><li>Implicits </li></ul><ul><li>Pro: clever way to implement open classes (automatic conversions, type safe) </li></ul><ul><li>Con: next slide… </li></ul>
  • 14. The problem with implicit <ul><li>scala> def speak (implicit greeting : String) = println(greeting) </li></ul><ul><li>speak: (implicit String)Unit </li></ul><ul><li>scala> speak(&quot;Goodbye world&quot;) </li></ul><ul><li>Goodbye world </li></ul><ul><li>scala> speak </li></ul><ul><li>:6: error: no implicit argument matching parameter type String was found. </li></ul><ul><li>scala> implicit val hello = &quot;Hello world&quot; </li></ul><ul><li>hello: java.lang.String = Hello world </li></ul><ul><li>scala> speak </li></ul><ul><li>Hello world </li></ul>
  • 15. Scala: why you should care <ul><li>Closures </li></ul><ul><li>Flexible operator overloading </li></ul><ul><li>Universal accessors (like Ruby and C# have) </li></ul><ul><li>Solid type system </li></ul><ul><li>Class constructors </li></ul><ul><li>Great integration with the Java platform </li></ul>
  • 16. Scala: why you shouldn't care too much <ul><li>More complex than Java </li></ul><ul><li>Implicits </li></ul><ul><li>Sophisticated generic system (as complex as Java, actually) </li></ul><ul><li>” Open classes”: clever but contrived </li></ul><ul><li>Case classes </li></ul>
  • 17. Last words on Scala <ul><li>Reconciling functional programming, imperative programming and the Java platform is tough </li></ul><ul><li>Good way to experiment and get familiar with functional programming concepts </li></ul><ul><li>Highly recommended: &quot;Programming in Scala&quot;, by Martin Odersky, Lex Spoon, and Bill Venners </li></ul><ul><li>@@ http://www.artima.com/images/scalafrontcover.jpg </li></ul>
  • 18. Groovy: why you should care <ul><li>Implements a lot of great ideas from various languages and concepts </li></ul><ul><li>High level, concise </li></ul><ul><li>Great integration with the Java platform </li></ul><ul><li>Interesting ideas and frameworks (expando objects, Grails) </li></ul><ul><li>Decent Eclipse support </li></ul>
  • 19. Groovy: why you shouldn't care too much <ul><li>Syntax is messy </li></ul><ul><li>Pell-mell of features added without a vision </li></ul><ul><li>Has a lot of dependencies </li></ul><ul><li>Slow </li></ul>
  • 20. Erlang (Joe Armstrong et al.) <ul><li>-module(trivial_process). </li></ul><ul><li>-export([start/0]). </li></ul><ul><li>start() -> </li></ul><ul><li>spawn(fun() -> loop() end). </li></ul><ul><li>loop() -> </li></ul><ul><li>receive </li></ul><ul><li>Any -> </li></ul><ul><li>io:format(&quot;~nI got the </li></ul><ul><li>message:~p~n&quot;,[Any]), </li></ul><ul><li>loop() </li></ul><ul><li>end. </li></ul>
  • 21. Erlang <ul><li>1> c(trivial_process). </li></ul><ul><li>{ok,trivial_process} </li></ul><ul><li>2> Pid = trivial_process:start(). </li></ul><ul><li><0.38.0> </li></ul><ul><li>3> Pid ! something. </li></ul><ul><li>something </li></ul><ul><li>I got the message: something </li></ul><ul><li>4> Pid ! [something,else]. </li></ul><ul><li>[something,else] </li></ul><ul><li>I got the message: [something,else] </li></ul>
  • 22. Erlang: why you should care <ul><li>No variables, only constants </li></ul><ul><li>Based on exchanging immutable messages, no shared data </li></ul><ul><li>Interesting approach to multiprocess and robustness (messages, supervisors) </li></ul>
  • 23. Erlang: why you shouldn't care too much <ul><li>Feels antiquated: no OO support, reuse is mostly copy/paste (creator has a strong anti-OO bias) </li></ul><ul><li>Very poor tool support </li></ul><ul><li>Still takes a lot of manual effort to support multiprocess and robustness </li></ul><ul><li>Declarative syntax (reminiscent of Prolog) </li></ul><ul><li>Syntax easy to get wrong (terminators, etc...) </li></ul>
  • 24. Erlang and remoteness <ul><li>&quot;If programmers cannot tell the difference between local and remote calls then it will be impossible to write efficient code.&quot; </li></ul><ul><li>Joe Armstrong (Erlang creator) </li></ul><ul><li>Erlang doesn't tell you if a process is remote or local (always assumed remote) </li></ul><ul><li>Three possible approaches: </li></ul><ul><li>Hide remoteness (bad idea, see &quot;A note on distributed computing&quot;, 1994) </li></ul><ul><li>Explicitly say when a call is local or remote (RMI and Java in general) </li></ul><ul><li>Assume everything is remote (Erlang) </li></ul>
  • 25. <ul><li>Back to Java </li></ul><ul><li>Let’s talk about types! </li></ul>
  • 26. Different types <ul><li>Static typing: the source files are enough to know the type of a variable </li></ul><ul><li>Dynamic typing: need to run the code to find out </li></ul><ul><li>Note: “strongly typed” and “weakly typed” are orthogonal to dynamic/static </li></ul>
  • 27. Types in practice <ul><li>Java: </li></ul><ul><ul><li>public void f(Person employee) { </li></ul></ul><ul><ul><li>employee.promote(); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>Ruby: </li></ul><ul><ul><li>def f(employee) { </li></ul></ul><ul><ul><li>employee promote </li></ul></ul><ul><ul><li>} </li></ul></ul>
  • 28. Dynamic typing <ul><li>Pros: </li></ul><ul><li>Fast prototyping </li></ul><ul><li>Usually more concise than static typing </li></ul>
  • 29. Dynamic typing <ul><li>Cons: </li></ul><ul><li>You need to know how to use a keyboard without making typos </li></ul><ul><li>Tests are mandatory </li></ul><ul><li>Very little help from tools (hardly any refactoring, primitive browsing and auto completion, “code change fear”) </li></ul><ul><li>Best case scenario: you catch a typo with your tests. </li></ul><ul><li>Worst case scenario: your customers catch the error for you. </li></ul>
  • 30. Dynamic typing is popular <ul><li>&quot;Compile time errors are not that common&quot; </li></ul><ul><li>==> True, but this is not the main problem with dynamic typing (tools!). </li></ul><ul><li>&quot;Smalltalk did it all more than twenty years ago!&quot; </li></ul><ul><li>==> Not really. </li></ul><ul><li>“ I’m ten times more productive with a dynamic language” </li></ul><ul><li>==> In the short term, probably. Gain in productivity also comes from features that are not related to dynamic typing (e.g. closures) </li></ul>
  • 31. Let's make something very clear <ul><li>Most automatic refactorings are impossible to achieve with dynamic languages. </li></ul><ul><li>Repeat: impossible </li></ul>
  • 32. One more personal thing about dynamic typing <ul><li>It makes me afraid </li></ul><ul><li>to change code. </li></ul>
  • 33. Duck typing <ul><li>def trace(o) </li></ul><ul><li>log(o.to_xml) </li></ul><ul><li>end </li></ul><ul><li>Duck typing is like alcohol: It feels great on the moment but causes headaches later. </li></ul>
  • 34. Duck typing refactoring <ul><li>def trace(o) </li></ul><ul><li>log(o.id + &quot;:&quot; + o.to_xml) </li></ul><ul><li>end </li></ul>
  • 35. Structural typing <ul><li>def test( </li></ul><ul><li>f: { def toXml(): String } </li></ul><ul><li>) </li></ul><ul><li>{ </li></ul><ul><li>log(f.toXml()) </li></ul><ul><li>} </li></ul>
  • 36. Structural typing <ul><li>Might as well capture it in a type (or a trait/mixin): </li></ul><ul><li>interface IXml { </li></ul><ul><li>String toXml(); </li></ul><ul><li>} </li></ul><ul><li>def test(f : IXml) { </li></ul><ul><li>log (f.toXml()); </li></ul><ul><li>} </li></ul>
  • 37. So, Java is perfect, right? <ul><li>public void update( </li></ul><ul><li>Map<Integer, String> accounts) </li></ul><ul><li>{ </li></ul><ul><li>Map<Integer, String> a2 = accounts; </li></ul><ul><li>Map<Integer, String> a3 = new </li></ul><ul><li>HashMap<Integer, String>(); </li></ul><ul><li>// ... </li></ul><ul><li>} </li></ul><ul><li>That's a lot of text... </li></ul>
  • 38. Type inference <ul><li>public void update( </li></ul><ul><li>Map<Integer,String> accounts) </li></ul><ul><li>{ </li></ul><ul><li>def a2 = accounts; </li></ul><ul><li>def a3 = new HashMap<Integer, </li></ul><ul><li>String>(); </li></ul><ul><li>// ... </li></ul><ul><li>} </li></ul><ul><li>Best of both worlds: statically typed and concise. </li></ul>
  • 39. Report card <ul><li>Java only supports static typing and no type inference </li></ul><ul><li>Ruby only supports dynamic typing (type inference N/A) </li></ul><ul><li>Scala is statically typed and supports type inference </li></ul><ul><li>Groovy is both dynamically and statically typed and supports type inference </li></ul>
  • 40. The Next Big Language <ul><li>Java’s strength is its ecosystem and its tools </li></ul><ul><li>The next big language will be evolutionary, not revolutionary </li></ul><ul><li>Java has been evolving and adapting fantastically well </li></ul>
  • 41. Next Big Language <ul><li>Strong IDE support </li></ul><ul><li>Stable v1.0 </li></ul><ul><li>Extensive documentation </li></ul><ul><li>Evolutionary syntax and features (closures, statically typed, optional dynamic support) </li></ul><ul><li>Close in speed to Java </li></ul>
  • 42. That’s it <ul><li>Any questions? (French okay!) </li></ul>
  • 43.  

×