Functional programming
Upcoming SlideShare
Loading in...5
×
 

Functional programming

on

  • 414 views

A small overview of functional programming.

A small overview of functional programming.

Statistics

Views

Total Views
414
Views on SlideShare
414
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Functional programming Functional programming Presentation Transcript

  • FUNCTIONAL PROGRAMMING (FP) Prateek Jain (prateekjainaa@gmail.com)
  • Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues
  • Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues View slide
  • Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues View slide
  • Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • What is FP? • RECURSION • ABSTRACTION • HIGHER ORDER FUNCTIONS • IMPACT MOST PROGRAMMING LANGUAGES
  • PROGRAMS AS FUNCTIONS • PROGRAM = DESCRIPTION OF A SPECIFIC COMPUTATION • Y = F(X) • F: X ->Y • MATHEMATICS • VARIABLES = ACTUAL VALUES • NO MEMEORY ALLOCATION CONCEPT • IMPERATIVE LANGUAGE • VARIABLES = MEMORY LOCATIONS + VALUES
  • PROGRAMS AS FUNCTIONS • NO LOOPS BUT RECURSION • NO VARIABLE EXCEPT AS A NAME FOR A VALUE • NO ASSIGNMENT OPERATION (x = x+1 , MEANINGLESS) • ONLY CONSTANTS, PARAMETERS AND VALUES
  • imperative functional EXAMPLE Void GCD (int u, int v, int* x) { Int y, t, z; z = u; y = v; While (y!=0) { … … } … } Void GCD(int u, int v) { if(v==0) return u; else return GCD(v, u%v); }
  • NO VARIABLES, NO ASSIGNMENT • No notion of the internal state of a function. • Referential Transparency. • Value Semantics.
  • FP vs Others • Recursions instead of loops • Pattern matching instead of “if” • Pattern matching instead of state machines • Information transformation instead of sequence of tasks
  • FP vs Others • Persistent data structures • Powerful concurrency constructs : Actors • Software transactional memory • Avoid “Null”
  • What it really means? • Immutability is good
  • What it really means? • Immutability is good • No bugs (due to nasty side effects)
  • What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency
  • What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency • No more messy loops
  • What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency • No more messy loops • Lazy evaluation
  • FP Examples • Erlang, Haskell, Clojure • F# • JAVA 8 (prject lambda), Scala, Groovy • R, Mathematica etc. (specialized languages)
  • CAUTION CAUTION
  • Maintaining, Maintainability • Use functional style wheretill it makes the intent more readable. Sort(extract(filter(having(on(Pet.class).getSpecies(), is(Dog)), pets, on(Pet.class).getName()), on(String.class)); List<Pet> dogs = filter(having(on(Pet.class).getSpecies(), is(Dog)), pets); List<String> dogNames = extract(dogs, on(Pet.class).getName()); List<String> sortedDogNames = sort(dogNames, on(String.class));
  • Maintaining, Maintainability • One liners are always not better. Convert(pets, new Convert<Pet, VetStay>() { @override public VetStay converter(Pet pet) { return new VetStay(pet, new Date(), “….”); }}); Private Converter<Pet, VetStay> toVetStay () { @override public VetStay converter(Pet pet) { return new VetStay(pet, new Date(), “….”); }}); Convert(pets, toVetStay());
  • FP - Adoption • Facebook (tchat), Linkedin uses Erlang • Twitter, UBS, Credit Suisse uses Scala
  • QUESTIONS? Questions?
  • FEEDBACK Feedback