SlideShare a Scribd company logo
1 of 28
Download to read offline
Functional Programming
Concepts and Ruby
Adrian Francke (@adrian2112)
Why I started to learn functional
programming
1. Interesting and useful concepts for general software
development
2. For fun
Structure and Interpretation of Computer Programs (SICP)
http://en.wikipedia.org/wiki/
Structure_and_Interpretation_of_Computer_Programs
1. Interesting and useful concepts for general software
development
2. For fun
Structure and Interpretation of Computer Programs (SICP)
http://en.wikipedia.org/wiki/
Structure_and_Interpretation_of_Computer_Programs
(3. Hipster)
Why I started to learn functional
programming
Goal of this talk
1. Show some functional programming concepts which
can be used in your day to day programming in a
non-functional programming language
2. Get you interested in functional programming
What is functional programming?
Declarative vs Imperative
Functional Programming is a kind of declarative programming
Imperative
“Describes computation in terms of statements that change a program state (...) describing
how a program operates.”
http://en.wikipedia.org/wiki/Imperative_programming
Declarative
“A style of building the structure and elements of computer programs, that expresses the logic
of a computation without describing its control flow. (...) describing what the program should
accomplish (...), rather than describing how”
http://en.wikipedia.org/wiki/Declarative_programming
Examples
Imperative Declarative
From: http://latentflip.com/imperative-vs-declarative/
Examples
Imperative Functional
Imperative: http://www.siafoo.net/snippet/306
Functional: http://en.literateprograms.org/Quicksort_%28Haskell%29
Functional Programming concepts:
Recursion
● Is a method where the solution to a
problem depends on solutions to smaller
instances of the same problem
● Recursion, see Recursion
● Recursion is heavily used in functional
programming as it is the canonical and
often the only way to iterate
Image from: http://learnyouahaskell.com/
Functional Programming concepts:
Recursion
Functional Programming concepts:
Higher order functions
● Functions that take
other functions as their
arguments
● Functions that returns
other functions
Functional Programming concepts:
Higher order functions
● Higher order function example
● accumulate from http://mitpress.mit.edu/sicp/full-text/book/
book-Z-H-15.html#%_sec_2.2.3
Functional Programming concepts:
Purity
● Referential transparency
● Lazy evaluation
Functional Programming concepts:
Referential transparency
● A program (or function) that has the same effects and
output on the same input
● Allows the programmer and the compiler to reason
about program behavior
● Try to make all functions referential transparent and
keep the side effects in one place
Functional Programming concepts:
Referential transparency
Useful
Useless
Unsafe
(side effects everywhere)
Safe
(Limited side effects)
• C
• Java
• … “normal” languages
• Haskell
• (probably other pure funcional laguages)
https://www.youtube.com/watch?v=iSmkqocn0oQ
Future
Functional Programming concepts:
Referential transparency
● A pure function can always be replaced by its result.
● There’s no difference between Math.cos(Math::PI)
and -1.0
● A function which calls an impure function is impure as
well. Impurity is contagious
http://www.sitepoint.com/functional-programming-pure-
functions/
Functional Programming concepts:
Referential transparency
Example from: http://valve.github.io/blog/2014/07/04/from-object-to-functional-immutability/
Referential opaque Referential transparent
Functional Programming concepts:
Referential transparency
● Easy to test (it does not depend on anything but its
input)
● Easy maintenance
● Concurrency/parallelization
Functional Programming concepts:
Referential transparency
Example from: http://www.sitepoint.com/functional-programming-pure-functions
Same function.
Only if it is a pure
function
Functional Programming concepts:
Lazy evaluation
● Pure functions can be performed at any time and
still yield the same result.
● Defer the computation of values until they are
needed
● Example
Which of this concepts I use in ruby and
how
● Higher order functions
o map
o reduce
o select
o find
● Pure functions (referential transparency)
Use attr_reader instead of attr_accessor
so once defined it cannot be changed
Keep side effects in
one place
Use of higher order
functions
This functions depend on self.date.
Should I send the date as parameter?
Current stand = Lets take this functions as “curried”
or partially applied with the objects date.
self.date not modifiable
Conclusions
● Learn new approaches to solve problems
● Try functional programing!!
● It will help you to create better code.
A language that doesn’t affect the way you think about programming, is not worth knowing.
— Alan Perlis
Resources
● Structure and Interpretation of Computer Programs (SICP) http://
mitpress.mit.edu/sicp/full-text/book/book-Z-H-38.html#
%_index_start
● Programming with Nothing http://codon.com/programming-with-
nothing
References
● Haskell wiki https://wiki.haskell.org/Functional_programming
● Composing programs (Higher order functions) http://
www.composingprograms.com/pages/16-higher-order-
functions.html
● Learn You a Haskell for Great Good! http://learnyouahaskell.com
● http://www.sitepoint.com/functional-programming-pure-functions/

