SlideShare uma empresa Scribd logo
1 de 50
Baixar para ler offline
Abhijeet Lele
Vladimir Zakharov
Goldman Sachs
21/04/2011
Goals




                 Our Guarantee:
        You won’t become knowledgeable,
           but you will become aware




                                          2
Java




       3
Interview With Josh Bloch

Can you give us an example of code that you are most
proud of creating and explain why?

The Collections framework. It's far from perfect, but it's
proven itself maintainable and pleasant over the years.
Doug Lea built many parts of java.util.concurrent atop it.
And I still get letters from programmers telling me how
much more pleasant it makes their jobs. It lets you write
stuff like this little program, which computes all the
anagrams in the file on standard input.

From “2008 JavaOne Conference - Rock Star Joshua Bloch”
http://java.sun.com/javaone/sf/2008/articles/rockstar_joshuabloch.jsp



                                                                        4
Anagram Algorithm: How It Works




                                  5
Java Example
import java.util.*;
public class Anagram {
  public static void main(String[] args)
  {
    int minGroupSize = Integer.parseInt(args[0]);
    // Read words from input and put into simulated multimap
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    // Print all permutation groups above size threshold
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)
        System.out.println(group.size() + ": " + group);
  }
  private static String alphagram(String s)
  {
    char[] chars = s.toCharArray();
    Arrays.sort(chars);
    return String.valueOf(chars);
  }
}                 From “2008 JavaOne Conference - Rock Star Joshua Bloch”
                 http://java.sun.com/javaone/sf/2008/articles/rockstar_joshuabloch.jsp   6
Java Example With Deluxe Features
import java.util.*;
public class Anagram {
  public static void main(String[] args) {
    int minGroupSize = Integer.parseInt(args[0]);
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);                                            Multimap
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    List<List<String>> winners = new ArrayList<List<String>>();
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)                                                        Filter
        winners.add(group);
    Collections.sort(winners, new Comparator<List<String>>() {
      public int compare(List<String> o1, List<String> o2) {
        return o2.size()-o1.size();                                                            Sort
      }
    });
    for (List<String> winner: winners)
      System.out.println(winner.size() + ": " + winner);
  }
                                                                                               Print

    private static String alphagram(String s) {
      char[] chars = s.toCharArray();
      Arrays.sort(chars);                                                                      Alphagram
      return String.valueOf(chars);
    }
}                     Additional code from “The Java™ Tutorial > Collections”
                      http://download.oracle.com/javase/tutorial/collections/algorithms/index.html         7
Groovy




         8
What is Groovy?
• Definition
   – A lightweight, low-ceremony, dynamic, object-oriented language
   – Open sourced under Apache License, version 2.0
   – “marvelous, wonderful, excellent, hip, trendy.” (Merriam-
     Webster)
• Like Java
   –   Follows Java semantics
   –   Seamlessly integrates with Java
   –   Compiles into Java bytecode
   –   Extends the Java API and libraries
   –   Groovy scripts can be injected into Java
• Not like Java
   –   Dynamic Language
   –   Closures
   –   Properties
   –   Native syntax for lists, maps, and regular expressions
                                                                      9
Groovy: Alphagram
 Java
private static String alphagram(String s) {
  char[] chars = s.toCharArray();
  Arrays.sort(chars);
  return String.valueOf(chars);
}

 Groovy
String.metaClass.alphagram = {
  char[] chars = delegate.toCharArray()
  Arrays.sort(chars)
  return String.valueOf(chars)
}

 Groovy - er
String.metaClass.alphagram = {
  return delegate.toList().sort().join()
}
                                              10
Groovy: Building Multimap
 Java
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
for (Scanner s = new Scanner(System.in); s.hasNext();) {
  String word = s.next();
  String alphagram = alphagram(word);
  List<String> group = anagrams.get(alphagram);
  if (group == null)
    anagrams.put(alphagram, group = new ArrayList<String>());
  group.add(word);
}




 Groovy
anagrams = (new Scanner(System.in)).toList().groupBy {it.alphagram()}




                                                                        11
Groovy: Filtering, Sorting, Printing
 Java
List<List<String>> winners = new ArrayList<List<String>>();
for (List<String> group : anagrams.values())
  if (group.size() >= minGroupSize)
    winners.add(group);
Collections.sort(winners, new Comparator<List<String>>() {
  public int compare(List<String> o1, List<String> o2) {
    return o2.size()-o1.size();
  }
});
for (List<String> winner: winners)
  System.out.println(winner.size() + ": " + winner);

 Groovy
winners = anagrams.values().findAll { it.size > minWordCount }
winners = winners.sort { -it.size }
winners.each { println "${it.size} : $it" }

                                                                 12
Groovy: Putting It All Together
String.metaClass.alphagram = {
  return delegate.toList().sort().join()
}

minWordCount = args[0].toInteger();

(new Scanner(System.in)).toList()
  .groupBy { it.alphagram() }
  .values()
  .findAll { it.size > minWordCount }
  .sort { -it.size }
  .each { println "${it.size} : $it" }




                                           13
