SlideShare a Scribd company logo
1 of 33
The Well-Grounded Java Developer

Polyglot & Functional Programming
This is still not an Oracle legal slide




                                  2
Why Polyglot & Functional?
• The WGJD wants to code rapidly


• The WGJD wants to code concisely


• The WGJD wants to take advantage of:
   - The JVM
   - Non Object-Orientated approaches
   - Dynamic language approaches


• Polyglot and functional languages exist on the JVM
   - The JVM is no longer tied to Java the language
Why Java is not a Golden Hammer
 • Recompilation is laborious


 • Static typing can be inflexible
    - Can lead to long refactoring times


 • Deployment is a heavyweight process
    - JRebel can mitigate this for web apps


 • Java's syntax is not a natural fit for producing DSLs
Java is a conservative language
• New language features take a while to arrive in Java


• This is deliberate


• Languages that move quickly can “repent at leisure”
   - There are some Scala features which everyone now regrets


• Non-Java languages are a test-bed for features
   - A good place to learn and experiment
Language Zoology
• Interpreted vs. Compiled
   - Interpreted source code is executed as-is
   - Compiled code is converted to machine code before
     execution


• Dynamic vs. static
   - Dynamic variables can have different types at different times
   - Dynamic types are only resolved at execution time
   - Static types can be resolved much earlier


• Imperative vs. functional
   - OO and Procedural are both imperative styles
   - Imperative: Code operates on Data
   - Functional: Code & Data are one and the same
Languages on the JVM
• Over 200! Falling into several broad groupings


• Language re-implementations
   - JRuby, Jython


• Attempted Java killers
   - Fantom, Ceylon, Xtend, Scala


• Dynamic languages
   - Groovy, Rhino, Clojure


• Academic
   - Ioke, Seph
Polyglot Programming Pyramid
• Courtesy of Ola Bini
Ola - JVM languages expert.
     Do not talk to him


    Your brain will melt

                           9
Polyglot Layers
• Domain-specific
   - Tightly coupled to a specific part of the application domain.
   - e.g. Apache Camel DSL, Drools, Web templating


• Dynamic
   - Rapid, productive, flexible development of functionality
   - e.g. Groovy, Jython, Clojure


• Stable
   - Core functionality, stable, well-tested, performant.
   - e.g. Java, Scala
Ask yourself before going Poly
• Is the project area low risk?


• How easily does the language interoperate with Java?


• What tooling support is there?


• Is it easy to build, test & deploy in this language?


• How steep is the learning curve?
   - How easy is it to hire developers?
Experts: “use < 5 bullet points”


         sr&%w that!


                             12
Matt Raible - 20 criteria web frameworks
      –   Developer Productivity
      –   Developer Perception
      –   Learning Curve
      –   Project Health
      –   Developer Availability
      –   Job Trends
      –   Templating
      –   Components
      –   Ajax
      –   Plugins or Add-Ons
      –   Scalability
      –   Testing Support
      –   i18n and l10n
      –   Validation
      –   Multi-language Support
      –   Quality of Documentation/Tutorials
      –   Books Published
      –   REST Support (client and server)
      –   Mobile / iPhone Support
      –   Degree of Risk
JVM language web framework shoot out




    • Grails Wins!

    • http://bit.ly/jvm-frameworks-matrix
Functional Programming
• Functional Programming is important again
   - Multi-core CPUs means that your code can truly run parallel
   - map, reduce, filter idioms would be welcome!


• Java's support is mostly missing
   - Java 7's Fork and Join provides a bit of Map/Reduce
   - How would we want it to work in Java?


• Other languages on the JVM already provide support
   - Groovy, Scala, Clojure
Example - Reconciliation Service
 • We have 2 sources of data


 • Source 1 - The upstream system “sourceData”
    - e.g Call a web service for transaction records


 • Source 2 - The downstream database


 • We need a reconciliation system
    - Check that data is actually reaching the DB.
Reconciliation - Java Take 1
Output of Reconciliation - Java Take 1
  7172329 OK

  7173341 OK

  1R6GT OK

  1R6GV OK

  1R6GW OK

  main_ref: 1R6H2 not present in DB

  main_ref: 1R6H3 not present in DB

  1R6H6 OK

  623SRC OK
Analysing the data
• Q: What’s gone wrong?


