SlideShare a Scribd company logo
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

PPTX
Flow control in Python
Md. Shafiuzzaman Hira
 
PPTX
C#
Norhan Said
 
PPTX
C#
Norhan Said
 
PPTX
C#
Norhan Said
 
PPTX
Android with kotlin course
Abdul Rahman Masri Attal
 
PDF
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
Codemotion
 
PPTX
Why functional programming in C# & F#
Riccardo Terrell
 
PDF
Design concerns for concrete syntax
Mikhail Barash
 
Flow control in Python
Md. Shafiuzzaman Hira
 
Android with kotlin course
Abdul Rahman Masri Attal
 
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
Codemotion
 
Why functional programming in C# & F#
Riccardo Terrell
 
Design concerns for concrete syntax
Mikhail Barash
 

What's hot (20)

PDF
EclipseCon 2015 - Generating business applications from executable models
Rafael Chaves
 
PDF
JDT embraces lambda expressions
Eclipse Day India
 
PPTX
Laravel 5 and SOLID
Igor Talevski
 
PDF
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Ranel Padon
 
PDF
Lo1
liankei
 
PDF
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 
PPTX
Modern Static Code Analysis in PHP
Vladimir Reznichenko
 
PDF
JDT Embraces Lambda Expressions - EclipseCon North America 2014
Noopur Gupta
 
PPTX
Concurrent Applications with F# Agents
Rachel Reese
 
PDF
Swift, a quick overview
Julian Król
 
PDF
Python for Swift
LINE Corporation
 
PPTX
Oop is not Dead
Hernan Wilkinson
 
PPTX
Functional Programming in JavaScript & ESNext
Unfold UI
 
PDF
New c sharp4_features_part_v
Nico Ludwig
 
PDF
Python Programming - III. Controlling the Flow
Ranel Padon
 
PPTX
Tech for devs, F#
Robert Rohr
 
PDF
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Dimitris Kolovos
 
PPTX
Immutable data structures - A Primer
binDebug WorkSpace
 
PPTX
Code: from Procedural to Object Oriented
kleinron
 
PDF
Pharo: A Reflective System
Marcus Denker
 
EclipseCon 2015 - Generating business applications from executable models
Rafael Chaves
 
JDT embraces lambda expressions
Eclipse Day India
 
Laravel 5 and SOLID
Igor Talevski
 
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
Ranel Padon
 
Lo1
liankei
 
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 
Modern Static Code Analysis in PHP
Vladimir Reznichenko
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
Noopur Gupta
 
Concurrent Applications with F# Agents
Rachel Reese
 
Swift, a quick overview
Julian Król
 
Python for Swift
LINE Corporation
 
Oop is not Dead
Hernan Wilkinson
 
Functional Programming in JavaScript & ESNext
Unfold UI
 
New c sharp4_features_part_v
Nico Ludwig
 
Python Programming - III. Controlling the Flow
Ranel Padon
 
Tech for devs, F#
Robert Rohr
 
Developing a new Epsilon Language through Grammar Extension: The Epsilon Dem...
Dimitris Kolovos
 
Immutable data structures - A Primer
binDebug WorkSpace
 
Code: from Procedural to Object Oriented
kleinron
 
Pharo: A Reflective System
Marcus Denker
 
Ad

Similar to Functional programming ruby mty (20)

PDF
Functional programming
Hideshi Ogoshi
 
PPTX
Functional programmning
Ayat_Khraisat
 
PDF
Functional programming
ijcd
 
PDF
Introduction to functional programming
Konrad Szydlo
 
PDF
Functional Programming Principles & Patterns
zupzup.org
 
PDF
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
PDF
Teach Yourself some Functional Programming with Scala
Damian Jureczko
 
PPTX
Good functional programming is good programming
kenbot
 
PPTX
Functional Paradigm.pptx
FurretMaster
 
PDF
Functional Programming for Busy Object Oriented Programmers
Diego Freniche Brito
 
PDF
Functional Go
Geison Goes
 
PPTX
Functional programming
Prashant Kalkar
 
PDF
Functional Programming #FTW
Adriano Bonat
 
PDF
A (very brief) into to Functional Programming
Brooklyn Zelenka
 
PPTX
Functional Programming Introduction
Roberto Lopez
 
PPTX
When life gives you functions make functional programs!
Aaron Levin
 
PDF
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
PDF
Thinking Functionally
Piyush Katariya
 
PDF
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
PPTX
Functional programming and ruby in functional style
Niranjan Sarade
 
Functional programming
Hideshi Ogoshi
 
Functional programmning
Ayat_Khraisat
 
Functional programming
ijcd
 
Introduction to functional programming
Konrad Szydlo
 
Functional Programming Principles & Patterns
zupzup.org
 
Functional Objects in Ruby: new horizons – Valentine Ostakh
Ruby Meditation
 
Teach Yourself some Functional Programming with Scala
Damian Jureczko
 
Good functional programming is good programming
kenbot
 
Functional Paradigm.pptx
FurretMaster
 
Functional Programming for Busy Object Oriented Programmers
Diego Freniche Brito
 
Functional Go
Geison Goes
 
Functional programming
Prashant Kalkar
 
Functional Programming #FTW
Adriano Bonat
 
A (very brief) into to Functional Programming
Brooklyn Zelenka
 
Functional Programming Introduction
Roberto Lopez
 
When life gives you functions make functional programs!
Aaron Levin
 
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
Thinking Functionally
Piyush Katariya
 
Beyond PITS, Functional Principles for Software Architecture
Jayaram Sankaranarayanan
 
Functional programming and ruby in functional style
Niranjan Sarade
 
Ad

Recently uploaded (20)

PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPT
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PPTX
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Exploring AI Agents in Process Industries
amoreira6
 
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
A REACT POMODORO TIMER WEB APPLICATION.pdf
Michael624841
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 

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
  • 7. Examples Imperative Functional Imperative: http://www.siafoo.net/snippet/306 Functional: http://en.literateprograms.org/Quicksort_%28Haskell%29
  • 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/