Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Oops! OOP's Not What I Thought

Oops! OOP's Not What I Thought

(Presented at Øredev 2018, DomCode 2016)

In this talk we'll go on a historical and philosophical journey deep into the heart of object-oriented programming (OOP). Come along with me as I have my world shaken by the discovery that objects and classes are not the most important concepts in OOP: messages and late binding are. Join me as we try to peek inside the heads of Alan Kay and the other founders of the paradigm as they were developing early object-oriented languages like Smalltalk, only to discover that those "old" ideas seem strikingly relevant today. We may even feel our jaws drop as we realize that OOP and functional programming are not as different as we may have thought, and that the first object-oriented language was not created in the 60's or 70's but much, much earlier…

What awaits us at the end of this journey? At worst, we'll experience a brief crisis of faith in everything we ever thought we knew about programming. (A support group will meet after the conference.) At best, we'll shift the way we view this near-ubiquitous but oft-misunderstood programming paradigm, and walk away with new insights for how we architect and understand our code.

Anjana Sofia Vakil

November 04, 2016
Tweet

More Decks by Anjana Sofia Vakil

Other Decks in Programming

Transcript

  1. oops!
    OOP’s not what I thought
    @AnjanaVakil
    Øredev 2018

    View Slide

  2. @AnjanaVakil
    hi, I’m Anjana!
    - philosophy grad
    - English language teacher
    - computational linguist
    - software developer

    View Slide

  3. @AnjanaVakil
    hi, I’m Anjana!
    live location data platform
    for developers
    mapbox.com

    View Slide

  4. @AnjanaVakil
    hi, I’m Anjana!
    events.mozilla.org
    /techspeakers
    outreachy.org

    View Slide

  5. @AnjanaVakil
    hi, I’m Anjana!
    The Recurse Center
    recurse.com

    View Slide

  6. @AnjanaVakil
    hi, I’m Anjana!
    ...and I had OOP all wrong

    View Slide

  7. @AnjanaVakil
    object-
    oriented
    programming
    objects (!)
    classes
    inheritance
    hierarchy
    C++, Java

    View Slide

  8. @AnjanaVakil
    object-
    oriented
    programming
    objects (!)
    classes
    inheritance
    hierarchy
    C++, Java

    View Slide

  9. @AnjanaVakil
    object-
    oriented
    programming
    ?

    View Slide

  10. @AnjanaVakil
    Photo by Marcin Wichary from San Francisco, U.S.A. (Alan Kay and the prototype of Dynabook, pt. 5)
    [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
    Alan
    Kay
    @AnjanaVakil

    View Slide

  11. @AnjanaVakil
    Alan
    Kay
    coiner of
    “object-
    oriented”
    @AnjanaVakil

    View Slide

  12. @AnjanaVakil
    Alan
    Kay
    (co-)creator of
    Smalltalk
    @AnjanaVakil

    View Slide

  13. @AnjanaVakil
    Alan
    Kay
    personal
    computing
    pioneer
    Dynabook
    @AnjanaVakil

    View Slide

  14. @AnjanaVakil
    Alan
    Kay
    undergrad
    biology major
    @AnjanaVakil

    View Slide

  15. @AnjanaVakil
    biological metaphors
    oops #1:

    View Slide

  16. @AnjanaVakil
    what I
    thought
    inheritance
    taxonomy

    View Slide

  17. @AnjanaVakil
    what it is
    cells
    organs

    View Slide

  18. @AnjanaVakil
    procedural
    imperative
    “Clocks Gears Wallpaper” via Wallpoper (http://wallpoper.com/images/00/38/51/35/clocks-gears_00385135.jpg) @AnjanaVakil

    View Slide

  19. @AnjanaVakil
    object-
    oriented
    “Slide of the Week: Increased WBC, April 14, 2011” via Center for Genomic Pathology
    (http://ctrgenpath.net/wp-content/uploads/2011/04/cml02.jpg) @AnjanaVakil

    View Slide

  20. @AnjanaVakil

    View Slide

  21. @AnjanaVakil

    View Slide

  22. @AnjanaVakil
    big ideas
    oops #2:

    View Slide

  23. @AnjanaVakil
    what I
    thought
    objects(!)
    classes

    View Slide

  24. @AnjanaVakil
    Alan
    Kay
    “I'm sorry that I long
    ago coined the
    term "objects" for
    this topic because it
    gets many people to
    focus on the
    lesser idea.
    @AnjanaVakil

    View Slide

  25. @AnjanaVakil
    Alan
    Kay
    “The big idea is
    "messaging"”
    - To Smalltalk/Squeak
    mailing list, 1998
    wiki.c2.com/?AlanKayOnMessaging
    @AnjanaVakil

    View Slide

  26. @AnjanaVakil
    what it is
    messaging
    late-binding

    View Slide

  27. @AnjanaVakil
    objects
    @AnjanaVakil

    View Slide

  28. @AnjanaVakil
    messages
    “Dopamine D3 receptor” via Orientation of Proteins in Membranes Database
    (http://opm.phar.umich.edu/images/png/3pbl.png) @AnjanaVakil

    View Slide

  29. @AnjanaVakil
    systems
    Image by The Opte Project (Internet Map)
    [CC BY 2.5 (http://creativecommons.org/licenses/by/2.5)], via Wikimedia Commons @AnjanaVakil

    View Slide

  30. @AnjanaVakil
    thing.do(some,stuff)

    View Slide

  31. @AnjanaVakil
    to: thing
    subject: pretty please? :D
    message: "do", some, stuff

    View Slide

  32. @AnjanaVakil
    recipient message
    thing.do(some,stuff)

    View Slide

  33. @AnjanaVakil
    recipient message
    thing.do(some,stuff)
    method name arguments

    View Slide

  34. @AnjanaVakil
    Ruby
    thing.do(some,stuff)
    thing.send(:do,some,stuff)

    View Slide

  35. @AnjanaVakil
    what does do do? how?
    thing.do(some,stuff)
    thing.do(other,stuff)
    child.do(some,stuff)
    thing.do(some,stuff)

    View Slide

  36. @AnjanaVakil
    early
    binding
    @AnjanaVakil

    View Slide

  37. @AnjanaVakil
    late
    binding
    @AnjanaVakil

    View Slide

  38. @AnjanaVakil
    beings vs. behaviors
    oops #3:

    View Slide

  39. @AnjanaVakil
    what I
    thought
    objects
    are nouns

    View Slide

  40. @AnjanaVakil
    what it is objects
    are verbs

    View Slide

  41. @AnjanaVakil
    data
    @AnjanaVakil

    View Slide

  42. @AnjanaVakil
    behavior
    @AnjanaVakil

    View Slide

  43. @AnjanaVakil
    thing.do(stuff)
    => behavior

    View Slide

  44. @AnjanaVakil
    class Friend:
    def __init__(self, friends):
    self.friends = friends
    def is_friend_of(self, name):
    return name in self.friends
    buddy = Friend(['alan', 'alonzo'])
    buddy.is_friend_of('guy') => False

    View Slide

  45. @AnjanaVakil
    buddy.is_friend_of('guy')
    buddy.send(:is_friend_of, 'guy')

    View Slide

  46. @AnjanaVakil
    buddy.is_friend_of('guy')
    buddy.send(:is_friend_of, 'guy')
    buddy('is_friend_of', 'guy')

    View Slide

  47. @AnjanaVakil
    def Friend(friend_names):
    my_friends = friend_names
    def is_my_friend(name):
    return name in friend_names
    def responder(method_name, *args):
    if method_name == 'is_friend_of':
    return is_my_friend(args)
    return responder
    buddy = Friend(['alan', 'alonzo'])
    buddy('is_friend_of','guy') => False

    View Slide

  48. @AnjanaVakil
    def Friend(friend_names):
    my_friends = friend_names
    def is_my_friend(name):
    return name in friend_names
    def buddy(method_name, *args):
    if method_name == 'is_friend_of':
    return is_my_friend(*args)
    return responder
    buddy = Friend(['alan', 'alonzo'])
    buddy('is_friend_of','guy') => False

    View Slide

  49. @AnjanaVakil
    def Friend(friend_names):
    my_friends = friend_names
    def is_my_friend(name):
    return name in friend_names
    def buddy(method_name, *args):
    if method_name == 'is_friend_of':
    return is_my_friend(*args)
    return responder
    buddy = Friend(['alan', 'alonzo'])
    buddy('is_friend_of','guy') => False

    View Slide

  50. @AnjanaVakil
    def Friend(friend_names):
    my_friends = friend_names
    def is_my_friend(name):
    return name in friend_names
    def responder(method_name, *args):
    if method_name == 'is_friend_of':
    return is_my_friend(*args)
    return responder
    buddy = Friend(['alan', 'alonzo'])
    buddy('is_friend_of','guy') => False

    View Slide

  51. @AnjanaVakil
    boundaries
    oops #4:

    View Slide

  52. @AnjanaVakil
    what I
    thought
    imperative
    ----------
    object-otd
    ==========
    functional

    View Slide

  53. @AnjanaVakil
    what it is
    imperative
    ==========
    object-otd
    ----------
    functional

    View Slide

  54. @AnjanaVakil
    Smalltalk
    class True
    ifTrue: a ifFalse: b
    ^ a value
    class False
    ifTrue: a ifFalse: b
    ^ b value

    View Slide

  55. @AnjanaVakil
    Smalltalk
    class True
    ifTrue: a ifFalse: b
    ^ a value
    class False
    ifTrue: a ifFalse: b
    ^ b value
    Lambda calculus
    TRUE := λx.λy.x
    FALSE := λx.λy.y

    View Slide

  56. @AnjanaVakil
    Erlang
    Fred Hébert
    Learn You Some Erlang
    for Great Good
    learnyousomeerlang.com

    View Slide

  57. @AnjanaVakil
    JS "callbags"
    André Stalz
    "Callback Heaven",
    Amsterdam JSNation 2018
    youtu.be/HssczgaY9BM

    View Slide

  58. @AnjanaVakil
    belief structures
    oops #5:

    View Slide

  59. @AnjanaVakil
    what I
    thought
    dogmatic
    restrictive

    View Slide

  60. @AnjanaVakil
    what it is built for
    change
    *or should be

    View Slide

  61. @AnjanaVakil
    simplicity
    complexity
    @AnjanaVakil

    View Slide

  62. @AnjanaVakil
    resilience
    @AnjanaVakil

    View Slide

  63. @AnjanaVakil
    scalability
    @AnjanaVakil

    View Slide

  64. @AnjanaVakil
    Alan Kay:
    - The early history of Smalltalk worrydream.com/EarlyHistoryOfSmalltalk
    - Comment on Moti Ben-Ari's Objects never? Well, hardly ever!
    computinged.wordpress.com/2010/09/11/moti-asks-objects-never-well-hardly-ever/#div-comment-3766
    - E-mail to Stefan Ram on definition of OOP purl.org/stefan_ram/pub/doc_kay_oop_en
    - E-mail to Squeak list on "messaging" wiki.c2.com/?AlanKayOnMessaging
    William Cook:
    - A Proposal for Simplified, Modern Definitions of "Object" and "Object Oriented"
    wcook.blogspot.com/2012/07/proposal-for-simplified-modern.html
    - On Understanding Data Abstraction, Revisited cs.utexas.edu/%7Ewcook/Drafts/2009/essay.pdf
    Anjana Vakil, "Programming across Paradigms" youtu.be/uNPdZm5oF_E
    Andre Stalz, "Why we need callbags" staltz.com/why-we-need-callbags
    Structure & Interpretation of Computer Programs mitpress.mit.edu/sicp
    Learn You Some Erlang for Great Good learnyousomeerlang.com
    further reading & references

    View Slide

  65. David Albert, Darius Bacon,
    Lindsey Kuper, Julia Evans, Matthew Parker, Ezekiel Smithburg,
    Juan Hernández, Andy Lee, Michael Arntzenius
    & the Recurse Center
    Team Øredev
    thank you!
    @AnjanaVakil

    View Slide