SlideShare uma empresa Scribd logo
1 de 32
The WGJD - Polyglot &
Functional Programming
    Ben Evans and Martijn Verburg
       (@kittylyst @karianna)

        http://www.teamsparq.net


    Slide Design by http://www.kerrykenneally.com
This is still not an Oracle legal
                slide




                              2
Polyglot and Functional - Why is it important?


• 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




                                                       3
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




                                                          4
Java is a conservative language


• New language features take a while to arrive in Java

• This is deliberate

• Languages which try to move quickly can “repent at leisure”
   – There are some features in Scala which everyone now regrets


• Non-Java languages are a test-bed for features
   – A good place to learn and experiment




                                                                5
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


                                                                     6
Languages on the JVM


• There are now 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

                                                             7
Polyglot Programming Pyramid


• Courtesy of Ola Bini




                                        8
Ola - JVM languages expert?
  Meh, do not talk to him




                            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




                                                                     10
Questions to ask yourself before going Poly


• Is the project area low risk?

• How easily does the language interoperate with Java?

• What tooling support is there for the language?
   – e.g. IDE support


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

• How steep is the learning curve for this language?

• How easy is it to hire developers for this language?


                                                             11
Experts: “use < 5 bullet points”


We have a fr&%!en movie screen!


                              12
Case Study: Rapid Web Development


• Matt Raible - 20 criteria for a web framework
       •   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                         13
JVM language web framework shoot out




• Grails Wins!
• http://bit.ly/jvm-frameworks-matrix


                                               14
Functional Programming


• Show a Java-centric approach to Functional Programming (FP)

• Focus on what’s missing & how we would want it to work in Java

• Example-driven

• Make the connection to other languages (especially Scala)




                                                              15
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.




                                                      16
Reconciliation - Java Take 1




                               17
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




                                                 18
Analysing the data


• What’s gone wrong?

• The answer is that 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


                                                           19
Reconciliation - Fixing Case Sensitivity




With this:




                                                        20
Introducing Functional Concepts


• This are 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




                                                                        21
What if we could...


• Suppose 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 need some way to treat a code blob as though it was a value
   – Want to be able to put it into a variable.


• FP requires the ability to represent bits of logic as though they were
  values.




                                                               22
Reconciliation - With Match Function




Imaginary FP-in-Java syntax:




                                                23
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 to have library support as well as the language primitive




                                                                     24
“What if” is for namby pamby
            dreamers



                          25
FP Map Pattern




• FP fans would call this a map() expression
   – extractPrimaryKeys() takes a List and returns a new List
   – Run an operation on each element in turn (and return the new list we
     built up).



                                                                  26
FP - More on the Map Pattern


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


• This is where the name “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.




                                                                 27
FP - The Filter Pattern




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


• It’s usually paired with this well-known pattern, the filter() form.




                                                              28
Functions-as-values


• Now we can see the construct that we need for function-as-value.
   – We need some 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
        • but that’s deliberate

                                                                    29
There you go Scala folks!
We finally gave you some props


       It’s the last time

                               30
What We Didn’t Have Time To Talk About


• Why functional is good for modern concurrency
   – That’s in the next hour!


• The myriad academic definitions of closures

• Groovy in depth

• Clojure

• What Java 8 JVM changes mean for other languages
   – Jigsaw could be a major opportunity or a headache




                                                         31
What? You still here?
Go take a break will you!




                            32

Mais conteúdo relacionado

Mais procurados

PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015kyphpug
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Java Presentation
Java PresentationJava Presentation
Java PresentationAmr Salah
 
Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)Ben Evans
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java RatnaJava
 
Introduction to Java Part-2
Introduction to Java Part-2Introduction to Java Part-2
Introduction to Java Part-2RatnaJava
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVMAlex Birch
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?C4Media
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...Miles Sabin
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java Hitesh-Java
 
