I feel understanding why data flow is higher level than control flow is key to writing good code (and convincing others during code reviews). I find this repeatedly when arguing why my functional style programming with immutability is superior to their mutable state code which is more common and expected.

But I don't understand why one is higher level than the other. The closest I can come up with, informally, is that ultimately end users don't care about what movement of control occurred. But they DO care what movement of data took place.

Other examples

  • applications which just do processing last only a couple of years, whereas files which store data can last decades)
  • a CPU just transforms volatile data, whereas disks store data persistently

In other words, control flow is a means of achieving data flow.

Is there a more rigorous way to explain this?

enter image description here
(source: slideplayer.com)

  • 1
    $\begingroup$ in the post you speak about dataflow/control flow ways of writing code. But the picture compares dataflow/control flow computing, that is, hardware level. Having control flow hardware, you can write both dataflow and control flow programs, and vice versa. So what are you talking about - hardware or software? and, when you ask "I don't understand why one is higher level than the other", what "one" and "other mean"? $\endgroup$ – rfq Feb 19 '17 at 20:32
  • $\begingroup$ Sorry I meant software. I couldn't find a good diagram so thought something is better than nothing. $\endgroup$ – Sridhar Sarnobat Feb 20 '17 at 1:31

Look at Wikipedia article "Control Flow". It contains typical flow chart. Arcs are the ways where control token moves from one node to another.

Now imagine you want to employ parallelism and launch several control tokens. Immediately a problem arise: how to isolate pieces of data from simultaneous modification by different control tokens. To tackle with this problem, we divide our data in parts - one parts belong to dedicated control token, and others are for exchanging information between control tokens. The result is a dataflow diagram (or chart). That is, to manage data in parallel environment, we have to split data into pieces and explicitly manipulate them. Data flow is no more than parallel control flow.

Functional programming is another story. While there exist both control flow (von Neumann) and data flow processors, there is no functional processor. Functional programs can be compiled both to data and control flow processors. But since ordinary imperative programs cannot be directly compiled to dataflow processors (they first have to be converted to dataflow programs, which is hard), and converting functional programs to dataflow representation is easy, we can consider functional programming as a variant of dataflow programming.

And finally, consider distributed computing. Since it involves multiple computers with no shared memory, it is best described as dataflow computing and not as imperative computing. What happens inside computer nodes, is it functional programming or imperative, does not matter. But the way how data are exchanged matters. And using functional data structures to exchange data between nodes is very appropriate.

  • $\begingroup$ Thanks for the detailed explanation. I'll have the refer back to this several times long term before I completely internalize this "proof" $\endgroup$ – Sridhar Sarnobat Feb 23 '17 at 3:18
  • $\begingroup$ Thanks also for introducing the term "functional data structure". I was aware that maps took a lot of hassle out of functional programming without really knowing why. Maps are awesome, almost as much as functional and control flow programming themselves. $\endgroup$ – Sridhar Sarnobat Feb 23 '17 at 3:24
  • $\begingroup$ Ahah. I think the last paragraph was the part that is at the fundamental part of this proof $\endgroup$ – Sridhar Sarnobat Apr 7 '17 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.