Java Reminder
import java.util.*;
public class Anagram {
  public static void main(String[] args) {
    int minGroupSize = Integer.parseInt(args[0]);
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    List<List<String>> winners = new ArrayList<List<String>>();
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)
        winners.add(group);
    Collections.sort(winners, new Comparator<List<String>>() {
      public int compare(List<String> o1, List<String> o2) {        String.metaClass.alphagram = {
        return o2.size()-o1.size();                                   return delegate.toList().sort().join()
      }                                                             }
    });
    for (List<String> winner: winners)                              minWordCount = args[0].toInteger();
      System.out.println(winner.size() + ": " + winner);
  }                                                                 (new Scanner(System.in)).toList()
                                                                      .groupBy { it.alphagram() }
  private static String alphagram(String s) {                         .values()
    char[] chars = s.toCharArray();                                   .findAll { it.size > minWordCount }
    Arrays.sort(chars);                                               .sort { -it.size }
    return String.valueOf(chars);                                     .each { println "${it.size} : $it" }
  }
}

                                                                                                       14
Scala




        15
What is Scala?
• Like Java
   – Bytecode looks very similar to javac output
   – Familiar object-oriented concepts
   – Static types, only better (better type inference, better generics,
     implicit parameters)
   – Performance equivalent to Java
   – Java code can depend on Scala code
• Not like Java
   –   Functional principles
   –   Closures
   –   Everything is an object
   –   No such thing as static
   –   Greatly improved type inference and generics
   –   Traits (mixins)
   –   Pattern Matching

                                                                          16
Scala: Alphagram
 Java
private static String alphagram(String s) {
  char[] chars = s.toCharArray();
  Arrays.sort(chars);
  return String.valueOf(chars);
}


 Scala

word => word.sorted

 Scala With Underbar

_.sorted



                                              17
Scala: Building Multimap
 Java
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
for (Scanner s = new Scanner(System.in); s.hasNext();) {
  String word = s.next();
  String alphagram = alphagram(word);
  List<String> group = anagrams.get(alphagram);
  if (group == null)
    anagrams.put(alphagram, group = new ArrayList<String>());
  group.add(word);
}


 Scala

val map =
  new BufferedReader(new InputStreamReader(System.in))
  .readLine().split(" ").groupBy( _.sorted)



                                                                      18
Scala: Filtering And Sorting
 Java
List<List<String>> winners = new ArrayList<List<String>>();
for (List<String> group : anagrams.values())
  if (group.size() >= minGroupSize)
    winners.add(group);
Collections.sort(winners, new Comparator<List<String>>() {
  public int compare(List<String> o1, List<String> o2) {
    return o2.size()-o1.size();
  }
});


 Scala

val winners = map.values.filter(_.size > Integer.parseInt(args(0))).toList
val sorted = winners.sortBy(-_.size)




                                                                      19
Scala: Printing
 Java
for (List<String> winner: winners)
  System.out.println(winner.size() + ": " + winner);




 Scala

for (winner <- sorted.view)
  println(winner.size + ": " + winner)


 Scala – Another Way

sorted.view.map(list => list.size + ": " + list).foreach(println)




                                                                    20
Scala: Putting It Together
new BufferedReader(new InputStreamReader(System.in))
  .readLine()
  .split(" ")
  .groupBy(_.sorted)
  .values
  .filter(_.length > Integer.parseInt(args(0)))
  .toList
  .sortBy( - _.size )
  .elements
  .foreach(winner => println(winner.size + ": " + winner.toList))




                                                             21
Java Reminder
import java.util.*;
public class Anagram {
  public static void main(String[] args) {
    int minGroupSize = Integer.parseInt(args[0]);
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    List<List<String>> winners = new ArrayList<List<String>>();
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)
        winners.add(group);
    Collections.sort(winners, new Comparator<List<String>>() {
      public int compare(List<String> o1, List<String> o2) {
        return o2.size()-o1.size();
      }                                               new BufferedReader(new InputStreamReader(System.in))
    });                                                  .readLine()
    for (List<String> winner: winners)                   .split(" ")
      System.out.println(winner.size() + ": " + winner); .groupBy(_.sorted)
  }                                                      .values
                                                         .filter(_.length > Integer.parseInt(args(0)))
  private static String alphagram(String s) {            .toList
    char[] chars = s.toCharArray();                      .sortBy( - _.size)
    Arrays.sort(chars);                                  .elements
    return String.valueOf(chars);                        .foreach(
  }                                                       winner => println(winner.size+": "+ winner.toList))
}

                                                                                                       22
Jython




         23
What is Jython?

• Like Java
   – Have access to Java standard libraries and third party libraries
• Not like Java
   – Language is Python; latest release conforms to Python 2.5
   – Dynamically typed
   – Choice of using procedural, object oriented, or functional
     programming constructs, or a mixture of the three
   – Have access to the Python standard libraries and any pure
     Python third party library
• Not like Python
   – No access to compiled Python libraries
   – Some library features are not available (like fork) due to the
     restrictions of the JVM


                                                                        24
Jython: Alphagram
 Java

private static String alphagram(String s) {
  char[] chars = s.toCharArray();
  Arrays.sort(chars);
  return String.valueOf(chars);
}


 Jython
alpha = lambda l : ''.join(sorted(l))




                                              25
Jython: Building Multimap
 Java

Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
for (Scanner s = new Scanner(System.in); s.hasNext();) {
  String word = s.next();
  String alphagram = alphagram(word);
  List<String> group = anagrams.get(alphagram);
  if (group == null)
    anagrams.put(alphagram, group = new ArrayList<String>());
  group.add(word);
}


 Jython

anagrams = [list(g) for k, g in
 itertools.groupby(
   sorted(sys.stdin.readline().split(), key =alpha),
   alpha)]



                                                                      26
