Functional and dataflow fight against object-oriented programming

Functional and dataflow fight against object-oriented programming

Hello World!

I made a couple of posts on twitter about the criticism of object-oriented programming. Let me summarize my point in a structured article.

I understood recently the programmers expressing concerns about object-oriented programming are actually talking about by reference passing of data, and the complications it introduces. They are not criticizing the actual object-orientation, the modularization of code or object-oriented polymorphism, and often it's not even about the dreaded, brittle inheritance hierarchies. It's really mostly about references. When data is passed by reference you can never understand what is the exact state of your application at any moment, a problem made even worse by multi-threading.

Many decades ago, when we had a couple of KB of memory to work with, managing that memory with pointers and references made a lot of sense. We don't live in that world anymore. Memory is cheap now. Why do we still wear the mental shackles trying to optimize it, kidding ourselves that we can, with so many abstraction layers between us and the hardware.

Functional languages are different, and the misconception is that they are somehow fighting against object-oriented programming. They are rather an answer to ubiquitous passing data by reference. It is a historical accident that almost all OO languages pass almost all objects by reference.

In a by-value functional dataflow world objects are simply a different manifestation of types, used as inputs or returned as outputs from pure functions, with references only found on and limited to the edges of your application. The benefit of dataflow is you don't need to care about classes, because they behave exactly like any other type of data i.e. they flow by-value. If nothing or almost nothing flows by-reference, you get most of the way there for free.

Because classes and types feel and smell the same, the distinction is simply not that useful.

OK, so functional programming is mostly about by value flow, agreed?... Yes, we add first class functions, and function composition, and closures etc. but it's actually about by value flow of data. Good! Oh, BTW immutable data is a natural by-product of by value dataflow.

In 2018 I wrote:

"Trying to figure out why dataflow, graphical programming feels so different to many people coming from procedural, text based background and finally figured out that it's a combination of two paradigms that exist in the world: procedural and functional. In fact the more I study these two fundamentally different approaches to programming the more I realize that graphical dataflow takes the best of both worlds, allowing you to mix and match the functional and procedural style, sprinkle in some OOP, some memory access and whatever you need, not breaking the mold. I have been saying this for a long time and I still believe it's true - graphical dataflow is the future of programming. The question of adoption is having teachers capable of explaining the hybrid nature of it. Does that make sense?"

I put forward that all benefits and selling points of functional programming, like immutable data, pure functions, first class functions etc. would be most naturally expressed in a dataflow oriented language. "Threading" macros in Clojure introduced as a basic language construct seem to support this theory. However every implementation of dataflow is different. I am thinking here specifically about the LabVIEW implementation, which is by far the closest to what I view as correct.

OO still needs to be used to achieve polymorphism in LabVIEW but only because first class support for passing functions around is not yet there.

Polymorphism is achieved in Clojure (Lisp) by handling functions as first class citizens, enabling higher order functions (functions which accept other functions as arguments), closures (functions which create and return other functions), lambdas (anonymous, unnamed functions created inline without ceremony). They enable a level of reusability achievable with OO languages only through a substantial amount of ceremony and boilerplate code, obfuscating the solution to the problem we are working on. This was and is also one of the main complaints about Java and LabVIEW.

LabVIEW needs to support functions as first class types, enable passing them around by value, evaluating them on demand, partially applying arguments and doing all that directly in code, enabling lambdas.

One step in the right direction for LabVIEW are Malleable VIs. Having a design which adapts in edit-time to the types you want to use, but otherwise remains generic would is a game changer, making LabVIEW editing as dynamic to write as Clojure and as type safe as Haskell. We still need to work on Malleable VIs to make them more stable and higher performance.

We could also have a discussion of making a dataflow language open-source, but that is a story for another time.

To summarize, I believe dataflow is the best way to express the integration of functional, reference based OO and multi-threaded code. The best and most complete implementation of dataflow programming is done in LabVIEW, and we still have room for improvement.

The whole world is embracing the principles driving functional programming e.g. immutable history of commits in GIT, block-chain technology, immutable databases, by value dataflow cloud deployment configurations etc. Lets do the same.

I do recommend everyone learning or at least looking at Clojure and LabVIEW. It will make you a better programmer :)

Below is a link to the presentation I gave during 2019 LabVIEW Architect summit. You might like it.


Steen Secher Schmidt

CTO and Founder at GPower | Business Developer | Technical Leader | Systems Engineer | LabVIEW Champion

5 年

Piotr, I always enjoy reading your posts - short blog style ones and longer presentation style ones. For each sentence and paragraph I find myself agreeing, and thinking "exactly" or "this sums it up" and so on. But I wouldn't be able to put those thoughts down as brief and exact as you do. Awesome value, important views, I hope you continue contributing like this. Thanks, and see you in Hungary soon! :-) /Steen

要查看或添加评论,请登录

Piotr Kruczkowski的更多文章

  • Theory of Constraints

    Theory of Constraints

    Every professional wants to be productive. If you are not productive, you are wasting time and money.

  • Learn to LOVE what you're good at!

    Learn to LOVE what you're good at!

    ?? If you do what you love, you will never have to work a day in your life. But here is the big secret almost nobody…

  • Epics, user stories, architectural work items and the backlog.

    Epics, user stories, architectural work items and the backlog.

    There are three levels of analysis and breakdown for a software engineering project. It might apply to all engineering…

    5 条评论
  • Simplify Down to First Principles

    Simplify Down to First Principles

    The first thing I do whenever faced with a problem or a complex system I do not understand, is simplifying it down to…

    1 条评论
  • My Lessons in Software Engineering

    My Lessons in Software Engineering

    I have compiled this list in an effort to organise my knowledge, my lessons and experiences, and also provide a…

    2 条评论
  • Sequence diagrams and the types of work enabling agile delivery

    Sequence diagrams and the types of work enabling agile delivery

    Two weeks ago I made a post which I then realised needs to be elaborated upon. ? I said it once, I'll say it again and…

  • Designing and visualising software architecture

    Designing and visualising software architecture

    It is not enough to do your best; you must know what to do, and then do your best. - William Edwards Deming This is one…

    5 条评论
  • Are factory automation games secretly functional programming languages?

    Are factory automation games secretly functional programming languages?

    TL;DR - Yes, if you squint ?? What are factory automation games? The application of scientific method to the…

    2 条评论
  • Scientific method in an era of magical thinking

    Scientific method in an era of magical thinking

    Scientific method and critical thinking are the only known, proven and repeatably reliable way to understand the world…

    2 条评论
  • Agile Management - Solid Gold Hits

    Agile Management - Solid Gold Hits

    Hejka All! For the longest time folks have been asking me to share my favourite materials and the videos I like to…

社区洞察

其他会员也浏览了