SlideShare a Scribd company logo
1 of 90
What can be done with

Java



but should better be done with


Erlang
Pavlo Baron
            Geek‘s
             Guide    pavlo.baron@codecentric.de
To The Working Life                @pavlobaron
Hey, dude.

What sort of application
should be optimally implemented
using your language?
.NET dude:




         win*
Python dude:




          sci*
Ruby dude:




       cool*
Clojure, Groovy, Scala dude:




        java*
Putonghua dude:




         谢谢
Java dude:




             *
Erlang dude:




fit → do();

_ → badarg.
This dude in front of you

is   very     picky.
So, let' assume that:




                =

                =
List<Integer> l =
    Arrays.asList(1, 2, 3, 4, 5);
List<Integer> r =
    new ArrayList<Integer>();
    for (int i : l) {
      r.add(i * 2);
    }
List<Integer> l =
  Arrays.asList(1, 2, 3, 4, 5);
Iterable<Integer> t =
  Iterables.transform(l,
    new Function<Integer, Integer>() {
      public Integer apply(Integer i) {
        return I * 2;
      }
    });
And this is just a simple map.
It gets even worse
with filter and fold
[X * 2 || X <- lists:seq(1, 5)].
so what?
List<Integer> l = Arrays.asList(1, 2, 3, 4, 5); Iterable<Integer> t = Iterables.transform(l, new Function<Integer, Integer>() {public Integer apply(Integer i) {return I * 2;}});
your colleagues will love it
That works!
synchronized (this) {
   if (!crawledSites.contains(site)) {
         linkedSites.add(site);
   }
 }

…

public class CountingSemaphore {
   private int signals = 0;
   public synchronized void take() {
        this.signals++;
        this.notify();
   }

    public synchronized void release()
                        throws InterruptedException {
       while (this.signals == 0) wait();
       this.signals--;
    }
}
1> A = 5.
5
2> A = 10.
** exception error: no match of
right hand side value 10
3>
so what?
The simplest way to avoid problems
with concurrency is to share only
immutable data between threads.
Immutable data is data which can
not be changed.

(from a Java concurrency tutorial)
Immutable class:

- all its fields are final
- class declared as final
- “this” reference is not allowed to
escape during construction
Any fields which refer to
mutable data objects:

- are private
- have no setter method
- are never directly returned of
otherwise exposed to a caller
- if they are changed internally
in the class this change is not
visible and has no effect
outside of the class
That works!
1> F = fun(F) -> F(F) end.
#Fun<erl_eval.6.80247286>
2> F(F).

…..................hours later................

BREAK: (a)bort (c)ontinue (p)roc info
(i)nfo (l)oaded (v)ersion (k)ill (D)b-tables
(d)istribution

a
so what?
...
for (paramFiber = recursion1.doit__1(paramEProc, paramEObject);
          paramFiber == EProc.TAIL_MARKER;
          paramFiber = (EFun)localFiber.getCallee())
     {
       S_O localS_O;
       switch (localFiber.up())
       {
       case 2:
         paramEProc.tail.go(paramEProc, localFiber.down());
         localS_O = new S_O();
         localS_O.f0 = paramEProc;
         localFiber.setState(localS_O, this, 1);
         return null;
       case 3:
         null;
         return null;
       case 1:
         localS_O = (S_O)localFiber.curState;
         paramEProc = (EProc)localS_O.f0;
       case 0:
       }
     }
...
That works!
1> F = fun([_|_]) ->
1> io:format("string~n");
1> (B) ->
1> io:format("integer~n")
1> end.
#Fun<erl_eval.6.80247286>
2> F(15).
integer
ok
3> F("whatever").
string
ok
4>
so what?
That works!
try {
   // Create a new class loader with the directory
   ClassLoader cl = new URLClassLoader(urls);

  // Load in the class
  Class cls = cl.loadClass("MyReloadableClassImpl");

   // Create a new instance of the new class
   myObj = (MyReloadableClass)cls.newInstance();
} catch (IllegalAccessException e) {
} catch (InstantiationException e) {
} catch (ClassNotFoundException e) {
}
Excessive class-reloading using
ClassLoader hierarchies is
expensive and leads to JVM
instance fatigue
That's why it's strongly
recommended to do hot
deployment in app servers
% hot_swap:sum(Num)
% adds 1 to Num
1> c(hot_swap).
{ok,hot_swap}
2> hot_swap:sum(1).
2
...
% hot_swap.erl has changed.
% now it adds 2 to Num
…
3> c(hot_swap).
{ok,hot_swap}
4> hot_swap:sum(1).
3
5>
code_change(OldVsn, State, Extra) ->
  ...code to convert state (and more) during
  code change...
  {ok, NewState}.