Jython: Filtering
 Java
List<List<String>> winners = new ArrayList<List<String>>();
for (List<String> group : anagrams.values())
  if (group.size() >= minGroupSize)
    winners.add(group);




 Jython

winners = (f for f in anagrams if len(f) > int(sys.argv[1]))


                            List comprehension:
          <output> for <variables> in <collection> if <filter>
             {<output>|<variables>       <collection>, <filter>}
                                     э


                                                                   27
Jython: Sorting
 Java
Collections.sort(winners, new Comparator<List<String>>() {
  public int compare(List<String> o1, List<String> o2) {
    return o2.size()-o1.size();
  }
});




 Jython

winners = sorted(winners, key = lambda t: -len(t))




                                                             28
Jython: Printing
 Java
for (List<String> winner: winners)
  System.out.println(winner.size() + ": " + winner);




 Jython

for winner in winners:
   print '%i: %s '%(len(winner), winner)




                                                       29
Jython: Complete Example
import itertools
alpha = lambda l : ''.join(sorted(l))

winners = [
  f for f in
    sorted (
      [list(g) for k, g in
        itertools.groupby(
          sorted(sys.stdin.readline().split(), key = alpha),
          alpha)],
      key = lambda t: -len(t) )
  if(len(f) > int(sys.argv[1]))]

for winner in winners:
   print '%i: %s '%(len(winner), winner)


                                                               30
Java Reminder
import java.util.*;
public class Anagram {
  public static void main(String[] args) {
    int minGroupSize = Integer.parseInt(args[0]);
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    List<List<String>> winners = new ArrayList<List<String>>();
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)                import itertools
        winners.add(group);                            alpha = lambda l : ''.join(sorted(l))
    Collections.sort(winners, new Comparator<List<String>>() {
      public int compare(List<String> o1, List<String> o2) {
                                                       winners = [
        return o2.size()-o1.size();                      f for f in
      }                                                    sorted (
    });                                                      [list(g) for k, g in
    for (List<String> winner: winners)                          itertools.groupby(
      System.out.println(winner.size() + ": " + winner);          sorted(
  }                                                                 sys.stdin.readline().split(),   key=alpha),
                                                                  alpha)],
  private static String alphagram(String s) {                key = lambda t: -len(t) )
    char[] chars = s.toCharArray();                      if(len(f) > int(sys.argv[1]))]
    Arrays.sort(chars);
    return String.valueOf(chars);                      for winner in winners:
  }                                                                 print '%i: %s '%(len(winner),   winner)
}

                                                                                                          31
Jython: A “Simple” Example
import java.util.*;
def sort_string(buf):
     l class Anagram {
public = list(buf)
  public static void main(String[] args) {
     l.sort()
    int minGroupSize = Integer.parseInt(args[0]);
     return ''.join(l)
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
def get_words():
      String word = s.next();
     fp = open('dictionary', 'r')
      String alphagram = alphagram(word);
     words = [ l.strip() for l in fp.readlines() ]
      List<String> group = anagrams.get(alphagram);
     words.sort() null)
      if (group ==
     return words
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
def }
    get_lists_of_size(list_lists, min_size):
    List<List<String>> winners = new ArrayList<List<String>>();
     return [ l for l in list_lists if len(l) >= min_size ]
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)
def main():
        winners.add(group);
     all_anagrams = {}
    Collections.sort(winners, new Comparator<List<String>>() {
     for word int get_words():
      public in compare(List<String> o1, List<String> o2) {
            key = sort_string(word)
        return o2.size()-o1.size();    a
                                    av
            if all_anagrams.has_key(key):
                                 e J ge!
      }

                              rit a
    });                  all_anagrams[key].append(word)
            else:
    for (List<String> winner: winners)
                             w u
                          an lang
      System.out.println(winner.size() + ": " + winner);
                         all_anagrams[key] = [word]
  }
                      u c ny
                    Yo alphagram(String s)8){
      list_lists = all_anagrams.values()
    private static String a
                       in
      winners = get_lists_of_size(anagrams,
      char[] chars = s.toCharArray();
      winners.sort(cmp=lambda x,y: cmp(-len(x), -len(y)))
      Arrays.sort(chars);
      for winner in winners:
      return String.valueOf(chars);
    }         print "%d : %s" % (len(winner), winner)
}

                                                                                32
Clojure




          33
What is Clojure?
• Like Java
   – Not much, really
   – Data structures implement the read-only portion of Collection
   – Functions implement Runnable & Callable
• Not like Java
   –   Dynamic, functional language
   –   Not object-oriented (!)
   –   Persistent, immutable data structures
   –   Lazy sequence abstraction
   –   Software transactional memory
   –   Multimethods and ad-hoc hierarchies
   –   Macros
• Compared to Common Lisp/Scheme
   –   Persistent, immutable data structures
   –   First-class Vectors, Sets, and Maps
   –   Focus on concurrency
   –   No tail call optimization; explicit calls to recur and trampoline required



                                                                                    34
Clojure: Alphagram
 Java

private static String alphagram(String s) {
  char[] chars = s.toCharArray();
  Arrays.sort(chars);
  return String.valueOf(chars);
}


 Clojure

(defn alphagram [word] (apply str (sort word)))

 Clojure anonymous function

(fn [word] (apply str (sort word)))

 Clojure with placeholder syntax

#(apply str (sort %))
                                                  35
