Algorithmic Programming

fbp

It’s 2020 and we have a plethora of programming languages each having it’s own USP. For business programming, this means the business logic has to be re-written using a new programming language almost every decade to benefit from the advances. Few months back, I had started on a goal of converting an algorithm to executable code with focus on easy maintenance, code re-usability and language independence. I’m glad to share an approach that might just work. Let me know if you find it useful.

When one starts on a program, one writes the algorithm as a sequence of steps. Wouldn’t it be nice if a program could convert an algorithm into program and execute it? My approach maintains a one-to-one correspondence of the initial draft with the final program. The name kind of highlights that fact. People familiar with the subject might see similarities with Flow Based Programming (FBP). Though there have been many iterations and improvements on the basic theme, I’ll let the reader decide if my approach is an improvement. This discussion provides a comparison between the two approaches.

To test the feasibility of this approach, I wrote some code to generate the runtime/orchestrator (index.js) from FBP definition (init.fbp). The code is available here https://gitlab.com/atamariya/fbp .

network.fbp (Sample FBP program)

Read line from network.fbp,lineReader,network.fbp  
Parse nodes,parseNodes  
Append nodes,append  
Generate code,genCode  
Execute code,vmscript  

This is a simple CSV file with two mandatory fields:

  1. Comment explaining the step
  2. Identifier from a component implemented in a programming language
  3. Init parameters for the component (optional)

You can run network.fbp (default) as

node index.js

You can also provide an FBP file without suffix as an argument

node index.js init

index.js (Sample NodeJS implementation)

var packages = ["lineReader", "parseNodes", "append", "genCode", "vmscript", ];  
var vars = [];  
var initargs = [];  
initargs[0] = ["network.fbp"];  
  
var core = require("./core")();  
var res;  
res = core.init(packages, initargs, vars);  
res = res.then(() => core.execute(e));  
res = res.then((e) => {  
console.log(e);  
// Additional code to process res  
// Returned value is the value of res  
return e;  
});  
return res;

Advantages

  • Inline comment makes it very clear what’s happening in that particular step. So one need not look into the component to understand the flow.
  • It’s easier to edit with or without a GUI tool. Hence, it’s beginner friendly.
  • For business logic, this seems to be a good balance between complexity and maintainability. More complex idioms are better suited for a programming language which can be implemented within a component.
  • Components are simply pieces of code to be executed by the orchestrator.
  • Algorithm remains totally independent of the runtime programming language.

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

Mozilla Readability in GNU Emacs

Data Visualization with GNU Emacs