so what?
JVM HotSwap is limited to
method bodies.

OSGi is invasive and
state-unaware
so what?
your managers will love *Rebel
in production
your ops will love *Rebel
in production
That works!
1> A = 20.
20
2> self().
<0.32.0>
3> 5 / 0.
** exception error: bad argument in an
arithmetic expression
    in operator '/'/2
      called as 5 / 0
4> self().
<0.36.0>
5> A.
20
6>
so what?
That works!
1> bit_size(<<3:5>>).
5
2>
so what?
That works!
QueueConnectionFactory connFactory =
   new QueueConnectionFactory();
QueueConnection conn = connFactory.createQueueConnection();
QueueSession session = conn.createQueueSession(false,
   Session.AUTO_ACKNOWLEDGE);
Queue q = new Queue("world");
QueueSender sender = session.createSender(q);
TextMessage msg = session.createTextMessage();
msg.setText("Hello there!");
sender.send(msg);

QueueReceiver receiver = session.createReceiver(q);
conn.start();
Message m = receiver.receive();
if (m instanceof TextMessage) {
     TextMessage txt = (TextMessage) m;
}

session.close();
conn.close();
register(serv, spawn(?MODULE, loop, [])),
serv ! {self(), “Hello there!”},
receive
  {_Pid, Msg} ->
  …
end.

…

loop() ->
   receive
     {From, Txt} ->
        …
        loop();
$ erl +P 134217727

Erlang R14B04 (erts-5.8.5) [source] [64-bit]
[smp:8:8] [rq:8] [async-threads:0] [hipe]
[kernel-poll:false]

Eshell V5.8.5 (abort with ^G)
1> erlang:system_info(process_limit).
134217727
2>
so what?
import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;

public class SimpleTask extends Task {
  static Mailbox<String> mb = new Mailbox<String>();

    public static void main(String[] args) throws Exception {
      new SimpleTask().start();
      Thread.sleep(10);
      mb.putnb("Hello ");
      mb.putnb("Worldn");
      mb.putnb("done");
    }

    public void execute() throws Pausable {
      while (true) {
         String s = mb.get();
         if (s.equals("done")) break;
         System.out.print(s);
      }
      System.exit(0);
    }
}
your ops will love this
in production
That works!
QueueConnectionFactory connFactory =
   new QueueConnectionFactory();
QueueConnection conn = connFactory.createQueueConnection();
QueueSession session = conn.createQueueSession(false,
   Session.AUTO_ACKNOWLEDGE);
Queue q = new Queue("world");
QueueSender sender = session.createSender(q);
TextMessage msg = session.createTextMessage();
msg.setText("Hello there!");
sender.send(msg);

QueueReceiver receiver = session.createReceiver(q);
conn.start();
Message m = receiver.receive();
if (m instanceof TextMessage) {
     TextMessage txt = (TextMessage) m;
}

session.close();
conn.close();
{serv, 'serv@pc'} ! {self(), “Hello there!”},
receive
  {_Pid, Msg} ->
  …
end.

…

loop() ->
   receive
     {From, Txt} ->
        …
        loop();
so what?
import org.gridgain.grid.*;
import org.gridgain.grid.gridify.*;
import org.gridgain.grid.gridify.aop.spring.*;

