BBP - GCD Example
Note: This description has been derived from the BB_Prog demonstration; the demonstrations list is in the BBPE Express Guide. The BB_Prog demonstration has been saved to the BB Programming Introduction available on the download page.
This is an introduction to the BB Programming. It outlines the methodological aspects of the BB Programming, shows some examples and explains the terminology.
It is believed that we are past the eras of structured programming and modular programming, and that we are entering the era of block building programming which should support mainly software reusability.
BB programming is aimed at top software engineers primarily in the field of systems programming. The methodology of BB Programming is aimed at all levels of programming.
In BB programming, blocks function as subblocks for other blocks. The block is based on the concept of the black box, i.e. the system. Both the "system" and the "(black) box", are well known terms since the advent of Cybernetics and The Theory of Systems.
Hence BB programming is Block Building with Black Boxes.
In the context of BB programming, the basic terms "block" and "box" are interchangeable. This presentation will mostly use "box". The boxes have inputs and outputs which are interconnected. Every box has a behavior which transforms its input values into output ones with respect to time.
BB programs are drawn rather than written. One of them is presented here and can be displayed on the screen in BBP demo mode.
Every BB program is a box containing other boxes and their interconnections. The box is called the superbox, the boxes inside it are called subboxes. All boxes are represented as thickly outlined rectangles.
The inputs and outputs of the boxes are represented by arrows which are located at the vertical edges of the boxes. The data arrows are solid, the control ones are hollow.
The connections are represented by thin lines. They can branch out and cross over.
The boxes, inputs and outputs are named. These names will be called "idents". The inputs and outputs will be referred to as "io-s". The idents of the boxes are given on their top edges, the idents of the io-s are next to their respective io-s.
BB programs consist therefore of boxes, inputs, outputs, connections and idents. These are called "objects".
The well known concept of the "system" is fairly general and serves as a good way of expressing static structures, i.e. systems with fixed subsystems and rigid interconnections. It is not as useful for expressing dynamic structures, i.e. the systems in which the connections and/or the subsystems are variable. To overcome this drawback the accepted basic conceptual background has been extended so that BB programming is able to cope with variable inputs and outputs, variable and shared subboxes, etc.
It is claimed that these extensions are the new and key features which assure that BB programming will significantly improve:
- the reusability of the boxes,
- the design of parallel programs,
- the maintenance of software products,
- the maintenance of large libraries,
- the design and implementation of software generators.
Subprograms, modules and programs implemented with other programming technologies and even computer instructions can become "basic boxes" of BB programming.
Therefore it is expected that BB programming should work at any programming level, even as an assembler or command language (JCL). Moreover, BB programming could be a tool in the logical design of circuits, boards and computers, as they all can be seen as boxes, too.
On the other hand BB programs can be seen as flow charts in which both the flow of control and the flow of data are explicitly expressed. In addition, BB charts are able to express and support modularity, data abstraction and recursion.
Designing BB charts by hand is troublesome and boring. The BB Programming Environment was designed to simplify this task and to make it more enjoyable. At present the Environment assists in the creation of BB charts. Let us demonstrate the speed at which it is able to draw a new BB chart.
BB charting is meant to be viewed as a new method of programming rather than a supplement to classical programming!
Note:
In the early stages of the project I discovered that the written form of BB programs is possible, but not practical.
Besides the graphical form of BB programs the Environment maintains several internal complex data structures which allow rapid design, updating, storage and retrieval of BB programs. These internal data structures will be used for code generation and for symbolic debugging.
For the purposes of an initial introduction to BB programming, an explanation of its basic features should suffice. An in-depth discussion of its extended features has been postponed until BB programming is presented to the public.
Now, let us look at a "real" BB program. This box, named GCD, has been designed to compute the Greatest Common Divisor. To facilitate the description process of the GCD box in BBPE demo-mode:
- each of the objects usually blinks briefly just before it is mentioned,
- the cursor is located close to the discussed object.
Note:
The cursor is a small non-blinking rectangle. It swaps the foreground color and the background color at its position.
The superbox has the following inputs and outputs:
- the data input x,
- the data input y,
- the data output "gcd" for result, i.e. the greatest common divisor of the input values "x" and "y",
- the control input "do" to activate the computation,
- the control output "ok" to signal that the result is ready.
The superbox contains four subboxes:
- the subbox X for some computations,
- the subbox Y, which is same as X,
- the subbox "any" for passing control,
- the subbox COMP for comparing.
The subbox X (Y) sets or subtracts an input value:
- on receiving "set" control, it sets the input value "iset" then sends "setok" control;
- on receiving "sub" control, it subtracts the input value "isub" then sends "subok" control.
The subbox "any" passes the control received at any of its inputs (named 1, 2 and 3) through its only output. It has no data io-s.
The subbox COMP compares its input values "x" and "y". The control is passed through one of its three control outputs:
- if x>y then through xgty,
- if x=y then through xeqy,
- if x<y then through xlty.
The whole superbox GCD works as follows:
- the input values x, y of GCD are copied,
- the greatest common divisor is computed,
- the result value is signaled.
The more detailed description of the GCD box follows:
- The subboxes X and Y copy the input values "x" and "y":
- the control received through "do" of GCD reaches "set" of X,
- then X assigns its "iset" value, which is "x" of GCD,
- and sends "setok" control, which is connected to "set" of Y,
- then Y assigns its "iset" value, which is "y" of GCD,
- and sends "setok" control through subbox "any"
- Then, while the output values of X and Y are not equal
- if COMP detects that x>y, it sends control through "xgty" X subtracts Y's output value from its output value, and sends control from "subok" through "any" subbox to "comp" of COMP.
- similarly, if COMP detects x<y, Y subtracts X's output value from its output value, and sends control from "subok" through "any" subbox to "comp" of COMP.
- When the output values of X and Y become equal the control leaves COMP through its "xeqy" output and therefore GCD through its "ok" output signaling the resultant value of the output "gcd".
X and Y are designed to keep the values of their data outputs unchanged while the control is not inside them. Because Y's output "o" is also GCD's output "gcd", so the output value of "gcd" remains unchanged. We can see that the fixed connections are sufficient for this simple box. Up to now we have not mentioned the types of data. To keep the example simple, let us imagine that all data io-s are integers.
It is supposed that the subboxes could be fetched into the designed box from a box library and that the newly designed box could be inserted into such a library. At present the BB Programming Environment does not support box libraries.
This is the end of GCD example. More about the BB Programming Environment is in the following BBP demo-files:
- the user interface - INTRFACE, EXCEPTNS, TINYEDIT, FILES;
- the box design - DESIGN, DESIGNX;
- the BBPE configuration - CONFIG.
The rest of this demo-file contain additions to the terminology of BB charts. It is recommended that it be seen before going to DESIGN and DESIGNX demo-files for the first time.
Let us add the following explanations.
Every thick lined rectangle bordering a box consists of:
- two vertical edges, on which the box's inputs and outputs are located,
- the top horizontal edge with the optional box name,
- the bottom horizontal edge with the optional box type ident,
- four corner elements, which allow various box manipulations.
The io-s (i.e. inputs and outputs) are represented by the little arrows. The form of each arrow depends on the kind of io it represents:
- data or control io - solid or hollow arrow;
- fixed or variable io - single or double arrow.
The connection lines are composed from various connection elements:
- the straight horizontal and vertical elements,
- the bend elements for connection bends,
- the joint elements for connection branching,
- the cross elements for crossing two connection lines,
- the bend marks for marking where the connections were or should be bent,
- the open beginnings and open endings of connections.
The adjoining horizontal elements and adjoining horizontal parts of the other elements create horizontal connection segments. The adjoining vertical elements and adjoining vertical parts of the other elements create vertical connection segments.
There are two sorts of io-s - "source" ones and "destination" ones:
- all superbox inputs and subbox outputs are called "source" io-s, .
- all superbox outputs and subbox inputs are called "destination" io-s.
The connection branch is the part of the connection which is located between a destination io and the nearest joint.
The connections are oriented. All regular connections have to go out from the source io-s and go into the destination io-s. Their orientation is shown by the arrows of the io-s they interconnect.
An irregular connection contains at least one open beginning or open ending. Bend marks, open beginnings and open endings are auxiliary elements. They ease the design of the boxes.
Note:
This description has been derived from BB_PROG presentation. The presentation is available also in "BB Programming Introduction.pdf"
file on the download page. The presentations list is in the BBPE Express Guide.
Note:
Any part or motif, which is unique to the BB Programming, its Environment or its Interface, may not be used in any other software product without the prior written consent of the author.
If you have an interest in BBP or MKI, please
contact me by e-mail.
Copyright © 1984-1991,2007 by Pavel Lamačka