6. Micro level
6
◈ Basic components:
○ Objects in OOP comprising both
information and behaviour
○ Functions and data-structures in FP
◈ Hierarchical organization
◈ Sequential communication or
evaluation
7. DSLs and Frameworks
as “coordination languages”
◈ Define common abstractions
◈ Initialize your components
◈ Use components in right order
7
10. ◈ Hierarchic structure of program
◈ Code is procedural and sequential
◈ Visualisation is more about structure
◈ Concurrency is not native
What is wrong
with conventional programming?
10
12. “FBP - a programming paradigm that defines
applications as networks of "black box" processes,
which exchange data across predefined connections by
message passing, where the connections are specified
externally to the processes. These black box processes
can be reconnected endlessly to form different
applications without having to be changed internally.
https://en.wikipedia.org/wiki/Flow-based_programming
12
14. “... whereas the conventional approaches to
programming start with process and view data as
secondary, business applications are usually
designed starting with data and viewing process as
secondary – processes are just the way data is
created, manipulated and destroyed.
J. Paul Morrison, Flow-Based Programming, 2nd Edition
14
16. Soft Drink Bottling Factory
◈ Independent well-defined components
◈ Clean interfaces
◈ Simple to reconfigure
◈ Minimizes side-effects
◈ Designer can sit at one “station”, or can
follow an item through system
http://www.jpaulmorrison.com/fbp/FBPnew.ppt 16
17. FPB characteristics
◈ Asynchronous processes communicating
via streams of data packets
◈ Data packets with a lifetime of their own
◈ Definition of connections external to
components
◈ Consistent view from macro to micro
http://www.jpaulmorrison.com/fbp/FBPnew.ppt 17
20. Everything new is actually well-forgotten old
◈ 1971, IBM, basic concepts
◈ 1975, Bank of Montreal, on-line banking
system, still works!
◈ 1994, Flow-Based Programming, 1st Ed
◈ 2010, Flow-Based Programming, 2st Ed
◈ 2012, NoFlo project by Henri Bergius,
FBP in JavaScript
◈ JavaFBP, C#FBP, CppFBP (C++ and Lua)
20
23. Telegram problem
A program which accepts lines of text and
generates output lines of a different
predefined length, without splitting any of
the words in the text.
The program accepts an input stream of
lines of some length and produce an
output stream of lines of another length.
23
24. Problem FBP design using GenServers
ReadSeq Recompose WriteSeqDecompose
Lines Words Lines
◈ Each component is a GenServer.
◈ Each component implements only
one function - “run” which transforms
input to output
◈ Communication is asynchronous
◈ Code is here:
https://github.com/antonmi/kyiv_meetup_3
24
30. What is cool in this simple implementation
◈ Each component do its own part of work
◈ The only API is “init” and “run”
◈ Components works in parallel
◈ Components are under supervisor
30
31. What is wrong with the implementation
◈ Components are not independent (each
of them knows who is the next)
◈ Flow is controlled internally by each of
the component
◈ There is no back-pressure mechanism
(when some component lags it can be
overflowed by data)
31
33. GenStage abstractions
◈ GenStage is build on top of GenServer
◈ Each of the stage can be producer,
consumer or both
producer
producer
consumer
consumer
producer
consumer
33
34. GenStage communication
◈ Consumer subscribes to producer
◈ Consumer asks for data (sends a demand)
◈ Producer sends data
producer consumer
Subscribe
Ask
Events
34
44. GenStage Dispatchers
◈ GenStage.DemandDispatcher
○ sends events to the highest demand
◈ GenStage.BroadcastDispatcher
○ accumulates demand from all
consumers before broadcasting events
to all of them
◈ GenStage.PartitionDispatcher
○ sends events according to partitions
44