public final class GridifyHelloWorldSessionExample {
  private GridifyHelloWorldSessionExample() { //ensure singleton }

     @Gridify(taskClass = GridifyHelloWorldSessionTask.class, timeout = 3000)
     public static int sayIt(String phrase) {
       System.out.println(phrase);
       return phrase.length();
     }
    public static void main(String[] args) throws GridException {
       if (args.length == 0) {
              GridFactory.start();
       }
       else {
              GridFactory.start(args[0]);
       }
       try {
              int phraseLen = sayIt("Hello World");
              System.out.println(„number of characters is '" + phraseLen + "'.");
       } finally {
              GridFactory.stop(true);
       }
     }
}
your ops will love this
in production
That works!
One GC per OS process.
Complex generation management.
Different GC stategies.
Stop the world situations possible
One GC per Erlang process.
Simple generation management.
(Mostly) one GC stategy.
Stop the world situations unlikely.
so what?
That works!
Hey, dude.

So do you imply Erlang is better
than Java for everything?
Erlang dude:



  body() -> [
     #h1 { text="My Simple Application" },
     #label { text="What is your name?" },
     #textbox { },
     #button { text="Submit" }
  ].
Java dude:

             LOL
              at
             you
Ruby on rails dude:

            ROFL
              at
             y'all
Erlang dude:



calc_month(S) ->
   L = ["Jan", "Feb", "Mar", "Apr", "May",
        "Jun", "Jul", "Aug", "Sep", "Oct",
        "Nov", "Dec"],
   find_ix(L, S, 1).
Java dude:

             LOL
              at
             you
Erlang dude:



Doing number crunching, you would
completely utilize the available cores with
few (as many) threads.

Erlang is for time sharing and doesn't
like long blocking processes.
Java dude:

             LOL
              at
             you
C dude:

          ROFL
            at
           y'all
Thank you
Some code examples were
   taken from public blogs / sites

      Most images originate from
               istockphoto.com

            except few ones taken
from Wikipedia and product pages
      or generated through public
                online generators

More Related Content

What's hot

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
HamletDRC
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unification
Norman Richards
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 

What's hot (20)

JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
core.logic introduction
core.logic introductioncore.logic introduction
core.logic introduction
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unification
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Spock: A Highly Logical Way To Test
Spock: A Highly Logical Way To TestSpock: A Highly Logical Way To Test
Spock: A Highly Logical Way To Test
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 

Viewers also liked

Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
l xf
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
Eonblast
 

Viewers also liked (20)

20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)20 reasons why we don't need architects (@pavlobaron)
20 reasons why we don't need architects (@pavlobaron)
 
High Performance Erlang
High  Performance  ErlangHigh  Performance  Erlang
High Performance Erlang
 
Winning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleWinning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test Cycle
 
Clojure class
Clojure classClojure class
Clojure class
 
Clojure values
Clojure valuesClojure values
Clojure values
 
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-SubramanyaErlang - Because s**t Happens by Mahesh Paolini-Subramanya
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
Elixir talk
Elixir talkElixir talk
Elixir talk
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 
From Perl To Elixir
From Perl To ElixirFrom Perl To Elixir
From Perl To Elixir
 
Introduction to Erlang for Python Programmers
Introduction to Erlang for Python ProgrammersIntroduction to Erlang for Python Programmers
Introduction to Erlang for Python Programmers
 
Elixir for aspiring Erlang developers
Elixir for aspiring Erlang developersElixir for aspiring Erlang developers
Elixir for aspiring Erlang developers
 
Erlang - Because S**t Happens
Erlang - Because S**t HappensErlang - Because S**t Happens
Erlang - Because S**t Happens
 
Clojure: Towards The Essence of Programming
Clojure: Towards The Essence of ProgrammingClojure: Towards The Essence of Programming
Clojure: Towards The Essence of Programming
 
Elixir Into Production
Elixir Into ProductionElixir Into Production
Elixir Into Production
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 

Similar to What can be done with Java, but should better be done with Erlang (@pavlobaron)

Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Similar to What can be done with Java, but should better be done with Erlang (@pavlobaron) (20)

Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Java
JavaJava
Java
 

More from Pavlo Baron

More from Pavlo Baron (20)

@pavlobaron Why monitoring sucks and how to improve it
@pavlobaron Why monitoring sucks and how to improve it@pavlobaron Why monitoring sucks and how to improve it
@pavlobaron Why monitoring sucks and how to improve it
 
Why we do tech the way we do tech now (@pavlobaron)
Why we do tech the way we do tech now (@pavlobaron)Why we do tech the way we do tech now (@pavlobaron)
Why we do tech the way we do tech now (@pavlobaron)
 
Qcon2015 living database
Qcon2015 living databaseQcon2015 living database
Qcon2015 living database
 
Becoming reactive without overreacting (@pavlobaron)
Becoming reactive without overreacting (@pavlobaron)Becoming reactive without overreacting (@pavlobaron)
Becoming reactive without overreacting (@pavlobaron)
 
The hidden costs of the parallel world (@pavlobaron)
The hidden costs of the parallel world (@pavlobaron)The hidden costs of the parallel world (@pavlobaron)
The hidden costs of the parallel world (@pavlobaron)
 
data, ..., profit (@pavlobaron)
data, ..., profit (@pavlobaron)data, ..., profit (@pavlobaron)
data, ..., profit (@pavlobaron)
 
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
Data on its way to history, interrupted by analytics and silicon (@pavlobaron)
 
(Functional) reactive programming (@pavlobaron)
(Functional) reactive programming (@pavlobaron)(Functional) reactive programming (@pavlobaron)
(Functional) reactive programming (@pavlobaron)
 
Near realtime analytics - technology choice (@pavlobaron)
Near realtime analytics - technology choice (@pavlobaron)Near realtime analytics - technology choice (@pavlobaron)
Near realtime analytics - technology choice (@pavlobaron)
 
Set this Big Data technology zoo in order (@pavlobaron)
Set this Big Data technology zoo in order (@pavlobaron)Set this Big Data technology zoo in order (@pavlobaron)
Set this Big Data technology zoo in order (@pavlobaron)
 
a Tech guy’s take on Big Data business cases (@pavlobaron)
a Tech guy’s take on Big Data business cases (@pavlobaron)a Tech guy’s take on Big Data business cases (@pavlobaron)
a Tech guy’s take on Big Data business cases (@pavlobaron)
 
Diving into Erlang is a one-way ticket (@pavlobaron)
Diving into Erlang is a one-way ticket (@pavlobaron)Diving into Erlang is a one-way ticket (@pavlobaron)
Diving into Erlang is a one-way ticket (@pavlobaron)
 
Dynamo concepts in depth (@pavlobaron)
Dynamo concepts in depth (@pavlobaron)Dynamo concepts in depth (@pavlobaron)
Dynamo concepts in depth (@pavlobaron)
 
Chef's Coffee - provisioning Java applications with Chef (@pavlobaron)
Chef's Coffee - provisioning Java applications with Chef (@pavlobaron)Chef's Coffee - provisioning Java applications with Chef (@pavlobaron)
Chef's Coffee - provisioning Java applications with Chef (@pavlobaron)
 
From Hand To Mouth (@pavlobaron)
From Hand To Mouth (@pavlobaron)From Hand To Mouth (@pavlobaron)
From Hand To Mouth (@pavlobaron)
 
The Big Data Developer (@pavlobaron)
The Big Data Developer (@pavlobaron)The Big Data Developer (@pavlobaron)
The Big Data Developer (@pavlobaron)
 
NoSQL - how it works (@pavlobaron)
NoSQL - how it works (@pavlobaron)NoSQL - how it works (@pavlobaron)
NoSQL - how it works (@pavlobaron)
 
Theoretical aspects of distributed systems - playfully illustrated (@pavlobaron)
Theoretical aspects of distributed systems - playfully illustrated (@pavlobaron)Theoretical aspects of distributed systems - playfully illustrated (@pavlobaron)
Theoretical aspects of distributed systems - playfully illustrated (@pavlobaron)
 
The Agile Alibi (Pavlo Baron)
The Agile Alibi (Pavlo Baron)The Agile Alibi (Pavlo Baron)
The Agile Alibi (Pavlo Baron)
 
Harry Potter and Enormous Data (Pavlo Baron)
Harry Potter and Enormous Data (Pavlo Baron)Harry Potter and Enormous Data (Pavlo Baron)
Harry Potter and Enormous Data (Pavlo Baron)
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

What can be done with Java, but should better be done with Erlang (@pavlobaron)

