SlideShare a Scribd company logo
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
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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!
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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!
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
JVM HotSwap is limited to
method bodies.

OSGi is invasive and
state-unaware
so what?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
your managers will love *Rebel
in production
your ops will love *Rebel
in production
That works!
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
That works!
What can be done with Java, but should better be done with Erlang (@pavlobaron)
1> bit_size(<<3:5>>).
5
2>
so what?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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?
What can be done with Java, but should better be done with Erlang (@pavlobaron)
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 (20)

PDF
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
ODP
Getting started with Clojure
John Stevenson
 
PDF
core.logic introduction
Norman Richards
 
ODP
AST Transformations at JFokus
HamletDRC
 
ODP
Clojure made simple - Lightning talk
John Stevenson
 
PPTX
Kotlin – the future of android
DJ Rausch
 
KEY
Google Guava
Alexander Korotkikh
 
PDF
Scala vs java 8
François Sarradin
 
PDF
The Logical Burrito - pattern matching, term rewriting and unification
Norman Richards
 
PDF
Privet Kotlin (Windy City DevFest)
Cody Engel
 
PDF
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 
PPTX
Building native Android applications with Mirah and Pindah
Nick Plante
 
PDF
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
PDF
Fun never stops. introduction to haskell programming language
Pawel Szulc
 
PDF
Clojure, Plain and Simple
Ben Mabey
 
PDF
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
PPTX
Clojure And Swing
Skills Matter
 
PDF
ConFess Vienna 2015 - Metaprogramming with Groovy
Iván López Martín
 
PPSX
Java.lang.object
Soham Sengupta
 
ODP
Clojure: Practical functional approach on JVM
sunng87
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
Getting started with Clojure
John Stevenson
 
core.logic introduction
Norman Richards
 
AST Transformations at JFokus
HamletDRC
 
Clojure made simple - Lightning talk
John Stevenson
 
Kotlin – the future of android
DJ Rausch
 
Google Guava
Alexander Korotkikh
 
Scala vs java 8
François Sarradin
 
The Logical Burrito - pattern matching, term rewriting and unification
Norman Richards
 
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 
Building native Android applications with Mirah and Pindah
Nick Plante
 
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
Fun never stops. introduction to haskell programming language
Pawel Szulc
 
Clojure, Plain and Simple
Ben Mabey
 
From Java to Parellel Clojure - Clojure South 2019
Leonardo Borges
 
Clojure And Swing
Skills Matter
 
ConFess Vienna 2015 - Metaprogramming with Groovy
Iván López Martín
 
Java.lang.object
Soham Sengupta
 
Clojure: Practical functional approach on JVM
sunng87
 

Viewers also liked (20)

PDF
20 reasons why we don't need architects (@pavlobaron)
Pavlo Baron
 
PDF
High Performance Erlang
PerconaPerformance
 
KEY
Winning the Erlang Edit•Build•Test Cycle
Rusty Klophaus
 
PDF
Clojure class
Aysylu Greenberg
 
PDF
Clojure values
Christophe Grand
 
PPTX
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Hakka Labs
 
PDF
Clojure made-simple - John Stevenson
JAX London
 
PDF
Messaging With Erlang And Jabber
l xf
 
PDF
Elixir talk
Cory Gwin
 
PDF
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
PDF
VoltDB and Erlang - Tech planet 2012
Eonblast
 
ZIP
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Howard Lewis Ship
 
ODP
From Perl To Elixir
Ruben Amortegui
 
PDF
Introduction to Erlang for Python Programmers
Python Ireland
 
PDF
Elixir for aspiring Erlang developers
Torben Dohrn
 
PPTX
Erlang - Because S**t Happens
Mahesh Paolini-Subramanya
 
PDF
Clojure: Towards The Essence of Programming
Howard Lewis Ship
 
PDF
Elixir Into Production
Jamie Winsor
 
PPTX
Clojure for Data Science
Mike Anderson
 
KEY
Functional programming in clojure
Juan-Manuel Gimeno
 