More Related Content

What's hot

EclipseCon 2015 - Generating business applications from executable models
EclipseCon 2015 - Generating business applications from executable modelsEclipseCon 2015 - Generating business applications from executable models
EclipseCon 2015 - Generating business applications from executable modelsRafael Chaves
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressionsEclipse Day India
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Ranel Padon
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
Modern Static Code Analysis in PHP
Modern Static Code Analysis in PHPModern Static Code Analysis in PHP
Modern Static Code Analysis in PHPVladimir Reznichenko
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014Noopur Gupta
 
Concurrent Applications with F# Agents
Concurrent Applications with F# AgentsConcurrent Applications with F# Agents
Concurrent Applications with F# AgentsRachel Reese
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overviewJulian Król
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowRanel Padon
 
Tech for devs, F#
Tech for devs, F#Tech for devs, F#
Tech for devs, F#Robert Rohr
 
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...Dimitris Kolovos
 
Immutable data structures - A Primer
Immutable data structures - A PrimerImmutable data structures - A Primer
Immutable data structures - A PrimerbinDebug WorkSpace
 
Code: from Procedural to Object Oriented
Code: from Procedural to Object OrientedCode: from Procedural to Object Oriented
Code: from Procedural to Object Orientedkleinron
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective SystemMarcus Denker
 

What's hot (20)

EclipseCon 2015 - Generating business applications from executable models
EclipseCon 2015 - Generating business applications from executable modelsEclipseCon 2015 - Generating business applications from executable models
EclipseCon 2015 - Generating business applications from executable models
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressions
 
Laravel 5 and SOLID
Laravel 5 and SOLIDLaravel 5 and SOLID
Laravel 5 and SOLID
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
 
Lo1
Lo1Lo1
Lo1
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
Modern Static Code Analysis in PHP
Modern Static Code Analysis in PHPModern Static Code Analysis in PHP
Modern Static Code Analysis in PHP
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
 
Concurrent Applications with F# Agents
Concurrent Applications with F# AgentsConcurrent Applications with F# Agents
Concurrent Applications with F# Agents
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
Python for Swift
Python for SwiftPython for Swift
Python for Swift
 
Oop is not Dead
Oop is not DeadOop is not Dead
Oop is not Dead
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
 
Tech for devs, F#
Tech for devs, F#Tech for devs, F#
Tech for devs, F#
 
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
 
Immutable data structures - A Primer
Immutable data structures - A PrimerImmutable data structures - A Primer
Immutable data structures - A Primer
 
Code: from Procedural to Object Oriented
Code: from Procedural to Object OrientedCode: from Procedural to Object Oriented
Code: from Procedural to Object Oriented
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 

Similar to Functional programming ruby mty

PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018Dolly Aswin Harahap
 
Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrencyAnshul Sharma
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCUlrich Krause
 
Third-Party Software Library Reuse : From Adoption to Migration
Third-Party Software Library Reuse : From Adoption to MigrationThird-Party Software Library Reuse : From Adoption to Migration
Third-Party Software Library Reuse : From Adoption to MigrationAli Ouni
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Modern Frontend Technology
Modern Frontend TechnologyModern Frontend Technology
Modern Frontend TechnologyShip Hsu
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesUlrich Krause
 
Python functional programming
Python functional programmingPython functional programming
Python functional programmingGeison Goes
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional ProgrammingDave Fancher
 
Functional programming
Functional programmingFunctional programming
Functional programmingPiumiPerera7
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
Introduction to java
Introduction to  javaIntroduction to  java
Introduction to javaKalai Selvi
 
General Terminologies to understand programming and Data Science
General Terminologies to understand programming and Data ScienceGeneral Terminologies to understand programming and Data Science
General Terminologies to understand programming and Data Sciencepujashri1975
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesSolstice Mobile Argentina
 
CommonJS via PINF JavaScript Loader - Introduction
CommonJS via PINF JavaScript Loader - IntroductionCommonJS via PINF JavaScript Loader - Introduction
CommonJS via PINF JavaScript Loader - Introductioncadorn
 

Similar to Functional programming ruby mty (20)

Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018
 
Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrency
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Training 8051Report
Training 8051ReportTraining 8051Report
Training 8051Report
 
Third-Party Software Library Reuse : From Adoption to Migration
Third-Party Software Library Reuse : From Adoption to MigrationThird-Party Software Library Reuse : From Adoption to Migration
Third-Party Software Library Reuse : From Adoption to Migration
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Modern Frontend Technology
Modern Frontend TechnologyModern Frontend Technology
Modern Frontend Technology
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Introduction to java
Introduction to  javaIntroduction to  java
Introduction to java
 
General Terminologies to understand programming and Data Science
General Terminologies to understand programming and Data ScienceGeneral Terminologies to understand programming and Data Science
General Terminologies to understand programming and Data Science
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
 