Rubykaigi 2017-nishimotz-v6
Rubykaigi 2017-nishimotz-v6Rubykaigi 2017-nishimotz-v6
Rubykaigi 2017-nishimotz-v6Takuya Nishimoto
 
Java Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.EasyJava Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.Easyroialdaag
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediZeroTurnaround
 
Smalltalk and ruby - 2012-12-08
Smalltalk and ruby  - 2012-12-08Smalltalk and ruby  - 2012-12-08
Smalltalk and ruby - 2012-12-08Koan-Sin Tan
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Whitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveWhitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveDragos Manolescu
 
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning TalksBuilding Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning TalksAtlassian
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?Charlie Gracie
 

Mais procurados (20)

PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 
Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)Perl On The JVM (London.pm Talk 2009-04)
Perl On The JVM (London.pm Talk 2009-04)
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Introduction to Java Part-2
Introduction to Java Part-2Introduction to Java Part-2
Introduction to Java Part-2
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...
Scaladays 2010 - The Scala IDE for Eclipse - Retrospect and Prospect for 2.8 ...
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Rubykaigi 2017-nishimotz-v6
Rubykaigi 2017-nishimotz-v6Rubykaigi 2017-nishimotz-v6
Rubykaigi 2017-nishimotz-v6
 
Java Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.EasyJava Edge.2009.Grails.Web.Dev.Made.Easy
Java Edge.2009.Grails.Web.Dev.Made.Easy
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila Szegedi
 
Smalltalk and ruby - 2012-12-08
Smalltalk and ruby  - 2012-12-08Smalltalk and ruby  - 2012-12-08
Smalltalk and ruby - 2012-12-08
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Whitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveWhitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to Reactive
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning TalksBuilding Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
Building Atlassian Plugins with Groovy - Atlassian Summit 2010 - Lightning Talks
 
#JavaOne What's in an object?
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
 

Semelhante a Polyglot and functional (Devoxx Nov/2011)

Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
 
Principles Of Programing Languages
Principles Of Programing LanguagesPrinciples Of Programing Languages
Principles Of Programing LanguagesMatthew McCullough
 
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
 
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
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mSteve Elliott
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformTomoharu ASAMI
 
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
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptAliyaJav
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in JavaRuben Badaró
 

Semelhante a Polyglot and functional (Devoxx Nov/2011) (20)

Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Principles Of Programing Languages
Principles Of Programing LanguagesPrinciples Of Programing Languages
Principles Of Programing Languages
 
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
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
 
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...
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).ppt
 
JavaFX 101
JavaFX 101JavaFX 101
JavaFX 101
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
 

Mais de Martijn Verburg

Garbage Collection - The Useful Parts
Garbage Collection - The Useful PartsGarbage Collection - The Useful Parts
Garbage Collection - The Useful PartsMartijn 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
 
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
 

Mais de Martijn Verburg (6)

NoHR Hiring
NoHR HiringNoHR Hiring
NoHR Hiring
 
Garbage Collection - The Useful Parts
Garbage Collection - The Useful PartsGarbage Collection - The Useful Parts
Garbage Collection - The Useful Parts
 
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)
 
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
 

