Busy Java Developer's Guide to Functional Programming. Ted Neward Neward & Associates http://www.tedneward.com

Similar documents
CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

ML for the Working Programmer

Chapter 7: Functional Programming Languages


Kotlin for Android Developers

Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Computing Concepts with Java Essentials

Programming Language Concepts for Software Developers

Habanero Extreme Scale Software Research Project

Formal Engineering for Industrial Software Development

CS346: Database Programming.

Lecture 1: Introduction

Functional Programming in C++11

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Programming Languages

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Chapter 12 Programming Concepts and Languages

.NET and J2EE Intro to Software Engineering

Introduction to programming

Towards Interface Types for Haskell

To Java SE 8, and Beyond (Plan B)

Regular Expressions and Automata using Haskell

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT

William E. Hart Carl Laird Jean-Paul Watson David L. Woodruff. Pyomo Optimization. Modeling in Python. ^ Springer

Programming Languages

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Factoring Trinomials: The ac Method

Programming Hadoop 5-day, instructor-led BD-106. MapReduce Overview. Hadoop Overview

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

@Scalding. Based on talk by Oscar Boykin / Twitter

BUSINESS RULES CONCEPTS... 2 BUSINESS RULE ENGINE ARCHITECTURE By using the RETE Algorithm Benefits of RETE Algorithm...

: provid.ir

CS555: Distributed Systems [Fall 2015] Dept. Of Computer Science, Colorado State University

Functional Programming

Lecture 11: Tail Recursion; Continuations

Chapter 15 Functional Programming Languages

Chapter 5 Names, Bindings, Type Checking, and Scopes

Computer Programming I & II*

APACHE SLING & FRIENDS TECH MEETUP BERLIN, SEPTEMBER APACHE SLING & SCALA Jochen Fliedner

[Refer Slide Time: 05:10]

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Computer Programming I

Sources: On the Web: Slides will be available on:

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

2sms SMS API Overview

CHM 579 Lab 1: Basic Monte Carlo Algorithm

Moving from CS 61A Scheme to CS 61B Java

Shark Installation Guide Week 3 Report. Ankush Arora

Tutorial on Writing Modular Programs in Scala

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Logging in Java Applications

CS Standards Crosswalk: CSTA K-12 Computer Science Standards and Oracle Java Programming (2014)

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Java SE 8 Programming

1/20/2016 INTRODUCTION

Domain specific language on automata: Design and Implementation problems. Loïc Fosse

The Inside Scoop on Hadoop

Syntax Check of Embedded SQL in C++ with Proto

Software quality improvement via pattern matching

Java SE 7 Programming

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Oracle Exam 1z0-102 Oracle Weblogic Server 11g: System Administration I Version: 9.0 [ Total Questions: 111 ]

Android Application Development Course Program

DIPLOMADO DE JAVA - OCA

Microsoft Windows PowerShell v2 For Administrators

Java Program Coding Standards Programming for Information Technology

11.1 What is Project Management? Object-Oriented Software Engineering Practical Software Development using UML and Java. What is Project Management?

Anatomy of Programming Languages. William R. Cook

Java Application Developer Certificate Program Competencies

Elixir Schedule Designer User Manual

Facebook Twitter YouTube Google Plus Website

BEST WEB PROGRAMMING LANGUAGES TO LEARN ON YOUR OWN TIME

Configuring and Integrating JMX

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

CLINIC MANAGEMENT SYSTEM WITH NOTIFICATION USING GSM MODEM CHAPTER 1 INTRODUCTION

MEAP Edition Manning Early Access Program Nim in Action Version 1

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

SSL CONFIGURATION GUIDE

The Designer's Guide to VHDL

Introduction to Database Systems. Chapter 1 Introduction. Chapter 1 Introduction

Java Coding Practices for Improved Application Performance

A Typing System for an Optimizing Multiple-Backend Tcl Compiler

Charles Dierbach. Wiley

El Dorado Union High School District Educational Services

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Towards a Framework for Generating Tests to Satisfy Complex Code Coverage in Java Pathfinder

Transcription:

Busy Java Developer's Guide to Functional Programming Ted Neward Neward & Associates http://www.tedneward.com

Who is this guy? Principal Consultant: architect, mentor, free agent coach BEA Technical Director, Microsoft MVP Architect JSR 175, 250, 277 EG member Founding Editor-in-Chief: TheServerSide.NET Author Professional F# (Forthcoming) Effective Enterprise Java (Addison-Wesley, 2004) Server-Based Java Programming (Manning, 2000) C# in a Nutshell (OReilly, 2003) SSCLI Essentials (w/stutz, Shilling; OReilly, 2003) Papers at http://www.tedneward.com Weblog at http://blogs.tedneward.com Credentials

Review What is functional programming (concepts)? Why do I care? How can one program functionally in Java? What close-to-java tools are there?