• A: Upstream system is case-insensitive
   - Whereas the downstream one is case-sensitive


• 1R6H2 is present in the DB
   - It’s just called 1r6h2 instead


• Let’s go back to the code slide
   - Can anyone see a problem with the code now?


• There’s no containsCaseInsensitive() method
   - This is an irritant
Reconciliation - Fixing Case Sensitivity




    • With this:
Functional Realisation
• If you’ve ever found yourself writing collections code


• And get frustrated because...
   - There’s a method which almost provides a way..
   - To do what you need..
   - But you just need to tweak it slightly..


• Then that frustration is an itch
   - That could be scratched by functional programming!
Introducing Functional Concepts
 • Two ideas related to FP in the previous example


 • First idea is:
     - Operating on collections / data structures as a whole
     - Rather than explicitly iterating over their contents


 • Second idea is:
     - A lack of capability to add additional logic to existing
       methods


 • Both ideas help with writing concise, safer OO code
What if we could...
• Tweak the functionality of a method?
   - By adding in some new code of our own?


• We’d need to pass the code into the method
   - As a parameter.


• We'd need some way to treat the as if it was a value
   - We want to be able to put it into a variable.


• FP requires the ability to represent bits of logic as
  though they were values.
Reconciliation - With Match Function
Library Support

• There’s no actual 2-parameter contains() method.


• But that’s what we would want, if we could start again


• Other languages have this functionality
   - Called: Lambda expressions, closures, function literals..


• Need library support as well as the language primitive
“What if” is for namby pamby
            dreamers



                          26
The Map Pattern




• FP fans would call this a map expression
   - extractPrimaryKeys() takes List & returns new List
   - Run an operation on each element in turn
       • And return the new list we built up
More on the Map Pattern

• Note that the type contained in the returned List may
  be different from the incoming List.
   - In our example, incoming type is DBInfo, outgoing String
   - The original List hasn’t been affected in any way.


• This is where “functional programming” comes from
   - The functions behave like mathematical functions


• A function like f(x) = x * x
   - Doesn’t alter the value 2 when it’s passed in.
   - Instead, it returns a different value, 4.
The Filter Pattern




• The use of map is an absolutely classic FP idiom.


• It’s usually paired with the filter idiom.
Functions-as-values
• We can construct our "function-as-a-value"
      - Need a way to represent that “predicate function” for filter


• Here’s one way we could write it (in almost-Scala):

 (msg) -> { !msg.get("status")

            .equalsIgnoreCase("CANCELLED") };



• This is a function which takes one argument
      - msg is a Map<String, String>
      - The function returns boolean


• Actually, this is also how Java 8 is going to write it.
      - In fact this is a very Java-ish way of writing Scala
There you go Scala folks!
We finally gave you some props


       It’s the last time

                               31
What We Didn’t Cover
• Why functional is good for modern concurrency
   - That’s in the next hour!


• The myriad academic definitions of closures


• Groovy, Scala, Clojure, JRuby, Jython, Nashorn
   - Well actually....


• The Groovy folder you copied from the USB stick
   - Unzip the groovy-2.0.0.zip to a location of your choice
   - Work through as much of CH08 as you like!
What? You still here?
Go take a break will you!




                            33

More Related Content

What's hot

AWS IoT Device Defender による IoT デバイスのセキュリティ管理
AWS IoT Device Defender による IoT デバイスのセキュリティ管理AWS IoT Device Defender による IoT デバイスのセキュリティ管理
AWS IoT Device Defender による IoT デバイスのセキュリティ管理Amazon Web Services Japan
 
[AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)
 [AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2) [AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)
[AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)Amazon Web Services Japan
 
Fault Tolerance 패턴
Fault Tolerance 패턴 Fault Tolerance 패턴
Fault Tolerance 패턴 YoungSu Son
 
AWSでDockerを扱うためのベストプラクティス
AWSでDockerを扱うためのベストプラクティスAWSでDockerを扱うためのベストプラクティス
AWSでDockerを扱うためのベストプラクティスAmazon Web Services Japan
 
いまさら聞けない Amazon EC2
いまさら聞けない Amazon EC2いまさら聞けない Amazon EC2
いまさら聞けない Amazon EC2Yasuhiro Matsuo
 