Último

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Polyglot and functional (Devoxx Nov/2011)

  • 1. The WGJD - Polyglot & Functional Programming Ben Evans and Martijn Verburg (@kittylyst @karianna) http://www.teamsparq.net Slide Design by http://www.kerrykenneally.com
  • 2. This is still not an Oracle legal slide 2
  • 3. Polyglot and Functional - Why is it important? • 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 3
  • 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 4
  • 5. Java is a conservative language • New language features take a while to arrive in Java • This is deliberate • Languages which try to move quickly can “repent at leisure” – There are some features in Scala which everyone now regrets • Non-Java languages are a test-bed for features – A good place to learn and experiment 5
  • 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 6
  • 7. Languages on the JVM • There are now 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 7
  • 8. Polyglot Programming Pyramid • Courtesy of Ola Bini 8
  • 9. Ola - JVM languages expert? Meh, do not talk to him 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 10
  • 11. Questions to ask yourself before going Poly • Is the project area low risk? • How easily does the language interoperate with Java? • What tooling support is there for the language? – e.g. IDE support • How easy is it to build, test & deploy in this language? • How steep is the learning curve for this language? • How easy is it to hire developers for this language? 11
  • 12. Experts: “use < 5 bullet points” We have a fr&%!en movie screen! 12
  • 13. Case Study: Rapid Web Development • Matt Raible - 20 criteria for a web framework • 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 13
  • 14. JVM language web framework shoot out • Grails Wins! • http://bit.ly/jvm-frameworks-matrix 14
  • 15. Functional Programming • Show a Java-centric approach to Functional Programming (FP) • Focus on what’s missing & how we would want it to work in Java • Example-driven • Make the connection to other languages (especially Scala) 15
  • 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. 16
  • 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 18
  • 19. Analysing the data • What’s gone wrong? • The answer is that 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 19
  • 20. Reconciliation - Fixing Case Sensitivity With this: 20
  • 21. Introducing Functional Concepts • This are 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 21
  • 22. What if we could... • Suppose 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 need some way to treat a code blob as though it was a value – Want to be able to put it into a variable. • FP requires the ability to represent bits of logic as though they were values. 22
  • 23. Reconciliation - With Match Function Imaginary FP-in-Java syntax: 23
  • 24. 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 to have library support as well as the language primitive 24
  • 25. “What if” is for namby pamby dreamers 25
  • 26. FP Map Pattern • FP fans would call this a map() expression – extractPrimaryKeys() takes a List and returns a new List – Run an operation on each element in turn (and return the new list we built up). 26
  • 27. FP - More on the Map Pattern • Note that the type contained in the returned List may be different from the incoming List. – Incoming type is DBInfo, outgoing is String – The original List hasn’t been affected in any way. • This is where the name “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. 27
  • 28. FP - The Filter Pattern • The use of map() is an absolutely classic FP idiom. • It’s usually paired with this well-known pattern, the filter() form. 28
  • 29. Functions-as-values • Now we can see the construct that we need for function-as-value. – We need some 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 • but that’s deliberate 29
  • 30. There you go Scala folks! We finally gave you some props It’s the last time 30
  • 31. What We Didn’t Have Time To Talk About • Why functional is good for modern concurrency – That’s in the next hour! • The myriad academic definitions of closures • Groovy in depth • Clojure • What Java 8 JVM changes mean for other languages – Jigsaw could be a major opportunity or a headache 31
  • 32. What? You still here? Go take a break will you! 32

Notas do Editor

  1. \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\nStatic types can be resolved at compile time for example\n\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;\nHands 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. So, we have 2 sources of data, and we want to check whether the same elements appear in each. 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. If you&amp;#x2019;ve ever found yourself writing collections code and getting frustrated because there&amp;#x2019;s a method which almost provides a way to do\nwhat you need, but you just need to tweak it slightly, then that frustration is an itch is could be scratched by functional programming.\n
  21. \n
  22. 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 customize functions. This is what&amp;#x2019;s called &amp;#x201C;higher-order functions&amp;#x201D;. This is a different approach.\n
  23. Of course, this method doesn&amp;#x2019;t really exist. That&amp;#x2019;s why Eclipse has red-underlined it.\n
  24. \n
  25. \n
  26. 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
  27. \n
  28. Notice the &amp;#x201C;defensive copy&amp;#x201D;. We return a new List. \nWe don&amp;#x2019;t mutate the existing List (so once again the filter() form behaves like a mathematical function). \nWe build up a new List by testing each element against a function which returns boolean. \nIf the result of testing an element is true, we add it into the output List.\n
  29. Predicate is the jargon for the returns-boolean testing function that we apply to each element in turn.\n\n
  30. \n
  31. \n
  32. \n