Live coding scala 'the java of the future'
-
Upload
xebia-nederland-bv -
Category
Technology
-
view
670 -
download
0
Transcript of Live coding scala 'the java of the future'
![Page 1: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/1.jpg)
Urs Peter 19:45 uur - Zaal Zand (boven)
Live Coding
'the Java of the future’
![Page 2: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/2.jpg)
Core ingredients of Scala
Java
1.7
![Page 3: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/3.jpg)
Who uses Scala?
![Page 4: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/4.jpg)
Scala Dev environment
![Page 5: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/5.jpg)
Classes
Options Our first sip of
Traits
Implicits
Tuples
![Page 6: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/6.jpg)
Loops
A single ride with many loops
![Page 7: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/7.jpg)
![Page 8: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/8.jpg)
Pattern Matching
![Page 9: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/9.jpg)
The future is bright, the future is fun -ctional
![Page 10: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/10.jpg)
Scala Collections
The beginning of a beautiful friendship
![Page 11: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/11.jpg)
Google Code Jam Exercise Problem The aim of this task is to translate a language into a new language called Googlerese. To translate we take any message and replace each English le<er with another English le<er. This mapping is one-‐to-‐one and onto, which means that the same input le<er always gets replaced with the same output le<er, and different input le<ers always get replaced with different output le<ers. A le<er may be replaced by itself. Spaces are leC as-‐is. For example (and here is a hint!), the translaIon algorithm includes the following three mappings: 'a' -‐> 'y', 'o' -‐> 'e', and 'z' -‐> 'q'. This means that "a zoo" will become "y qee". Sample Input/Output Input: Case #1: ejp mysljylc kd kxveddknmc re jsicpdrysi
Case #2: rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd Case #3: de kr kd eoya kw aej tysr re ujdr lkgc jv"
Output: Case #1: our language is impossible to understand
Case #2: there are twenty six factorial possibilities Case #3: so it is okay if you want to just give up"
![Page 12: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/12.jpg)
Lets go parallel
![Page 13: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/13.jpg)
(Back to) The future of Java
![Page 14: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/14.jpg)
Java8 will have Lambda Expressions Java
root.listFiles((File f) -> f.isDirectory());""//even with type inference"root.listFiles(f -> f.isDirectory());""//... and shorthand notation"root.listFiles(File::isDirectory);""""
root.listFiles(f:File => f.isDirectory)""root.listFiles(f => f.isDirectory)""root.listFiles(_.isDirectory)"
Scala
![Page 15: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/15.jpg)
Java8 will have internal iteration with Lambda expressions Java
double highestScore ="" students.filter(Student s -> s.getGradYear() == 2011)"" " .map(Student s -> s.getScore())"" " .max();"
""
val highestScore = ""studens.filter(s:Student => s.gradYear == 2011)"" ".map(s:Student => s.score)"" ".max"
Scala
![Page 16: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/16.jpg)
Java8 will have default implementations for interfaces (virtual extension methods) Java ""
""interface List<T> … {"
"// existing methods, plus""void sort(Comparator<? super T> cmp) "default { "" "Collections.sort(this, cmp); }""}"
//however: no fields, no self types, "//... And therefore ‘no multiple inheritance without the issues’"
Traits ..."//with fields, self types"//... And therefore: ‘multiple inheritance without the issues’"
Scala
![Page 17: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/17.jpg)
Java8 will have support for parallel Collections Java ""
"Set<Album> favs =" albums.parallel()"
" .filter(a -> a.tracks.anyMatch(t -> (t.rating >= 4)))"" .into(new ConcurrentHashSet<>());"
val favs = " albums.par! .filter(a => a.tracks.exists(t => t.rating >= 4)" .toSet" "
Scala
![Page 18: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/18.jpg)
Delivery date Java8 ""
2013 !in JDK 8!
"" "With an impressive track record of many mission critical applications by now ..."
since 2010 !in JDK 1.5, 1.6, 1.7 !
Scala
![Page 19: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/19.jpg)
My Advice:
and enjoy:
![Page 20: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/20.jpg)
def ask(question: Any) = question match {! case "?" => "answer for ?"! case "???" => "answer for ???"! case _ => "42"! }"
![Page 21: Live coding scala 'the java of the future'](https://reader033.fdocuments.net/reader033/viewer/2022052315/556222e4d8b42ac6588b4c7d/html5/thumbnails/21.jpg)
Code samples can be found at:""https://github.com/upeter/Java8vsScalaCodeSamples.git""All rights reserved.""