Aws auto scalingによるwebapサーバbatchサーバの構成例
Aws auto scalingによるwebapサーバbatchサーバの構成例Aws auto scalingによるwebapサーバbatchサーバの構成例
Aws auto scalingによるwebapサーバbatchサーバの構成例Takeshi Mikami
 
Amazon s3へのデータ転送における課題とその対処法を一挙紹介
Amazon s3へのデータ転送における課題とその対処法を一挙紹介Amazon s3へのデータ転送における課題とその対処法を一挙紹介
Amazon s3へのデータ転送における課題とその対処法を一挙紹介Tetsunori Nishizawa
 
[Black Belt Online Seminar] AWS上でのログ管理
[Black Belt Online Seminar] AWS上でのログ管理[Black Belt Online Seminar] AWS上でのログ管理
[Black Belt Online Seminar] AWS上でのログ管理Amazon Web Services Japan
 
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けて
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けてAWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けて
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けてAmazon Web Services Japan
 
HCL Notes/Domino ライセンスガイド
HCL Notes/Domino ライセンスガイドHCL Notes/Domino ライセンスガイド
HCL Notes/Domino ライセンスガイドSoftware Info HCL Japan
 
SESとLambdaでメールをSlackに通知してみよう
SESとLambdaでメールをSlackに通知してみようSESとLambdaでメールをSlackに通知してみよう
SESとLambdaでメールをSlackに通知してみようKen'ichirou Kimura
 
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-Yuta Imai
 
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration Service20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration ServiceAmazon Web Services Japan
 
(독서광) 책 vs 책 - 파이썬 신간 분석
(독서광) 책 vs 책 - 파이썬 신간 분석(독서광) 책 vs 책 - 파이썬 신간 분석
(독서광) 책 vs 책 - 파이썬 신간 분석Jay Park
 
Route53 で親子同居
Route53 で親子同居Route53 で親子同居
Route53 で親子同居@ otsuka752
 
Addie Öğretim Tasarımı Modeli
Addie Öğretim Tasarımı ModeliAddie Öğretim Tasarımı Modeli
Addie Öğretim Tasarımı ModeliHilal Seda Yıldız
 
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみた
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみたre:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみた
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみたHideaki Aoyagi
 
ADMM algorithm in ProxImaL
ADMM algorithm in ProxImaL ADMM algorithm in ProxImaL
ADMM algorithm in ProxImaL Masayuki Tanaka
 
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)Amazon Web Services Japan
 

What's hot (20)

AWS IoT Device Defender による IoT デバイスのセキュリティ管理
AWS IoT Device Defender による IoT デバイスのセキュリティ管理AWS IoT Device Defender による IoT デバイスのセキュリティ管理
AWS IoT Device Defender による IoT デバイスのセキュリティ管理
 
[AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)
 [AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2) [AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)
[AWSマイスターシリーズ] Amazon Elastic Compute Cloud (EC2)
 
Fault Tolerance 패턴
Fault Tolerance 패턴 Fault Tolerance 패턴
Fault Tolerance 패턴
 
AWSでDockerを扱うためのベストプラクティス
AWSでDockerを扱うためのベストプラクティスAWSでDockerを扱うためのベストプラクティス
AWSでDockerを扱うためのベストプラクティス
 
いまさら聞けない Amazon EC2
いまさら聞けない Amazon EC2いまさら聞けない Amazon EC2
いまさら聞けない Amazon EC2
 
Aws auto scalingによるwebapサーバbatchサーバの構成例
Aws auto scalingによるwebapサーバbatchサーバの構成例Aws auto scalingによるwebapサーバbatchサーバの構成例
Aws auto scalingによるwebapサーバbatchサーバの構成例
 
Amazon s3へのデータ転送における課題とその対処法を一挙紹介
Amazon s3へのデータ転送における課題とその対処法を一挙紹介Amazon s3へのデータ転送における課題とその対処法を一挙紹介
Amazon s3へのデータ転送における課題とその対処法を一挙紹介
 
[Black Belt Online Seminar] AWS上でのログ管理
[Black Belt Online Seminar] AWS上でのログ管理[Black Belt Online Seminar] AWS上でのログ管理
[Black Belt Online Seminar] AWS上でのログ管理
 
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けて
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けてAWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けて
AWS Black Belt Online Seminar AWS 認定クラウドプラクティショナー取得に向けて
 