Clojure: Multimap
 Java
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
for (Scanner s = new Scanner(System.in); s.hasNext();) {
  String word = s.next();
  String alphagram = alphagram(word);
  List<String> group = anagrams.get(alphagram);
  if (group == null)
    anagrams.put(alphagram, group = new ArrayList<String>());
  group.add(word);
}


 Clojure

(group-by alphagram (iterator-seq (java.util.Scanner. System/in)))

 Clojure with placeholder syntax

(group-by #(apply str (sort %))
  (iterator-seq (java.util.Scanner. System/in)))
                                                                      36
Clojure: Filtering And Sorting
 Java
List<List<String>> winners = new ArrayList<List<String>>();
  for (List<String> group : anagrams.values())
    if (group.size() >= minGroupSize)
      winners.add(group);
Collections.sort(winners, new Comparator<List<String>>() {
  public int compare(List<String> o1, List<String> o2) {
    return o2.size()-o1.size();
  }
});

 Clojure
(def words-in (iterator-seq (java.util.Scanner. System/in)))
(defn select-anagrams [words]
  (sort-by #(- (count %))
    (filter #(> (count %) min-group-size)
      (vals
        (group-by alphagram words)))))
                                                               37
Clojure: Printing
 Java

for (List<String> winner: winners)
  System.out.println(winner.size() + ": " + winner);
}




 Clojure

(doseq [winner (select-anagrams words-in)]
  (println (count winner) ": " winner))




                                                       38
Clojure: Complete Example
 Keeping it functional

(defn alphagram [word] (apply str (sort word)))
(def min-group-size (Integer/valueOf (first *command-line-args*)))
(def words-in (iterator-seq (java.util.Scanner. System/in)))
(defn select-anagrams [words]
  (sort-by #(- (count %))
    (filter #(> (count %) min-group-size)
      (vals
        (group-by alphagram words)))))

(doseq [winner (select-anagrams words-in)]
  (println (count winner) ":" winner))
 Let there be bindings!

