Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Functional Geekery for an Imperative Mind
Search
Rajeev Bharshetty
April 04, 2015
Programming
0
260
Functional Geekery for an Imperative Mind
Slides for the talk at RubyConf India 2015
Rajeev Bharshetty
April 04, 2015
Tweet
Share
More Decks by Rajeev Bharshetty
See All by Rajeev Bharshetty
SPDY : Let's Make the Web Faster
rshetty01
2
170
Other Decks in Programming
See All in Programming
Node.js, Deno, Bun 最新動向とその所感について
yosuke_furukawa
PRO
6
2.9k
英語文法から学ぶ、クリーンな設計の秘訣
newnomad
1
260
DenoでOpenTelemetryに入門する
yotahada3
2
270
「その気にさせる」エンジニアが 最強のリーダーになる理由
gimupop
3
450
AHC 044 混合整数計画ソルバー解法
kiri8128
0
260
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
2
720
PHPUnit 高速化テクニック / PHPUnit Speedup Techniques
pinkumohikan
1
650
CIBMTR振り返り+敗北から学ぶコンペの取り組み方反省
takanao
1
490
Scala 3 で GLSL のための c-like-for を実装してみた
exoego
1
160
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
1
260
Compose Navigation実装の見通しを良くする
hiroaki404
0
130
PHPer's Guide to Daemon Crafting Taming and Summoning
uzulla
2
540
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
A designer walks into a library…
pauljervisheath
205
24k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
101
18k
Being A Developer After 40
akosma
89
590k
Gamification - CAS2011
davidbonilla
80
5.2k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Agile that works and the tools we love
rasmusluckow
328
21k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
It's Worth the Effort
3n
184
28k
Transcript
FUNCTIONAL GEEKERY FOR AN IMPERATIVE MIND Rajeev N B
@rshetty on Github @rbharshetty on Twitter
None
SIMON PEYTON JONES
NIRVANA C, C++, Java, Ruby .. Haskell Nirvana Useful Less
Useful Unsafe Safe
IMPERATIVE VS FUNCTIONAL
PROPERTY IMPERATIVE FUNCTIONAL FOCUS Changing existing values Declaring new values
CONTROL FLOW Loops, Conditionals and Function calls Functional calls including Recursion MANIPULATION UNIT Instances of classes and structs Functions and Data Structures. MENTAL MODEL Algorithmic Programming Composing problems with set of functions.
FUNCTIONAL PROGRAMMING?
– John Hughes (Why Functional Programming Matters) “Functional Programming is
so called because a program consists entirely of functions”
CONCEPTS
FUNCTION COMPOSITION (F O G)
It is the act of pipelining result of a function
into input of another, creating a new function
Function g(x) x + 1 Function f(x) x * x
x = 3 g(x)= 4 f(g(x))= 16
None
None
It is the act of pipelining result of a function
into input of with another, creating a new function
None
None
None
LAZY EVALUATION
Evaluation of a expression is deferred until the result is
needed by other computations
LAZY EVALUATION Call by need Infinite Data structures Thunks Performant
HIGHER ORDER FUNCTIONS
Functions which either take functions as arguments or return functions
as return values
None
None
CURRYING
Transforming function that takes multiple arguments into function that takes
single argument
None
None
PURE FUNCTION
Function that returns exactly the same result every time it
is called with same set of arguments
Pure Function f(x) = Math.cos(x) Pure Function ( No Side
Effects ) x f(x)
None
REFERENTIAL TRANSPARENCY Expression is referentially transparent if it can be
replaced with its value Property of Pure functions No side effects Easier to reason about programs
WHY PURE FUNCTIONS? Reproducible results Memoization Parallelization
IMMUTABILITY
Immutable object is an object whose state cannot be modified
after it is created
IMMUTABLE DATA STRUCTURES Data structure once created cannot be modified
Uses sophisticated structure sharing
WHY? Concurrency Security
FUNCTIONAL THINKING
REFERENCES Haskell Wiki Learn You a Haskell Ruby Function Composition
Resurgence of Functional Programming Code samples
THANKS
QUESTIONS?