Concepts Functional languages functional as in mathematics' notion of function for every x, there is a corresponding value y this implies no side effects not imperative statements, but expressions "x = x+1" is not increment, it's impossible this implies expressions can be substituted or executed independently (parallellism) spectrum of "functional-ness", known as purity "pure" functional languages allow for no side effects "impure" functional languages allow for side effects

Any effect Spectrum Pure (no effects) C, C++, Java, C#, VB Excel, Haskell X := In1 X := X*X X := X + In2*In2 Commands, control flow Do this, then do that X is the name of a cell that has different values at different times Expressions, data flow No notion of sequence A2 is the name of a (single) value

Imperative C, C++, Java, C#, VB X := In1 X := X*X X := X + In2*In2 In1 In2 X 3 4 Commands, control flow Do this, then do that X is the name of a cell that has different values at different times

Imperative C, C++, Java, C#, VB X := In1 X := X*X X := X + In2*In2 In1 In2 X 3 4 3 Commands, control flow Do this, then do that X is the name of a cell that has different values at different times

Imperative C, C++, Java, C#, VB X := In1 X := X*X X := X + In2*In2 In1 In2 X 3 4 9 Commands, control flow Do this, then do that X is the name of a cell that has different values at different times

Imperative C, C++, Java, C#, VB X := In1 X := X*X X := X + In2*In2 In1 In2 X 3 4 25 Commands, control flow Do this, then do that X is the name of a cell that has different values at different times

Functional Excel, Haskell, F# A1 B1 * * A2 B2 + A3 A2 = A1*A1 B2 = B1*B1 A3 = A2+B2 Expressions, data flow No notion of sequence A2 is the name of a (single) value

Concepts Some basic functional concepts strongly-typed, type-inferenced immutable values functions as first-class values expressions-not-statements tuples, lists recursion pattern-matching currying, partial-application of functions

Concepts Strongly-typed Java already has this to a point Generics could/should be all the way through the JVM Type-inferenced Java fails on this point requires explicit declarations Not a deal-breaking concern, just more verbosity Expressions-not-statements Java fails on this point statements core to the language We could (maybe) support this by doing everything declaratively (e.g. generics-based expressions), but bleah

Concepts Recursion Java supports recursion, obviously Immutable values Java supports immutability, but only with help in other words, you have to train your fingers to type final

Concepts Functions as first-class values Java fails here, but libraries can help some Essentially, we will make heavy use of anonymous inner-class implementations to mimic/fake standalone functions; this is commonly known as functors Not perfect, but manageable maybe (Note: other languages make this point much easier, by hiding the ugly details behind their syntax) BGGA-javac, Groovy, Scala, Clojure

Concepts Tuples, lists, option Lists can be List<E>, but List<E> is missing some key ideas Namely, all the functional operations Tuples are strongly-typed "bundles" of public data Tuple2/Pair, Tuple3/Triplet, Tuple4/Quad, Option<E> is a single-membered collection, with two derived classes: Some<E>, and None Some<E> represents a value None<E> represents no value Being an Iterable<E> means we can operate safely Most functional operations can be Collections-style algorithms on a support class

Concepts Generators Iterable<E> knows how to produce Iterator<E>s any Iterable<E> can participate in the enhanced "for" loop But Iterator<E>s can produce values, not just report them these are sometimes called generators Iterator<E>s could even never terminate! so long as we have appropriate methods to handle them this makes Iterator<E>s akin to sequences this opens up a new way of thinking/processing

Concepts Sequences lots of things can be seen as sequences characters in a string fields in a record records in a database files in a directory algorithmic calculations (factorial, fibonacci, ) lines in a file sequences and Collections have a deep relationship more on this later

Concepts Pattern-matching pattern-matching feels like a next-generation switch/case patterns can be a variety of types in Java, pattern-matching is not supported

Concepts Partial application of functions returning a function that is defined by taking another function and filling in some (not all) of its parameters in Java, this means having to define a new method (as a subclass of a differently-defined functor interface) that manually passes in the filled-in parameters in other words, not precisely doing us any favors here

Implementation Most functional implementations in Java have to be done as a library of functors functor: object behaving as a function as a consequence, most functional implementations miss out on much of the functional language s goodness no type inference, no pattern-matching not impossible to program functionally just hard imagine programming to the JVM in C

Implementation Some functional Java implementations Apache Commons Functor library http://commons.apache.org/sandbox/functor FunctionalJava http://www.functionaljava.org BGGA compiler http://javac.info Mango http://www.jezuk.co.uk/cgi-bin/view/mango Generic Algorithms for Java http://jga.sourceforge.net/

Summary Functional programming is a powerful approach particularly when married against Java Collections particularly when married against immutable values Consider a functional JVM language Scala or Clojure are the front-runners Jaskell is Haskell-on-JVM

? Questions