20 reasons why we don't need architects (@pavlobaron)
Pavlo Baron
 
High Performance Erlang
PerconaPerformance
 
Winning the Erlang Edit•Build•Test Cycle
Rusty Klophaus
 
Clojure class
Aysylu Greenberg
 
Clojure values
Christophe Grand
 
Erlang - Because s**t Happens by Mahesh Paolini-Subramanya
Hakka Labs
 
Clojure made-simple - John Stevenson
JAX London
 
Messaging With Erlang And Jabber
l xf
 
Elixir talk
Cory Gwin
 
NDC London 2014: Erlang Patterns Matching Business Needs
Torben Hoffmann
 
VoltDB and Erlang - Tech planet 2012
Eonblast
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Howard Lewis Ship
 
From Perl To Elixir
Ruben Amortegui
 
Introduction to Erlang for Python Programmers
Python Ireland
 
Elixir for aspiring Erlang developers
Torben Dohrn
 
Erlang - Because S**t Happens
Mahesh Paolini-Subramanya
 
Clojure: Towards The Essence of Programming
Howard Lewis Ship
 
Elixir Into Production
Jamie Winsor
 
Clojure for Data Science
Mike Anderson
 
Functional programming in clojure
Juan-Manuel Gimeno
 
Ad

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

PDF
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
siouxhotornot
 
PDF
Keynote joearmstrong
Sentifi
 
PDF
Erlang Message Passing Concurrency, For The Win
l xf
 
ODP
erlang at hover.in , Devcamp Blr 09
Bhasker Kode
 
PPTX
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Garth Gilmour
 
PDF
Why Erlang? - Bar Camp Atlanta 2008
boorad
 
PDF
Introduction To Erlang Final
SinarShebl
 
PPTX
Erlang FTW!
Mahesh Paolini-Subramanya
 
PDF
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri
 
PDF
Erlang, the big switch in social games
Wooga
 
PDF
Tour of language landscape (katsconf)
Yan Cui
 
ODP
An introduction to erlang
Mirko Bonadei
 
KEY
Erlang bootstrap course
Martin Logan
 
PDF
Erlang, an overview
Patrick Huesler
 
PDF
FP Days: Down the Clojure Rabbit Hole
Christophe Grand
 
PDF
Java Pitfalls and Good-to-Knows
Miquel Martin
 
PDF
Erlang is not a city in Germany
momo-13
 
PDF
Ice mini guide
Ady Liu
 
KEY
Scala Introduction
Adrian Spender
 
PDF
Martin Odersky: What's next for Scala
Marakana Inc.
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
siouxhotornot
 
Keynote joearmstrong
Sentifi
 
Erlang Message Passing Concurrency, For The Win
l xf
 
erlang at hover.in , Devcamp Blr 09
Bhasker Kode
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Garth Gilmour
 
Why Erlang? - Bar Camp Atlanta 2008
boorad
 
Introduction To Erlang Final
SinarShebl
 
Erlang factory SF 2011 "Erlang and the big switch in social games"
Paolo Negri
 
Erlang, the big switch in social games
Wooga
 
Tour of language landscape (katsconf)
Yan Cui
 
An introduction to erlang
Mirko Bonadei
 
Erlang bootstrap course
Martin Logan
 
Erlang, an overview
Patrick Huesler
 
FP Days: Down the Clojure Rabbit Hole
Christophe Grand
 
Java Pitfalls and Good-to-Knows
Miquel Martin
 
Erlang is not a city in Germany
momo-13
 
Ice mini guide
Ady Liu
 
Scala Introduction
Adrian Spender
 
Martin Odersky: What's next for Scala
Marakana Inc.
 
Ad

More from Pavlo Baron (20)

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

Recently uploaded (20)

PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 

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 [email protected] 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;}});
  • 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
  • 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: } } ...
  • 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>
  • 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}.
  • 46. JVM HotSwap is limited to method bodies. OSGi is invasive and state-unaware
  • 49. your managers will love *Rebel in production
  • 50. your ops will love *Rebel in production
  • 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>
  • 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.
  • 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