SlideShare a Scribd company logo
1 of 36
1
http://cowbirdsinlove.com/43
2
FP vs OOP :
Design Methodology
Compairing Data Abstraction techiniques employed by
Objects Oriented Programming and Abstract Data Types
Harshad Nawathe
3
Something about me...
● I ♡ Programming.
● Like to learn new programming languages.
○ Languages I know :
[“C++”, “C”, “Python”, “Haskell”, “Ruby”, “Go”, “Rust”]++[“Java”]
○ Wish list so far : [“D”, “Erlang”, “Clojure”] ++ manyMoreToCome
● Currently working on Barclaycard - UK project.
4
Object Orientation is a hoax !!!
5
Object Orientation is a Hoax!
● Alexander Stepanov used this interesting phrase.
● http://c2.com/cgi/wiki?ObjectOrientationIsaHoax
● Full interview: http://www.stlport.org/resources/StepanovUSA.html
6
Who is Alexander Stepanov ?
● Russian Mathematician
● Programmer by profession
● Advocate of Generic Programming
style
● Primary designer and implementer of
C++ Standard Template Library
● Wrote 2 fantastic books on
programming
○ Elements of Programming
○ From Mathematics to Generic Programming
https://upload.wikimedia.org/wikipedia/commons/th
umb/1/1c/Alexander_Stepanov.jpg/250px-
Alexander_Stepanov.jpg
7
Question:I think STL and Generic Programming mark a definite departure from the common C++
programming style, which I find is almost completely derived from SmallTalk. Do you agree?
Answer: Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as
Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In
a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really
fundamental work: BillGosper's Hakmem is one of the best things for a programmer to read. AI might not
have had a serious foundation, but it produced Gosper and RichardStallman (Emacs), Moses
(Macsyma) and GeraldSussman (Scheme, together with GuySteele). I find OOP technically unsound. It
attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real
problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP
philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting -
saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts
with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start
with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You
end with axioms. The same thing is true in programming: you have to start with interesting algorithms.
Only when you understand them well, can you come up with an interface that will let them work.
http://c2.com/cgi/wiki?ObjectOrientationIsaHoax
8
Question:I think STL and Generic Programming mark a definite departure from the common C++
programming style, which I find is almost completely derived from SmallTalk. Do you agree?
Answer: Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as
Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In
a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really
fundamental work: BillGosper's Hakmem is one of the best things for a programmer to read. AI might not
have had a serious foundation, but it produced Gosper and RichardStallman (Emacs), Moses
(Macsyma) and GeraldSussman (Scheme, together with GuySteele). I find OOP technically unsound. It
attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real
problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP
philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting -
saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts
with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start
with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You
end with axioms. The same thing is true in programming: you have to start with interesting algorithms.
Only when you understand them well, can you come up with an interface that will let them work.
http://c2.com/cgi/wiki?ObjectOrientationIsaHoax
9
Data Abstraction
● “It attempts to decompose the world in terms of interfaces that vary on a
single type”
● “multisorted algebras - families of interfaces that span multiple types.”
OOP
Abstract Data Type = ADT
● Technique for defining and manipulating data in abstract fashion
● It deals with conceptual view of properties of data
● Abstract type can be a “type” that is conceived apart from the concrete
realities
10
11
● This paper provides the core for this talk
https://www.cs.utexas.edu/users/wcook/papers/OOPvsADT/CookOOPvsADT90.pdf
Course of Action
● Implement a data abstraction for List of integers using both methods
● Compare the implementation using following criteria
○ Extending the implementation by adding more concrete implementation
○ Extending the implementation by adding more operations
○ Optimization
12
Implementation
13
Implementation using OOP
14
List
isEmpty():bool
length():int
head():int
tail():List
EmptyList()
true
0
error
error
LinkedList(data:int, next:List)
false
1 + self.next.length()
self.data
self.next
⛔ ⛔ ⛔
✅
✅
✅
✅
✅
Abstract Type Concrete Implementations
Observations
● Primary mechanism is “Procedural Abstraction”
● Objects can be called as PDAs - Procedural Data Abstraction
● Data is abstract because it is accessed from a Procedural Interface
● PDAs are organized around constructors
● Observations become attributes and methods of the procedural data
values
● Procedural data value is defined as combination of all the possible
observations on it
15
Implementation using OOP - Remarks
Implementation using ADT
16
List Nil Cons(x:Int, t’:List)
Abstract Type Concrete Types
nil :: List -> Bool True False
length :: List -> Int 0 1 + (length t’)
head :: List -> Int error x
tail :: List -> List error t’
Observations
✅ ✅ ✅
⛔
⛔
⛔
⛔
⛔
17
module MyList
( IntList
, makeNil
, appendTo
, head
, tail
, length
, nil
) where
-- Data
data IntList = Nil | Cons Int IntList deriving(Show)
-- Constructor functions
makeNil :: IntList
makeNil = Nil
appendTo :: Int -> IntList -> IntList
appendTo = Cons
18
-- Operations
head :: IntList -> Int
head Nil = error "head called on Nil Int List"
head (Cons x _) = x
tail :: IntList -> IntList
tail Nil = error "tail called on Nil Int List"
tail (Cons _ xs) = xs
length :: IntList -> Int
length Nil = 0
length (Cons _ xs) = 1 + (length' xs)
nil :: IntList -> Bool
nil Nil = True
nil (Cons _ _) = False
Implementation using ADT - Remarks
● Primary mechanism is Type Abstraction
● Data abstraction is achieved by “opaque” types
● ADTs are organized around observations
● Each observation defined as the operation upon the concrete
representation derived from the constructors
● Constructors are also defined as operations that create values in
represenation types
● Representation is shared among the operations, but hidden from the
clients of the ADT
19
Extensibility
20
Summary
● OOP
○ New concrete representations of abstract data can be added.
○ New operations cannot be added
● ADT
○ New operations can be added
○ New concrete representations cannot be added
21
Optimization
22
Optimizing ADTs
● As operations can inspect the representations of the arguments it is easy
to improve efficiency of the operations
23
24
data IntList = Nil | Cons Int IntList | IntRange Int Word deriving(Show)
instance Eq IntList where
(==) Nil Nil = True
(==) _ Nil = False
(==) Nil _ = False
(==) (IntRange f1 n1) (IntRange f2 n2) = (f1 == f2) && (n1 == n2)
(==) list1 list2 = (head1 == head2) && (tail1 == tail2)
where head1 = head list1
head2 = head list2
tail1 = tail list1
tail2 = tail list2
Optimizing PDAs
25
● Optimizing operations is difficult as the representation of the argument
cannot be inspected
26
interface IntList {
boolean empty();
int size();
int head();
IntList tail();
boolean checkIfEquals(IntList rhs);
}
27
public boolean checkIfEquals(IntList rhs) {
IntList lhs = this;
while( !lhs.empty() && !rhs.empty() ) {
if( lhs.head() != rhs.head() ) return false;
lhs = lhs.tail();
rhs = rhs.tail();
}
return lhs.empty() && rhs.empty();
}
What if …
IntList list1 = new IntRange(1, 1000000 );
IntList list2 = new IntRange(1, 1000001 );
list1.checkIfEqual(list2);
Tyranny of Dominant Decomposition
28
29
● The limitation of OOP is one has to choose a fixed decomposition of the
system in the design of class hierarchy
● Example:
Classifications of Trees and Plants from the view of Lumberjack and Bird.
Tree
HardWood SoftWood
Cherry Mahogany PineMango
View of a Lumberjack
Plant
NectorPlant
Cherry
View of a Bird
InsectsPlant
Pine MahoganyMango
30
Typeclasses
class Tree a where
treeFunction1 :: a -> Int
treeFunction2 :: a -> b -> Bool
.
.
class Tree a => HardWood where
hardwoodFunction :: a -> [b]
class Tree a => SoftWood where
softwoodFunction :: a -> [b]
class Plant a where
plantFunction1 :: a -> Int
plantFunction2 :: a -> String
.
.
class Plant a => NectorPlant where
sweetness :: a -> Int
class Plant a => InsectPlant where
insectTypes :: a -> [b]
Instantiation
instance HardWood CherryTree where
treeFunction1 …
treeFunction2 …
hardwoodFunction ...
instance NectorPlant CherryTree where
plantFunction1 …
plantFunction2 …
sweetness ...
31
type SomeCherryTreeAttributes = ( Int, Int, String, ….. )
data CherryTree = CherryTree SomeCherryTreeAttributes
A Real Life Example
32http://www.karambelkar.info/downloads/java_collections/Java-Collections_API-List-ImageMap.html
Quiz
● Is someFunction is of Quadratic complexity ?
public static void someFunction(List<String> list ) {
int[] indices = ….;
for( int index : indices ) {
list.get(index);
}
}
● What is the complexity of
java.util.collections.binarySearch(List< T > … )
33
ADT approach
● Standard Template Library in C++
● Divided between Containers, Algorithms and Iterators.
● STL is not OO
● Algorithms are defined using iterators
● Iterators encapsulate access to Containers
● Container types
○ Sequence containers: array, forward_list, list, vector, deque
○ Container adaptors: stack, queue, priority_queue
○ Associative containers (ordered): set, map, multiset, multimap
34
35
forward
_list
list vector array
Forward Range
Bidirectional
Range
Random Range
Single Pass algorithms
eg. for_each, transform, copy, find, rotate etc.
Algorithms with bidirectional access
eg. reverse, partition*
Random access algorithms
eg. sort, binary_search etc
Thank You!
harshadn@thoughtworks.com
36

More Related Content

Similar to FP vs OOP : Design Methodology by Harshad Nawathe

Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Evolving as a professional software developer
Evolving as a professional software developerEvolving as a professional software developer
Evolving as a professional software developerAnton Kirillov
 
On being a professional software developer
On being a professional software developerOn being a professional software developer
On being a professional software developerAnton Kirillov
 
Антон Кириллов, ZeptoLab
Антон Кириллов, ZeptoLabАнтон Кириллов, ZeptoLab
Антон Кириллов, ZeptoLabDiana Dymolazova
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with pythonPorimol Chandro
 
It Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaIt Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaKevlin Henney
 
Discussion forum unit 6 - Software Engineering 2.docx
Discussion forum unit 6 - Software Engineering 2.docxDiscussion forum unit 6 - Software Engineering 2.docx
Discussion forum unit 6 - Software Engineering 2.docxwilsonchandiga1
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
Artificial Intelligence - Anna Uni -v1.pdf
Artificial Intelligence - Anna Uni -v1.pdfArtificial Intelligence - Anna Uni -v1.pdf
Artificial Intelligence - Anna Uni -v1.pdfJayanti Prasad Ph.D.
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
Objects & OO Thinking for Java
Objects & OO Thinking for JavaObjects & OO Thinking for Java
Objects & OO Thinking for JavaJeff Sonstein
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.pptMikeAdva
 

Similar to FP vs OOP : Design Methodology by Harshad Nawathe (20)

Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Evolving as a professional software developer
Evolving as a professional software developerEvolving as a professional software developer
Evolving as a professional software developer
 
On being a professional software developer
On being a professional software developerOn being a professional software developer
On being a professional software developer
 
Антон Кириллов, ZeptoLab
Антон Кириллов, ZeptoLabАнтон Кириллов, ZeptoLab
Антон Кириллов, ZeptoLab
 
Intro_2.ppt
Intro_2.pptIntro_2.ppt
Intro_2.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with python
 
Python training
Python trainingPython training
Python training
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Python for web security - beginner
Python for web security - beginnerPython for web security - beginner
Python for web security - beginner
 
It Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaIt Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in Java
 
Discussion forum unit 6 - Software Engineering 2.docx
Discussion forum unit 6 - Software Engineering 2.docxDiscussion forum unit 6 - Software Engineering 2.docx
Discussion forum unit 6 - Software Engineering 2.docx
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Artificial Intelligence - Anna Uni -v1.pdf
Artificial Intelligence - Anna Uni -v1.pdfArtificial Intelligence - Anna Uni -v1.pdf
Artificial Intelligence - Anna Uni -v1.pdf
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Objects & OO Thinking for Java
Objects & OO Thinking for JavaObjects & OO Thinking for Java
Objects & OO Thinking for Java
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

FP vs OOP : Design Methodology by Harshad Nawathe

  • 1. 1
  • 3. FP vs OOP : Design Methodology Compairing Data Abstraction techiniques employed by Objects Oriented Programming and Abstract Data Types Harshad Nawathe 3
  • 4. Something about me... ● I ♡ Programming. ● Like to learn new programming languages. ○ Languages I know : [“C++”, “C”, “Python”, “Haskell”, “Ruby”, “Go”, “Rust”]++[“Java”] ○ Wish list so far : [“D”, “Erlang”, “Clojure”] ++ manyMoreToCome ● Currently working on Barclaycard - UK project. 4
  • 5. Object Orientation is a hoax !!! 5
  • 6. Object Orientation is a Hoax! ● Alexander Stepanov used this interesting phrase. ● http://c2.com/cgi/wiki?ObjectOrientationIsaHoax ● Full interview: http://www.stlport.org/resources/StepanovUSA.html 6
  • 7. Who is Alexander Stepanov ? ● Russian Mathematician ● Programmer by profession ● Advocate of Generic Programming style ● Primary designer and implementer of C++ Standard Template Library ● Wrote 2 fantastic books on programming ○ Elements of Programming ○ From Mathematics to Generic Programming https://upload.wikimedia.org/wikipedia/commons/th umb/1/1c/Alexander_Stepanov.jpg/250px- Alexander_Stepanov.jpg 7
  • 8. Question:I think STL and Generic Programming mark a definite departure from the common C++ programming style, which I find is almost completely derived from SmallTalk. Do you agree? Answer: Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: BillGosper's Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and RichardStallman (Emacs), Moses (Macsyma) and GeraldSussman (Scheme, together with GuySteele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work. http://c2.com/cgi/wiki?ObjectOrientationIsaHoax 8
  • 9. Question:I think STL and Generic Programming mark a definite departure from the common C++ programming style, which I find is almost completely derived from SmallTalk. Do you agree? Answer: Yes. STL is not object oriented. I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people. In a sense, I am unfair to AI: I learned a lot of stuff from the MIT AI Lab crowd, they have done some really fundamental work: BillGosper's Hakmem is one of the best things for a programmer to read. AI might not have had a serious foundation, but it produced Gosper and RichardStallman (Emacs), Moses (Macsyma) and GeraldSussman (Scheme, together with GuySteele). I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work. http://c2.com/cgi/wiki?ObjectOrientationIsaHoax 9
  • 10. Data Abstraction ● “It attempts to decompose the world in terms of interfaces that vary on a single type” ● “multisorted algebras - families of interfaces that span multiple types.” OOP Abstract Data Type = ADT ● Technique for defining and manipulating data in abstract fashion ● It deals with conceptual view of properties of data ● Abstract type can be a “type” that is conceived apart from the concrete realities 10
  • 11. 11 ● This paper provides the core for this talk https://www.cs.utexas.edu/users/wcook/papers/OOPvsADT/CookOOPvsADT90.pdf
  • 12. Course of Action ● Implement a data abstraction for List of integers using both methods ● Compare the implementation using following criteria ○ Extending the implementation by adding more concrete implementation ○ Extending the implementation by adding more operations ○ Optimization 12
  • 14. Implementation using OOP 14 List isEmpty():bool length():int head():int tail():List EmptyList() true 0 error error LinkedList(data:int, next:List) false 1 + self.next.length() self.data self.next ⛔ ⛔ ⛔ ✅ ✅ ✅ ✅ ✅ Abstract Type Concrete Implementations Observations
  • 15. ● Primary mechanism is “Procedural Abstraction” ● Objects can be called as PDAs - Procedural Data Abstraction ● Data is abstract because it is accessed from a Procedural Interface ● PDAs are organized around constructors ● Observations become attributes and methods of the procedural data values ● Procedural data value is defined as combination of all the possible observations on it 15 Implementation using OOP - Remarks
  • 16. Implementation using ADT 16 List Nil Cons(x:Int, t’:List) Abstract Type Concrete Types nil :: List -> Bool True False length :: List -> Int 0 1 + (length t’) head :: List -> Int error x tail :: List -> List error t’ Observations ✅ ✅ ✅ ⛔ ⛔ ⛔ ⛔ ⛔
  • 17. 17 module MyList ( IntList , makeNil , appendTo , head , tail , length , nil ) where -- Data data IntList = Nil | Cons Int IntList deriving(Show) -- Constructor functions makeNil :: IntList makeNil = Nil appendTo :: Int -> IntList -> IntList appendTo = Cons
  • 18. 18 -- Operations head :: IntList -> Int head Nil = error "head called on Nil Int List" head (Cons x _) = x tail :: IntList -> IntList tail Nil = error "tail called on Nil Int List" tail (Cons _ xs) = xs length :: IntList -> Int length Nil = 0 length (Cons _ xs) = 1 + (length' xs) nil :: IntList -> Bool nil Nil = True nil (Cons _ _) = False
  • 19. Implementation using ADT - Remarks ● Primary mechanism is Type Abstraction ● Data abstraction is achieved by “opaque” types ● ADTs are organized around observations ● Each observation defined as the operation upon the concrete representation derived from the constructors ● Constructors are also defined as operations that create values in represenation types ● Representation is shared among the operations, but hidden from the clients of the ADT 19
  • 21. Summary ● OOP ○ New concrete representations of abstract data can be added. ○ New operations cannot be added ● ADT ○ New operations can be added ○ New concrete representations cannot be added 21
  • 23. Optimizing ADTs ● As operations can inspect the representations of the arguments it is easy to improve efficiency of the operations 23
  • 24. 24 data IntList = Nil | Cons Int IntList | IntRange Int Word deriving(Show) instance Eq IntList where (==) Nil Nil = True (==) _ Nil = False (==) Nil _ = False (==) (IntRange f1 n1) (IntRange f2 n2) = (f1 == f2) && (n1 == n2) (==) list1 list2 = (head1 == head2) && (tail1 == tail2) where head1 = head list1 head2 = head list2 tail1 = tail list1 tail2 = tail list2
  • 25. Optimizing PDAs 25 ● Optimizing operations is difficult as the representation of the argument cannot be inspected
  • 26. 26 interface IntList { boolean empty(); int size(); int head(); IntList tail(); boolean checkIfEquals(IntList rhs); }
  • 27. 27 public boolean checkIfEquals(IntList rhs) { IntList lhs = this; while( !lhs.empty() && !rhs.empty() ) { if( lhs.head() != rhs.head() ) return false; lhs = lhs.tail(); rhs = rhs.tail(); } return lhs.empty() && rhs.empty(); } What if … IntList list1 = new IntRange(1, 1000000 ); IntList list2 = new IntRange(1, 1000001 ); list1.checkIfEqual(list2);
  • 28. Tyranny of Dominant Decomposition 28
  • 29. 29 ● The limitation of OOP is one has to choose a fixed decomposition of the system in the design of class hierarchy ● Example: Classifications of Trees and Plants from the view of Lumberjack and Bird. Tree HardWood SoftWood Cherry Mahogany PineMango View of a Lumberjack Plant NectorPlant Cherry View of a Bird InsectsPlant Pine MahoganyMango
  • 30. 30 Typeclasses class Tree a where treeFunction1 :: a -> Int treeFunction2 :: a -> b -> Bool . . class Tree a => HardWood where hardwoodFunction :: a -> [b] class Tree a => SoftWood where softwoodFunction :: a -> [b] class Plant a where plantFunction1 :: a -> Int plantFunction2 :: a -> String . . class Plant a => NectorPlant where sweetness :: a -> Int class Plant a => InsectPlant where insectTypes :: a -> [b]
  • 31. Instantiation instance HardWood CherryTree where treeFunction1 … treeFunction2 … hardwoodFunction ... instance NectorPlant CherryTree where plantFunction1 … plantFunction2 … sweetness ... 31 type SomeCherryTreeAttributes = ( Int, Int, String, ….. ) data CherryTree = CherryTree SomeCherryTreeAttributes
  • 32. A Real Life Example 32http://www.karambelkar.info/downloads/java_collections/Java-Collections_API-List-ImageMap.html
  • 33. Quiz ● Is someFunction is of Quadratic complexity ? public static void someFunction(List<String> list ) { int[] indices = ….; for( int index : indices ) { list.get(index); } } ● What is the complexity of java.util.collections.binarySearch(List< T > … ) 33
  • 34. ADT approach ● Standard Template Library in C++ ● Divided between Containers, Algorithms and Iterators. ● STL is not OO ● Algorithms are defined using iterators ● Iterators encapsulate access to Containers ● Container types ○ Sequence containers: array, forward_list, list, vector, deque ○ Container adaptors: stack, queue, priority_queue ○ Associative containers (ordered): set, map, multiset, multimap 34
  • 35. 35 forward _list list vector array Forward Range Bidirectional Range Random Range Single Pass algorithms eg. for_each, transform, copy, find, rotate etc. Algorithms with bidirectional access eg. reverse, partition* Random access algorithms eg. sort, binary_search etc