CommonJS via PINF JavaScript Loader - Introduction
CommonJS via PINF JavaScript Loader - IntroductionCommonJS via PINF JavaScript Loader - Introduction
CommonJS via PINF JavaScript Loader - Introduction
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 

Recently uploaded (20)

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 

Functional programming ruby mty

  • 1. Functional Programming Concepts and Ruby Adrian Francke (@adrian2112)
  • 2. Why I started to learn functional programming 1. Interesting and useful concepts for general software development 2. For fun Structure and Interpretation of Computer Programs (SICP) http://en.wikipedia.org/wiki/ Structure_and_Interpretation_of_Computer_Programs
  • 3. 1. Interesting and useful concepts for general software development 2. For fun Structure and Interpretation of Computer Programs (SICP) http://en.wikipedia.org/wiki/ Structure_and_Interpretation_of_Computer_Programs (3. Hipster) Why I started to learn functional programming
  • 4. Goal of this talk 1. Show some functional programming concepts which can be used in your day to day programming in a non-functional programming language 2. Get you interested in functional programming
  • 5. What is functional programming? Declarative vs Imperative Functional Programming is a kind of declarative programming Imperative “Describes computation in terms of statements that change a program state (...) describing how a program operates.” http://en.wikipedia.org/wiki/Imperative_programming Declarative “A style of building the structure and elements of computer programs, that expresses the logic of a computation without describing its control flow. (...) describing what the program should accomplish (...), rather than describing how” http://en.wikipedia.org/wiki/Declarative_programming
  • 8. Functional Programming concepts: Recursion ● Is a method where the solution to a problem depends on solutions to smaller instances of the same problem ● Recursion, see Recursion ● Recursion is heavily used in functional programming as it is the canonical and often the only way to iterate Image from: http://learnyouahaskell.com/
  • 10. Functional Programming concepts: Higher order functions ● Functions that take other functions as their arguments ● Functions that returns other functions
  • 11. Functional Programming concepts: Higher order functions ● Higher order function example ● accumulate from http://mitpress.mit.edu/sicp/full-text/book/ book-Z-H-15.html#%_sec_2.2.3
  • 12. Functional Programming concepts: Purity ● Referential transparency ● Lazy evaluation
  • 13. Functional Programming concepts: Referential transparency ● A program (or function) that has the same effects and output on the same input ● Allows the programmer and the compiler to reason about program behavior ● Try to make all functions referential transparent and keep the side effects in one place
  • 14. Functional Programming concepts: Referential transparency Useful Useless Unsafe (side effects everywhere) Safe (Limited side effects) • C • Java • … “normal” languages • Haskell • (probably other pure funcional laguages) https://www.youtube.com/watch?v=iSmkqocn0oQ Future
  • 15. Functional Programming concepts: Referential transparency ● A pure function can always be replaced by its result. ● There’s no difference between Math.cos(Math::PI) and -1.0 ● A function which calls an impure function is impure as well. Impurity is contagious http://www.sitepoint.com/functional-programming-pure- functions/
  • 16. Functional Programming concepts: Referential transparency Example from: http://valve.github.io/blog/2014/07/04/from-object-to-functional-immutability/ Referential opaque Referential transparent
  • 17. Functional Programming concepts: Referential transparency ● Easy to test (it does not depend on anything but its input) ● Easy maintenance ● Concurrency/parallelization
  • 18. Functional Programming concepts: Referential transparency Example from: http://www.sitepoint.com/functional-programming-pure-functions Same function. Only if it is a pure function
  • 19. Functional Programming concepts: Lazy evaluation ● Pure functions can be performed at any time and still yield the same result. ● Defer the computation of values until they are needed ● Example
  • 20. Which of this concepts I use in ruby and how ● Higher order functions o map o reduce o select o find ● Pure functions (referential transparency)
  • 21. Use attr_reader instead of attr_accessor so once defined it cannot be changed
  • 22. Keep side effects in one place
  • 23. Use of higher order functions
  • 24. This functions depend on self.date. Should I send the date as parameter?
  • 25. Current stand = Lets take this functions as “curried” or partially applied with the objects date. self.date not modifiable
  • 26. Conclusions ● Learn new approaches to solve problems ● Try functional programing!! ● It will help you to create better code. A language that doesn’t affect the way you think about programming, is not worth knowing. — Alan Perlis
  • 27. Resources ● Structure and Interpretation of Computer Programs (SICP) http:// mitpress.mit.edu/sicp/full-text/book/book-Z-H-38.html# %_index_start ● Programming with Nothing http://codon.com/programming-with- nothing
  • 28. References ● Haskell wiki https://wiki.haskell.org/Functional_programming ● Composing programs (Higher order functions) http:// www.composingprograms.com/pages/16-higher-order- functions.html ● Learn You a Haskell for Great Good! http://learnyouahaskell.com ● http://www.sitepoint.com/functional-programming-pure-functions/