  • 1. What can be done with Java but should better be done with Erlang
  • 2. Pavlo Baron Geek‘s Guide pavlo.baron@codecentric.de To The Working Life @pavlobaron
  • 3. Hey, dude. What sort of application should be optimally implemented using your language?
  • 4. .NET dude: win*
  • 6. Ruby dude: cool*
  • 10. Erlang dude: fit → do(); _ → badarg.
  • 11. This dude in front of you is very picky.
  • 12. So, let' assume that: = =
  • 13. List<Integer> l = Arrays.asList(1, 2, 3, 4, 5); List<Integer> r = new ArrayList<Integer>(); for (int i : l) { r.add(i * 2); }
  • 14. List<Integer> l = Arrays.asList(1, 2, 3, 4, 5); Iterable<Integer> t = Iterables.transform(l, new Function<Integer, Integer>() { public Integer apply(Integer i) { return I * 2; } });
  • 15. And this is just a simple map. It gets even worse with filter and fold
  • 16. [X * 2 || X <- lists:seq(1, 5)].
  • 18. List<Integer> l = Arrays.asList(1, 2, 3, 4, 5); Iterable<Integer> t = Iterables.transform(l, new Function<Integer, Integer>() {public Integer apply(Integer i) {return I * 2;}});
  • 20.
  • 22. synchronized (this) { if (!crawledSites.contains(site)) { linkedSites.add(site); } } … public class CountingSemaphore { private int signals = 0; public synchronized void take() { this.signals++; this.notify(); } public synchronized void release() throws InterruptedException { while (this.signals == 0) wait(); this.signals--; } }
  • 23. 1> A = 5. 5 2> A = 10. ** exception error: no match of right hand side value 10 3>
  • 25. The simplest way to avoid problems with concurrency is to share only immutable data between threads. Immutable data is data which can not be changed. (from a Java concurrency tutorial)
  • 26. Immutable class: - all its fields are final - class declared as final - “this” reference is not allowed to escape during construction
  • 27. Any fields which refer to mutable data objects: - are private - have no setter method - are never directly returned of otherwise exposed to a caller - if they are changed internally in the class this change is not visible and has no effect outside of the class
  • 29.
  • 30. 1> F = fun(F) -> F(F) end. #Fun<erl_eval.6.80247286> 2> F(F). …..................hours later................ BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution a
  • 32. ... for (paramFiber = recursion1.doit__1(paramEProc, paramEObject); paramFiber == EProc.TAIL_MARKER; paramFiber = (EFun)localFiber.getCallee()) { S_O localS_O; switch (localFiber.up()) { case 2: paramEProc.tail.go(paramEProc, localFiber.down()); localS_O = new S_O(); localS_O.f0 = paramEProc; localFiber.setState(localS_O, this, 1); return null; case 3: null; return null; case 1: localS_O = (S_O)localFiber.curState; paramEProc = (EProc)localS_O.f0; case 0: } } ...
  • 34.
  • 35. 1> F = fun([_|_]) -> 1> io:format("string~n"); 1> (B) -> 1> io:format("integer~n") 1> end. #Fun<erl_eval.6.80247286> 2> F(15). integer ok 3> F("whatever"). string ok 4>
  • 37.
  • 39. try { // Create a new class loader with the directory ClassLoader cl = new URLClassLoader(urls); // Load in the class Class cls = cl.loadClass("MyReloadableClassImpl"); // Create a new instance of the new class myObj = (MyReloadableClass)cls.newInstance(); } catch (IllegalAccessException e) { } catch (InstantiationException e) { } catch (ClassNotFoundException e) { }
  • 40. Excessive class-reloading using ClassLoader hierarchies is expensive and leads to JVM instance fatigue
  • 41. That's why it's strongly recommended to do hot deployment in app servers
  • 42. % hot_swap:sum(Num) % adds 1 to Num 1> c(hot_swap). {ok,hot_swap} 2> hot_swap:sum(1). 2 ... % hot_swap.erl has changed. % now it adds 2 to Num … 3> c(hot_swap). {ok,hot_swap} 4> hot_swap:sum(1). 3 5>
  • 43. code_change(OldVsn, State, Extra) -> ...code to convert state (and more) during code change... {ok, NewState}.
  • 45.
  • 46. JVM HotSwap is limited to method bodies. OSGi is invasive and state-unaware
  • 48.
  • 49. your managers will love *Rebel in production
  • 50. your ops will love *Rebel in production
  • 52.
  • 53. 1> A = 20. 20 2> self(). <0.32.0> 3> 5 / 0. ** exception error: bad argument in an arithmetic expression in operator '/'/2 called as 5 / 0 4> self(). <0.36.0> 5> A. 20 6>
  • 55.
  • 57.
  • 60.
  • 62. QueueConnectionFactory connFactory = new QueueConnectionFactory(); QueueConnection conn = connFactory.createQueueConnection(); QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = new Queue("world"); QueueSender sender = session.createSender(q); TextMessage msg = session.createTextMessage(); msg.setText("Hello there!"); sender.send(msg); QueueReceiver receiver = session.createReceiver(q); conn.start(); Message m = receiver.receive(); if (m instanceof TextMessage) { TextMessage txt = (TextMessage) m; } session.close(); conn.close();
  • 63. register(serv, spawn(?MODULE, loop, [])), serv ! {self(), “Hello there!”}, receive {_Pid, Msg} -> … end. … loop() -> receive {From, Txt} -> … loop();
  • 64. $ erl +P 134217727 Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:8:8] [rq:8] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) 1> erlang:system_info(process_limit). 134217727 2>
  • 66. import kilim.Mailbox; import kilim.Pausable; import kilim.Task; public class SimpleTask extends Task { static Mailbox<String> mb = new Mailbox<String>(); public static void main(String[] args) throws Exception { new SimpleTask().start(); Thread.sleep(10); mb.putnb("Hello "); mb.putnb("Worldn"); mb.putnb("done"); } public void execute() throws Pausable { while (true) { String s = mb.get(); if (s.equals("done")) break; System.out.print(s); } System.exit(0); } }
  • 67. your ops will love this in production
  • 69. QueueConnectionFactory connFactory = new QueueConnectionFactory(); QueueConnection conn = connFactory.createQueueConnection(); QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = new Queue("world"); QueueSender sender = session.createSender(q); TextMessage msg = session.createTextMessage(); msg.setText("Hello there!"); sender.send(msg); QueueReceiver receiver = session.createReceiver(q); conn.start(); Message m = receiver.receive(); if (m instanceof TextMessage) { TextMessage txt = (TextMessage) m; } session.close(); conn.close();
  • 70. {serv, 'serv@pc'} ! {self(), “Hello there!”}, receive {_Pid, Msg} -> … end. … loop() -> receive {From, Txt} -> … loop();
  • 72. import org.gridgain.grid.*; import org.gridgain.grid.gridify.*; import org.gridgain.grid.gridify.aop.spring.*; public final class GridifyHelloWorldSessionExample { private GridifyHelloWorldSessionExample() { //ensure singleton } @Gridify(taskClass = GridifyHelloWorldSessionTask.class, timeout = 3000) public static int sayIt(String phrase) { System.out.println(phrase); return phrase.length(); } public static void main(String[] args) throws GridException { if (args.length == 0) { GridFactory.start(); } else { GridFactory.start(args[0]); } try { int phraseLen = sayIt("Hello World"); System.out.println(„number of characters is '" + phraseLen + "'."); } finally { GridFactory.stop(true); } } }
  • 73. your ops will love this in production
  • 75. One GC per OS process. Complex generation management. Different GC stategies. Stop the world situations possible
  • 76. One GC per Erlang process. Simple generation management. (Mostly) one GC stategy. Stop the world situations unlikely.
  • 78.
  • 80. Hey, dude. So do you imply Erlang is better than Java for everything?
  • 81. Erlang dude: body() -> [ #h1 { text="My Simple Application" }, #label { text="What is your name?" }, #textbox { }, #button { text="Submit" } ].
  • 82. Java dude: LOL at you
  • 83. Ruby on rails dude: ROFL at y'all
  • 84. Erlang dude: calc_month(S) -> L = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], find_ix(L, S, 1).
  • 85. Java dude: LOL at you
  • 86. Erlang dude: Doing number crunching, you would completely utilize the available cores with few (as many) threads. Erlang is for time sharing and doesn't like long blocking processes.
  • 87. Java dude: LOL at you
  • 88. C dude: ROFL at y'all
  • 90. Some code examples were taken from public blogs / sites Most images originate from istockphoto.com except few ones taken from Wikipedia and product pages or generated through public online generators