[Haskell-cafe] [OT] thoughts about OO vs. functional "philosophy"
Dennis Raddle
dennis.raddle at gmail.com
Sun Mar 10 20:28:18 UTC 2019
I have a thought about OO vs. functional programming .
I'm moderately experienced with functional languages such as Haskell and
Purescript and have used OO for many years at work (Python, C++).
I'm giving tutoring lessons in Python to a professional who wants to use
programming as part of his work. (He's an entrepreneur.) He is eager to
understand functional and OO styles within Python--he keeps asking about
the real benefit of each, not content with a superficial approach.
I've explained about "encapsulation": gathering related functions together
and minimizing coupling to the rest of the program.
He asks "why do we encapsulate?" I've explained that one reason is to help
we, the programmers, be confident that our code is correct.
For example, in a class we try to isolate the implementation details from
the rest of the program, and the compiler helps enforce that.So when we're
writing our code and confirming to ourselves it's correct, we can make
simplifying assumptions. We know the rest of the program won't modify our
private variables and won't access us in any way other than the interface
we've presented to the world.
I explained that a large program is like a corporation, and pieces of the
program are like individual employees. When we write a class or function,
in a sense we "become" that employee and "forget about" a lot of the
details of other employees. (i.e., encapsulation).
Then has asked why functional programming is helpful. I explained about
referential transparency. Say we're a function: then other "employees"
(other functions) can trust us with simplifying assumptions, like no
side-effects.
Then this thought occurred to me, which is nifty but maybe not the whole
story.
"""
Say we're a class. Then the simplifying assumptions of OO allow *us* to
trust the *rest of the program* won't mess with us.
Say we're a function. Then the simplifying assumptions of functional style
help the *rest of the program* trust that *we* won't mess with it.
"""
D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190310/e08d4d7e/attachment.html>
More information about the Haskell-Cafe
mailing list