HCL Notes/Domino ライセンスガイド
HCL Notes/Domino ライセンスガイドHCL Notes/Domino ライセンスガイド
HCL Notes/Domino ライセンスガイド
 
SESとLambdaでメールをSlackに通知してみよう
SESとLambdaでメールをSlackに通知してみようSESとLambdaでメールをSlackに通知してみよう
SESとLambdaでメールをSlackに通知してみよう
 
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
 
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration Service20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
 
(독서광) 책 vs 책 - 파이썬 신간 분석
(독서광) 책 vs 책 - 파이썬 신간 분석(독서광) 책 vs 책 - 파이썬 신간 분석
(독서광) 책 vs 책 - 파이썬 신간 분석
 
Route53 で親子同居
Route53 で親子同居Route53 で親子同居
Route53 で親子同居
 
今だからこそ見直そうAzureコスト最適化
今だからこそ見直そうAzureコスト最適化今だからこそ見直そうAzureコスト最適化
今だからこそ見直そうAzureコスト最適化
 
Addie Öğretim Tasarımı Modeli
Addie Öğretim Tasarımı ModeliAddie Öğretim Tasarımı Modeli
Addie Öğretim Tasarımı Modeli
 
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみた
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみたre:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみた
re:Invent 2021のS3アップデート紹介 & Glacier Instant Retrieval試してみた
 
ADMM algorithm in ProxImaL
ADMM algorithm in ProxImaL ADMM algorithm in ProxImaL
ADMM algorithm in ProxImaL
 
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)
JAWS-UG 情シス支部の皆様向け Amazon Elastic File System (Amazon EFS)
 

Similar to Polyglot and Functional Programming (OSCON 2012)

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Martijn Verburg
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Martijn Verburg
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirBarry Jones
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in JavaRuben Badaró
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mSteve Elliott
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...InfinIT - Innovationsnetværket for it
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 

Similar to Polyglot and Functional Programming (OSCON 2012) (20)

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)Introduction to Java 7 (OSCON 2012)
Introduction to Java 7 (OSCON 2012)
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 

More from Martijn Verburg

Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)
Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)
Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)Martijn Verburg
 
Garbage Collection - The Useful Parts
Garbage Collection - The Useful PartsGarbage Collection - The Useful Parts
Garbage Collection - The Useful PartsMartijn Verburg
 
Free community with deep roots
Free community with deep rootsFree community with deep roots
Free community with deep rootsMartijn Verburg
 
Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Martijn Verburg
 
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)Martijn Verburg
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Martijn Verburg
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Martijn Verburg
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Martijn Verburg
 
How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)Martijn Verburg
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Martijn Verburg
 

More from Martijn Verburg (11)

NoHR Hiring
NoHR HiringNoHR Hiring
NoHR Hiring
 
Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)
Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)
Adopt OpenJDK - Lessons learned and Where we're going (FOSDEM 2013)
 
Garbage Collection - The Useful Parts
Garbage Collection - The Useful PartsGarbage Collection - The Useful Parts
Garbage Collection - The Useful Parts
 
Free community with deep roots
Free community with deep rootsFree community with deep roots
Free community with deep roots
 
Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)
 
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)
Paperwork, Politics and Pain - Our year in the JCP (FOSDEM 2012)
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)How to open source a project at Mega Corp (Geecon - May/2011)
How to open source a project at Mega Corp (Geecon - May/2011)
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
 

Recently uploaded

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
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
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
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
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
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
 
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
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
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
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 

Recently uploaded (20)

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
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
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
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
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
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
 
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
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
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
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 