(let [alphagram #(apply str (sort %))
      map (group-by alphagram words-in)
      filtered (filter #(> (count %) min-group-size) (vals map))
      winners (sort-by #(- (count %)) filtered)]
  (doseq [winner winners] (println (count winner) ": " winner)))
                                                                     39
Java Reminder
import java.util.*;
public class Anagram {
  public static void main(String[] args) {
    int minGroupSize = Integer.parseInt(args[0]);
    Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
    for (Scanner s = new Scanner(System.in); s.hasNext();) {
      String word = s.next();
      String alphagram = alphagram(word);
      List<String> group = anagrams.get(alphagram);
      if (group == null)
        anagrams.put(alphagram, group = new ArrayList<String>());
      group.add(word);
    }
    List<List<String>> winners = new ArrayList<List<String>>();
    for (List<String> group : anagrams.values())
      if (group.size() >= minGroupSize)
        winners.add(group);
    Collections.sort(winners, new Comparator<List<String>>() {
      public int compare(List<String> o1, List<String> o2) {
        return o2.size()-o1.size();                        (defn alphagram [word] (apply str (sort word)))
      }                                                    (def min-group-size
    });                                                      (Integer/valueOf (first *command-line-args*)))
    for (List<String> winner: winners)                     (def words-in
      System.out.println(winner.size() + ": " + winner);     (iterator-seq (java.util.Scanner. System/in)))
  }                                                        (defn select-anagrams [words]
                                                             (sort-by #(- (count %))
  private static String alphagram(String s) {                   (filter #(> (count %) min-group-size)
    char[] chars = s.toCharArray();                               (vals
    Arrays.sort(chars);                                             (group-by alphagram words)))))
    return String.valueOf(chars);
  }                                                        (doseq [winner (select-anagrams words-in)]
}                                                            (println (count winner) ":" winner))

                                                                                                       40
JRuby




        41
What is JRuby?
• Like Java
   – Have access to Java standard libraries and third party
     libraries
   – Runs in a JVM
• Not like Java
   –   Language is Ruby; latest release conforms to Ruby 1.8.7
   –   Dynamically typed
   –   Can compile to class files
   –   Have access to the Ruby standard libraries and any pure
       Ruby third party library
• Not like Ruby
   – No access to Ruby native-C API
   – No access to Ruby continuations


                                                                 42
JRuby Example: Alphagram
 Java
private static String alphagram(String s) {
  char[] chars = s.toCharArray();
  Arrays.sort(chars);
  return String.valueOf(chars);
}


 JRuby
word.chars.sort.join




                                              43
JRuby: Multimap
 Java
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
for (Scanner s = new Scanner(System.in); s.hasNext();) {
  String word = s.next();
  String alphagram = alphagram(word);
  List<String> group = anagrams.get(alphagram);
  if (group == null)
    anagrams.put(alphagram, group = new ArrayList<String>());
  group.add(word);
}


 JRuby
anagrams = words.group_by { |word| word.chars.sort.join }




                                                                      44
JRuby: Filtering, Sorting, Printing
 Java
List<List<String>> winners = new ArrayList<List<String>>();
for (List<String> group : anagrams.values())
  if (group.size() >= minGroupSize)
    winners.add(group);
Collections.sort(winners, new Comparator<List<String>>() {
  public int compare(List<String> o1, List<String> o2) {
    return o2.size()-o1.size();
  }
});
for (List<String> winner: winners)
  System.out.println(winner.size() + ": " + winner);


 JRuby

filtered = anagrams.values.select {|array| array.length > 4 } winners =
filtered.sort_by { |array| array.length }
winners.each {|each| puts “#{each.size} : #{each.join(‘, ‘)}"}



                                                                      45
JRuby: Complete Example

anagrams = words.group_by {|word| word.chars.sort.join}
filtered = anagrams.values.select {|array| array.length > 4}
winners = filtered.sort_by { |array| array.length }
winners.each {|each| puts “#{each.size} : #{each.join(‘, ‘)}"}




                                                                 46
JRuby: Complete Example – Let’s Make It Better
class String
  def collation
    self.chars.sort.join
  end
end

class Symbol
  def to_proc
    proc { |*args| args[0].send(self, *args[1...args.size]) }
  end
end

module Enumerable

 def partitioned_with(&transformer)
   group_by(&transformer).values
 end

 def longer_than(size)
   self.select {|e| e.length > size}
 end

 def sorted_by_size
   self.sort_by(&:length)
 end

end
                                                                47
JRuby: Better Complete Example

groups = words.partitioned_with(&:collation)
winners = groups.longer_than(4).sorted_by_size
winners.each{|each| puts "#{each.size}: #{each.join(', ')}"}




                                                               48
Takeaways
• JVM provides a robust, industrial strength, scalable
  platform
• You can take advantage of JVM and the rest of the
  Java ecosystem without the complexity of Java the
  language
• Don’t have to wait for Java to adopt the features
  already available in other languages: closures, dynamic
  capabilities, rich, humane interfaces
• Not all languages are enterprise ready
   – These languages are still worth looking into
• Pragmatic Programmer advice:
  Learn a new language every year. When you learn a
  new language, you learn a new way to think.


                                                        49
The End




          50

Mais conteúdo relacionado

Mais procurados

Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Stephen Chin
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageStephen Chin
 
Better Tests, Less Code: Property-based Testing
Better Tests, Less Code: Property-based TestingBetter Tests, Less Code: Property-based Testing
Better Tests, Less Code: Property-based TestingC4Media
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scalaXing
 
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)Stephen Chin
 
JavaFX and Scala - Like Milk and Cookies
JavaFX and Scala - Like Milk and CookiesJavaFX and Scala - Like Milk and Cookies
JavaFX and Scala - Like Milk and CookiesStephen Chin
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212Mahmoud Samir Fayed
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinDmitry Pranchuk
 

Mais procurados (18)

Tuples All the Way Down
Tuples All the Way DownTuples All the Way Down
Tuples All the Way Down
 
Java 7 New Features
Java 7 New FeaturesJava 7 New Features
Java 7 New Features
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
 
Xm lparsers
Xm lparsersXm lparsers
Xm lparsers
 
Better Tests, Less Code: Property-based Testing
Better Tests, Less Code: Property-based TestingBetter Tests, Less Code: Property-based Testing
Better Tests, Less Code: Property-based Testing
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)
Cleaner APIs, Cleaner UIs with Visage (33rd Degrees)
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
JavaFX and Scala - Like Milk and Cookies
JavaFX and Scala - Like Milk and CookiesJavaFX and Scala - Like Milk and Cookies
JavaFX and Scala - Like Milk and Cookies
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 

Semelhante a Java Groovy Scala Anagram Algorithm

1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basicswpgreenway
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Jesper Kamstrup Linnet
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Evolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveEvolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveNaresha K
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersMatthew Farwell
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Ganesh Samarthyam
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...Naresha K
 

Semelhante a Java Groovy Scala Anagram Algorithm (20)

What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Arrays
ArraysArrays
Arrays
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Pattern Matching in Java 14
Pattern Matching in Java 14Pattern Matching in Java 14
Pattern Matching in Java 14
 
Scala
ScalaScala
Scala
 
Collection
CollectionCollection
Collection
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Evolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveEvolving with Java - How to Remain Effective
Evolving with Java - How to Remain Effective
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 

Mais de Saltmarch Media

Concocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for AzureConcocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for AzureSaltmarch Media
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code QualitySaltmarch Media
 
Learning Open Source Business Intelligence
Learning Open Source Business IntelligenceLearning Open Source Business Intelligence
Learning Open Source Business IntelligenceSaltmarch Media
 
Java EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderJava EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderSaltmarch Media
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Saltmarch Media
 
Introduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 DevelopersIntroduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 DevelopersSaltmarch Media
 
Integrated Services for Web Applications
Integrated Services for Web ApplicationsIntegrated Services for Web Applications
Integrated Services for Web ApplicationsSaltmarch Media
 
Gaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No TimeGaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No TimeSaltmarch Media
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentSaltmarch Media
 
JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6Saltmarch Media
 
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise ServicesWF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise ServicesSaltmarch Media
 
“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst PracticesSaltmarch Media
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Saltmarch Media
 
Building Facebook Applications on Windows Azure
Building Facebook Applications on Windows AzureBuilding Facebook Applications on Windows Azure
Building Facebook Applications on Windows AzureSaltmarch Media
 
Architecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkArchitecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkSaltmarch Media
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6Saltmarch Media
 
A Bit of Design Thinking for Developers
A Bit of Design Thinking for DevelopersA Bit of Design Thinking for Developers
A Bit of Design Thinking for DevelopersSaltmarch Media
 

Mais de Saltmarch Media (18)

Concocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for AzureConcocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for Azure
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code Quality
 
Learning Open Source Business Intelligence
Learning Open Source Business IntelligenceLearning Open Source Business Intelligence
Learning Open Source Business Intelligence
 
Java EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderJava EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud Treader
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?
 
Introduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 DevelopersIntroduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 Developers
 
Integrated Services for Web Applications
Integrated Services for Web ApplicationsIntegrated Services for Web Applications
Integrated Services for Web Applications
 
Gaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No TimeGaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No Time
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE Development
 
JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6
 
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise ServicesWF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
 
“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0
 
Building Facebook Applications on Windows Azure
Building Facebook Applications on Windows AzureBuilding Facebook Applications on Windows Azure
Building Facebook Applications on Windows Azure
 
Architecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkArchitecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity Framework
 
Agile Estimation
Agile EstimationAgile Estimation
Agile Estimation
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 
A Bit of Design Thinking for Developers
A Bit of Design Thinking for DevelopersA Bit of Design Thinking for Developers
A Bit of Design Thinking for Developers
 

Último

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 

Último (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 

Java Groovy Scala Anagram Algorithm

  • 2. Goals Our Guarantee: You won’t become knowledgeable, but you will become aware 2
  • 3. Java 3
  • 4. Interview With Josh Bloch Can you give us an example of code that you are most proud of creating and explain why? The Collections framework. It's far from perfect, but it's proven itself maintainable and pleasant over the years. Doug Lea built many parts of java.util.concurrent atop it. And I still get letters from programmers telling me how much more pleasant it makes their jobs. It lets you write stuff like this little program, which computes all the anagrams in the file on standard input. From “2008 JavaOne Conference - Rock Star Joshua Bloch” http://java.sun.com/javaone/sf/2008/articles/rockstar_joshuabloch.jsp 4
  • 6. Java Example import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); // Read words from input and put into simulated multimap Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } // Print all permutation groups above size threshold for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) System.out.println(group.size() + ": " + group); } private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } } From “2008 JavaOne Conference - Rock Star Joshua Bloch” http://java.sun.com/javaone/sf/2008/articles/rockstar_joshuabloch.jsp 6
  • 7. Java Example With Deluxe Features import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); Multimap if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) Filter winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); Sort } }); for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); } Print private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); Alphagram return String.valueOf(chars); } } Additional code from “The Java™ Tutorial > Collections” http://download.oracle.com/javase/tutorial/collections/algorithms/index.html 7
  • 8. Groovy 8
  • 9. What is Groovy? • Definition – A lightweight, low-ceremony, dynamic, object-oriented language – Open sourced under Apache License, version 2.0 – “marvelous, wonderful, excellent, hip, trendy.” (Merriam- Webster) • Like Java – Follows Java semantics – Seamlessly integrates with Java – Compiles into Java bytecode – Extends the Java API and libraries – Groovy scripts can be injected into Java • Not like Java – Dynamic Language – Closures – Properties – Native syntax for lists, maps, and regular expressions 9
  • 10. Groovy: Alphagram Java private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } Groovy String.metaClass.alphagram = { char[] chars = delegate.toCharArray() Arrays.sort(chars) return String.valueOf(chars) } Groovy - er String.metaClass.alphagram = { return delegate.toList().sort().join() } 10
  • 11. Groovy: Building Multimap Java Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } Groovy anagrams = (new Scanner(System.in)).toList().groupBy {it.alphagram()} 11
  • 12. Groovy: Filtering, Sorting, Printing Java List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } }); for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); Groovy winners = anagrams.values().findAll { it.size > minWordCount } winners = winners.sort { -it.size } winners.each { println "${it.size} : $it" } 12
  • 13. Groovy: Putting It All Together String.metaClass.alphagram = { return delegate.toList().sort().join() } minWordCount = args[0].toInteger(); (new Scanner(System.in)).toList() .groupBy { it.alphagram() } .values() .findAll { it.size > minWordCount } .sort { -it.size } .each { println "${it.size} : $it" } 13
  • 14. Java Reminder import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { String.metaClass.alphagram = { return o2.size()-o1.size(); return delegate.toList().sort().join() } } }); for (List<String> winner: winners) minWordCount = args[0].toInteger(); System.out.println(winner.size() + ": " + winner); } (new Scanner(System.in)).toList() .groupBy { it.alphagram() } private static String alphagram(String s) { .values() char[] chars = s.toCharArray(); .findAll { it.size > minWordCount } Arrays.sort(chars); .sort { -it.size } return String.valueOf(chars); .each { println "${it.size} : $it" } } } 14
  • 15. Scala 15
  • 16. What is Scala? • Like Java – Bytecode looks very similar to javac output – Familiar object-oriented concepts – Static types, only better (better type inference, better generics, implicit parameters) – Performance equivalent to Java – Java code can depend on Scala code • Not like Java – Functional principles – Closures – Everything is an object – No such thing as static – Greatly improved type inference and generics – Traits (mixins) – Pattern Matching 16
  • 17. Scala: Alphagram Java private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } Scala word => word.sorted Scala With Underbar _.sorted 17
  • 18. Scala: Building Multimap Java Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } Scala val map = new BufferedReader(new InputStreamReader(System.in)) .readLine().split(" ").groupBy( _.sorted) 18
  • 19. Scala: Filtering And Sorting Java List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } }); Scala val winners = map.values.filter(_.size > Integer.parseInt(args(0))).toList val sorted = winners.sortBy(-_.size) 19
  • 20. Scala: Printing Java for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); Scala for (winner <- sorted.view) println(winner.size + ": " + winner) Scala – Another Way sorted.view.map(list => list.size + ": " + list).foreach(println) 20
  • 21. Scala: Putting It Together new BufferedReader(new InputStreamReader(System.in)) .readLine() .split(" ") .groupBy(_.sorted) .values .filter(_.length > Integer.parseInt(args(0))) .toList .sortBy( - _.size ) .elements .foreach(winner => println(winner.size + ": " + winner.toList)) 21
  • 22. Java Reminder import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } new BufferedReader(new InputStreamReader(System.in)) }); .readLine() for (List<String> winner: winners) .split(" ") System.out.println(winner.size() + ": " + winner); .groupBy(_.sorted) } .values .filter(_.length > Integer.parseInt(args(0))) private static String alphagram(String s) { .toList char[] chars = s.toCharArray(); .sortBy( - _.size) Arrays.sort(chars); .elements return String.valueOf(chars); .foreach( } winner => println(winner.size+": "+ winner.toList)) } 22
  • 23. Jython 23
  • 24. What is Jython? • Like Java – Have access to Java standard libraries and third party libraries • Not like Java – Language is Python; latest release conforms to Python 2.5 – Dynamically typed – Choice of using procedural, object oriented, or functional programming constructs, or a mixture of the three – Have access to the Python standard libraries and any pure Python third party library • Not like Python – No access to compiled Python libraries – Some library features are not available (like fork) due to the restrictions of the JVM 24
  • 25. Jython: Alphagram Java private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } Jython alpha = lambda l : ''.join(sorted(l)) 25
  • 26. Jython: Building Multimap Java Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } Jython anagrams = [list(g) for k, g in itertools.groupby( sorted(sys.stdin.readline().split(), key =alpha), alpha)] 26
  • 27. Jython: Filtering Java List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Jython winners = (f for f in anagrams if len(f) > int(sys.argv[1])) List comprehension: <output> for <variables> in <collection> if <filter> {<output>|<variables> <collection>, <filter>} э 27
  • 28. Jython: Sorting Java Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } }); Jython winners = sorted(winners, key = lambda t: -len(t)) 28
  • 29. Jython: Printing Java for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); Jython for winner in winners: print '%i: %s '%(len(winner), winner) 29
  • 30. Jython: Complete Example import itertools alpha = lambda l : ''.join(sorted(l)) winners = [ f for f in sorted ( [list(g) for k, g in itertools.groupby( sorted(sys.stdin.readline().split(), key = alpha), alpha)], key = lambda t: -len(t) ) if(len(f) > int(sys.argv[1]))] for winner in winners: print '%i: %s '%(len(winner), winner) 30
  • 31. Java Reminder import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) import itertools winners.add(group); alpha = lambda l : ''.join(sorted(l)) Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { winners = [ return o2.size()-o1.size(); f for f in } sorted ( }); [list(g) for k, g in for (List<String> winner: winners) itertools.groupby( System.out.println(winner.size() + ": " + winner); sorted( } sys.stdin.readline().split(), key=alpha), alpha)], private static String alphagram(String s) { key = lambda t: -len(t) ) char[] chars = s.toCharArray(); if(len(f) > int(sys.argv[1]))] Arrays.sort(chars); return String.valueOf(chars); for winner in winners: } print '%i: %s '%(len(winner), winner) } 31
  • 32. Jython: A “Simple” Example import java.util.*; def sort_string(buf): l class Anagram { public = list(buf) public static void main(String[] args) { l.sort() int minGroupSize = Integer.parseInt(args[0]); return ''.join(l) Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { def get_words(): String word = s.next(); fp = open('dictionary', 'r') String alphagram = alphagram(word); words = [ l.strip() for l in fp.readlines() ] List<String> group = anagrams.get(alphagram); words.sort() null) if (group == return words anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); def } get_lists_of_size(list_lists, min_size): List<List<String>> winners = new ArrayList<List<String>>(); return [ l for l in list_lists if len(l) >= min_size ] for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) def main(): winners.add(group); all_anagrams = {} Collections.sort(winners, new Comparator<List<String>>() { for word int get_words(): public in compare(List<String> o1, List<String> o2) { key = sort_string(word) return o2.size()-o1.size(); a av if all_anagrams.has_key(key): e J ge! } rit a }); all_anagrams[key].append(word) else: for (List<String> winner: winners) w u an lang System.out.println(winner.size() + ": " + winner); all_anagrams[key] = [word] } u c ny Yo alphagram(String s)8){ list_lists = all_anagrams.values() private static String a in winners = get_lists_of_size(anagrams, char[] chars = s.toCharArray(); winners.sort(cmp=lambda x,y: cmp(-len(x), -len(y))) Arrays.sort(chars); for winner in winners: return String.valueOf(chars); } print "%d : %s" % (len(winner), winner) } 32
  • 33. Clojure 33
  • 34. What is Clojure? • Like Java – Not much, really – Data structures implement the read-only portion of Collection – Functions implement Runnable & Callable • Not like Java – Dynamic, functional language – Not object-oriented (!) – Persistent, immutable data structures – Lazy sequence abstraction – Software transactional memory – Multimethods and ad-hoc hierarchies – Macros • Compared to Common Lisp/Scheme – Persistent, immutable data structures – First-class Vectors, Sets, and Maps – Focus on concurrency – No tail call optimization; explicit calls to recur and trampoline required 34
  • 35. Clojure: Alphagram Java private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } Clojure (defn alphagram [word] (apply str (sort word))) Clojure anonymous function (fn [word] (apply str (sort word))) Clojure with placeholder syntax #(apply str (sort %)) 35
  • 36. Clojure: Multimap Java Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } Clojure (group-by alphagram (iterator-seq (java.util.Scanner. System/in))) Clojure with placeholder syntax (group-by #(apply str (sort %)) (iterator-seq (java.util.Scanner. System/in))) 36
  • 37. Clojure: Filtering And Sorting Java List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } }); Clojure (def words-in (iterator-seq (java.util.Scanner. System/in))) (defn select-anagrams [words] (sort-by #(- (count %)) (filter #(> (count %) min-group-size) (vals (group-by alphagram words))))) 37
  • 38. Clojure: Printing Java for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); } Clojure (doseq [winner (select-anagrams words-in)] (println (count winner) ": " winner)) 38
  • 39. Clojure: Complete Example Keeping it functional (defn alphagram [word] (apply str (sort word))) (def min-group-size (Integer/valueOf (first *command-line-args*))) (def words-in (iterator-seq (java.util.Scanner. System/in))) (defn select-anagrams [words] (sort-by #(- (count %)) (filter #(> (count %) min-group-size) (vals (group-by alphagram words))))) (doseq [winner (select-anagrams words-in)] (println (count winner) ":" winner)) Let there be bindings! (let [alphagram #(apply str (sort %)) map (group-by alphagram words-in) filtered (filter #(> (count %) min-group-size) (vals map)) winners (sort-by #(- (count %)) filtered)] (doseq [winner winners] (println (count winner) ": " winner))) 39
  • 40. Java Reminder import java.util.*; public class Anagram { public static void main(String[] args) { int minGroupSize = Integer.parseInt(args[0]); Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); (defn alphagram [word] (apply str (sort word))) } (def min-group-size }); (Integer/valueOf (first *command-line-args*))) for (List<String> winner: winners) (def words-in System.out.println(winner.size() + ": " + winner); (iterator-seq (java.util.Scanner. System/in))) } (defn select-anagrams [words] (sort-by #(- (count %)) private static String alphagram(String s) { (filter #(> (count %) min-group-size) char[] chars = s.toCharArray(); (vals Arrays.sort(chars); (group-by alphagram words))))) return String.valueOf(chars); } (doseq [winner (select-anagrams words-in)] } (println (count winner) ":" winner)) 40
  • 41. JRuby 41
  • 42. What is JRuby? • Like Java – Have access to Java standard libraries and third party libraries – Runs in a JVM • Not like Java – Language is Ruby; latest release conforms to Ruby 1.8.7 – Dynamically typed – Can compile to class files – Have access to the Ruby standard libraries and any pure Ruby third party library • Not like Ruby – No access to Ruby native-C API – No access to Ruby continuations 42
  • 43. JRuby Example: Alphagram Java private static String alphagram(String s) { char[] chars = s.toCharArray(); Arrays.sort(chars); return String.valueOf(chars); } JRuby word.chars.sort.join 43
  • 44. JRuby: Multimap Java Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); for (Scanner s = new Scanner(System.in); s.hasNext();) { String word = s.next(); String alphagram = alphagram(word); List<String> group = anagrams.get(alphagram); if (group == null) anagrams.put(alphagram, group = new ArrayList<String>()); group.add(word); } JRuby anagrams = words.group_by { |word| word.chars.sort.join } 44
  • 45. JRuby: Filtering, Sorting, Printing Java List<List<String>> winners = new ArrayList<List<String>>(); for (List<String> group : anagrams.values()) if (group.size() >= minGroupSize) winners.add(group); Collections.sort(winners, new Comparator<List<String>>() { public int compare(List<String> o1, List<String> o2) { return o2.size()-o1.size(); } }); for (List<String> winner: winners) System.out.println(winner.size() + ": " + winner); JRuby filtered = anagrams.values.select {|array| array.length > 4 } winners = filtered.sort_by { |array| array.length } winners.each {|each| puts “#{each.size} : #{each.join(‘, ‘)}"} 45
  • 46. JRuby: Complete Example anagrams = words.group_by {|word| word.chars.sort.join} filtered = anagrams.values.select {|array| array.length > 4} winners = filtered.sort_by { |array| array.length } winners.each {|each| puts “#{each.size} : #{each.join(‘, ‘)}"} 46
  • 47. JRuby: Complete Example – Let’s Make It Better class String def collation self.chars.sort.join end end class Symbol def to_proc proc { |*args| args[0].send(self, *args[1...args.size]) } end end module Enumerable def partitioned_with(&transformer) group_by(&transformer).values end def longer_than(size) self.select {|e| e.length > size} end def sorted_by_size self.sort_by(&:length) end end 47
  • 48. JRuby: Better Complete Example groups = words.partitioned_with(&:collation) winners = groups.longer_than(4).sorted_by_size winners.each{|each| puts "#{each.size}: #{each.join(', ')}"} 48
  • 49. Takeaways • JVM provides a robust, industrial strength, scalable platform • You can take advantage of JVM and the rest of the Java ecosystem without the complexity of Java the language • Don’t have to wait for Java to adopt the features already available in other languages: closures, dynamic capabilities, rich, humane interfaces • Not all languages are enterprise ready – These languages are still worth looking into • Pragmatic Programmer advice: Learn a new language every year. When you learn a new language, you learn a new way to think. 49
  • 50. The End 50