Polyglot and Functional Programming (OSCON 2012)

  • 1. The Well-Grounded Java Developer Polyglot & Functional Programming
  • 2. This is still not an Oracle legal slide 2
  • 3. Why Polyglot & Functional? • The WGJD wants to code rapidly • The WGJD wants to code concisely • The WGJD wants to take advantage of: - The JVM - Non Object-Orientated approaches - Dynamic language approaches • Polyglot and functional languages exist on the JVM - The JVM is no longer tied to Java the language
  • 4. Why Java is not a Golden Hammer • Recompilation is laborious • Static typing can be inflexible - Can lead to long refactoring times • Deployment is a heavyweight process - JRebel can mitigate this for web apps • Java's syntax is not a natural fit for producing DSLs
  • 5. Java is a conservative language • New language features take a while to arrive in Java • This is deliberate • Languages that move quickly can “repent at leisure” - There are some Scala features which everyone now regrets • Non-Java languages are a test-bed for features - A good place to learn and experiment
  • 6. Language Zoology • Interpreted vs. Compiled - Interpreted source code is executed as-is - Compiled code is converted to machine code before execution • Dynamic vs. static - Dynamic variables can have different types at different times - Dynamic types are only resolved at execution time - Static types can be resolved much earlier • Imperative vs. functional - OO and Procedural are both imperative styles - Imperative: Code operates on Data - Functional: Code & Data are one and the same
  • 7. Languages on the JVM • Over 200! Falling into several broad groupings • Language re-implementations - JRuby, Jython • Attempted Java killers - Fantom, Ceylon, Xtend, Scala • Dynamic languages - Groovy, Rhino, Clojure • Academic - Ioke, Seph
  • 8. Polyglot Programming Pyramid • Courtesy of Ola Bini
  • 9. Ola - JVM languages expert. Do not talk to him Your brain will melt 9
  • 10. Polyglot Layers • Domain-specific - Tightly coupled to a specific part of the application domain. - e.g. Apache Camel DSL, Drools, Web templating • Dynamic - Rapid, productive, flexible development of functionality - e.g. Groovy, Jython, Clojure • Stable - Core functionality, stable, well-tested, performant. - e.g. Java, Scala
  • 11. Ask yourself before going Poly • Is the project area low risk? • How easily does the language interoperate with Java? • What tooling support is there? • Is it easy to build, test & deploy in this language? • How steep is the learning curve? - How easy is it to hire developers?
  • 12. Experts: “use < 5 bullet points” sr&%w that! 12
  • 13. Matt Raible - 20 criteria web frameworks – Developer Productivity – Developer Perception – Learning Curve – Project Health – Developer Availability – Job Trends – Templating – Components – Ajax – Plugins or Add-Ons – Scalability – Testing Support – i18n and l10n – Validation – Multi-language Support – Quality of Documentation/Tutorials – Books Published – REST Support (client and server) – Mobile / iPhone Support – Degree of Risk
  • 14. JVM language web framework shoot out • Grails Wins! • http://bit.ly/jvm-frameworks-matrix
  • 15. Functional Programming • Functional Programming is important again - Multi-core CPUs means that your code can truly run parallel - map, reduce, filter idioms would be welcome! • Java's support is mostly missing - Java 7's Fork and Join provides a bit of Map/Reduce - How would we want it to work in Java? • Other languages on the JVM already provide support - Groovy, Scala, Clojure
  • 16. Example - Reconciliation Service • We have 2 sources of data • Source 1 - The upstream system “sourceData” - e.g Call a web service for transaction records • Source 2 - The downstream database • We need a reconciliation system - Check that data is actually reaching the DB.
  • 18. Output of Reconciliation - Java Take 1 7172329 OK 7173341 OK 1R6GT OK 1R6GV OK 1R6GW OK main_ref: 1R6H2 not present in DB main_ref: 1R6H3 not present in DB 1R6H6 OK 623SRC OK
  • 19. Analysing the data • Q: What’s gone wrong? • A: Upstream system is case-insensitive - Whereas the downstream one is case-sensitive • 1R6H2 is present in the DB - It’s just called 1r6h2 instead • Let’s go back to the code slide - Can anyone see a problem with the code now? • There’s no containsCaseInsensitive() method - This is an irritant
  • 20. Reconciliation - Fixing Case Sensitivity • With this:
  • 21. Functional Realisation • If you’ve ever found yourself writing collections code • And get frustrated because... - There’s a method which almost provides a way.. - To do what you need.. - But you just need to tweak it slightly.. • Then that frustration is an itch - That could be scratched by functional programming!
  • 22. Introducing Functional Concepts • Two ideas related to FP in the previous example • First idea is: - Operating on collections / data structures as a whole - Rather than explicitly iterating over their contents • Second idea is: - A lack of capability to add additional logic to existing methods • Both ideas help with writing concise, safer OO code
  • 23. What if we could... • Tweak the functionality of a method? - By adding in some new code of our own? • We’d need to pass the code into the method - As a parameter. • We'd need some way to treat the as if it was a value - We want to be able to put it into a variable. • FP requires the ability to represent bits of logic as though they were values.
  • 24. Reconciliation - With Match Function
  • 25. Library Support • There’s no actual 2-parameter contains() method. • But that’s what we would want, if we could start again • Other languages have this functionality - Called: Lambda expressions, closures, function literals.. • Need library support as well as the language primitive
  • 26. “What if” is for namby pamby dreamers 26
  • 27. The Map Pattern • FP fans would call this a map expression - extractPrimaryKeys() takes List & returns new List - Run an operation on each element in turn • And return the new list we built up
  • 28. More on the Map Pattern • Note that the type contained in the returned List may be different from the incoming List. - In our example, incoming type is DBInfo, outgoing String - The original List hasn’t been affected in any way. • This is where “functional programming” comes from - The functions behave like mathematical functions • A function like f(x) = x * x - Doesn’t alter the value 2 when it’s passed in. - Instead, it returns a different value, 4.
  • 29. The Filter Pattern • The use of map is an absolutely classic FP idiom. • It’s usually paired with the filter idiom.
  • 30. Functions-as-values • We can construct our "function-as-a-value" - Need a way to represent that “predicate function” for filter • Here’s one way we could write it (in almost-Scala): (msg) -> { !msg.get("status") .equalsIgnoreCase("CANCELLED") }; • This is a function which takes one argument - msg is a Map<String, String> - The function returns boolean • Actually, this is also how Java 8 is going to write it. - In fact this is a very Java-ish way of writing Scala
  • 31. There you go Scala folks! We finally gave you some props It’s the last time 31
  • 32. What We Didn’t Cover • Why functional is good for modern concurrency - That’s in the next hour! • The myriad academic definitions of closures • Groovy, Scala, Clojure, JRuby, Jython, Nashorn - Well actually.... • The Groovy folder you copied from the USB stick - Unzip the groovy-2.0.0.zip to a location of your choice - Work through as much of CH08 as you like!
  • 33. What? You still here? Go take a break will you! 33

Editor's Notes

  1. TODO: If we have time, replace images of code with real text based code\n
  2. It&amp;#x2019;s always worth repeating a bad joke\n
  3. Explain what polyglot means\n
  4. Do yourself a favour and get a JRebel license if you web hack in Java\n
  5. Learning non-Java languages will make you a better programmer\n
  6. * Java confuses matters as it&amp;#x2019;s.... both\n* Static types can be resolved at compile time for example\n
  7. \n
  8. \n
  9. \n
  10. \n
  11. * Intro the web dev slides. &amp;#x201C;One major use case for poly is web dev.&amp;#x201D;\n* Hands up if you do Struts or JSF. Hands up if you like it.\n
  12. Upcoming 20 bullet point slide\n
  13. \n
  14. Actually I can talk to the start-up story here - MV\n\n\n
  15. \n
  16. \n
  17. * We have 2 sources of data, and we want to check whether the same elements appear in each.\n* We need two loops to do this - as there are 3 cases - id is OK, id only appears in source, and only in DB\n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. * So, we&amp;#x2019;ve come at this a different way - we started out by saying that we need to pass in function values to customise functions.\n* This is what&amp;#x2019;s called &amp;#x201C;higher-order functions&amp;#x201D;. This is a different approach.\n
  24. * Imaginary FP-in-Java syntax\n* Of course, this method doesn&amp;#x2019;t really exist. That&amp;#x2019;s why Eclipse has red-underlined it.\n
  25. \n
  26. \n
  27. Let&amp;#x2019;s show a bit more context, and show how the reconcile() method gets called. DBInfo is the type which was actually returned from the DB lookup\nAlso, another slightly sneaky trick is in the call to reconcile() &amp;#x2013; we pass the returned List from extractPrimaryKeys() into the constructor for HashSet to convert it to a Set. This handily de-dups the List for us, making the contains() call more compact in the reconcile() method.\n
  28. \n
  29. \n* Notice the &amp;#x201C;defensive copy&amp;#x201D;. We return a new List. \n* We don&amp;#x2019;t mutate the existing List (the filter() form behaves like a mathematical function). \n* We build up a new List by testing each element against a function which returns boolean. \n* If the result of testing an element is true, we add it into the output List\n
  30. Predicate is the jargon for the returns-boolean testing function that we apply to each element in turn.\n\n
  31. \n
  32. \n
  33. \n