code visualization

Business logic gone visual

Create insightful visual deliverables with Conquest products
Picture is worth
a thousand words
At Conquest Software Solutions we are producing tools for Oracle database development and maintenance, and the static PL/SQL code analyser is a notable part of our Windows applications. We are a single-vendor toolset provider, which means we've been focusing on Oracle development tools and PL/SQL as a development language for almost 15 years.

Inspired by a famous saying "picture is worth a thousand words", we decided to turn the static code analyser into a code illustrator, visualising pieces of code as flowcharts and call tree diagrams. Though drawing blocks and arrows is a simple task, laying out appeared to be pretty challenging. Arrows flowing over the blocks, cross minimisation, grouping – the solution seemed tedious and too complicated, an unaffordable luxury!

It was then that we started to look for a third-party solution and Graphviz immediately attracted our attention. AT&T made an earlier version of this software, and now it is available as a set of command-line tools, libraries, and sources under The Eclipse Public License.

The graph engine of Graphviz uses a DOT graph description language – a plain description of graph nodes and their relations with multiple attributes for visual presentation.
Let's use a simple PL/SQL subprogram as an example:

PROCEDURE WRITE_STRING(

   P_MESSAGE_TYPE IN NUMBER

  , P_MESSAGE IN VARCHAR2

 )

 IS

 BEGIN

  IF P_MESSAGE_TYPE >= LOG_LEVEL THEN

   ADD_LOG_RECORD(P_MESSAGE_TYPE, P_MESSAGE);

  END IF;

 END WRITE_STRING;
Translated into the DOT language, it's still that light and self-explanatory:

digraph G {

 N0 [label="”]

 N1_COND [label="P_MESSAGE_TYPE \>= LOG_LEVEL ?"];

 N2 [label="ADD_LOG_RECORD(P_MESSAGE_TYPE, P_MESSAGE);"];

 EXIT_LABEL [label="END"];

  

 N0 -> N1_COND

 N1_COND -> N2

 N1_COND -> EXIT_LABEL

 N2 -> EXIT_LABEL 

}
Based on the listing above, Graphviz generates the following picture:
Looks good, but not that sexy. We make it a little more eye-catching by adding block shapes (shape=diamond), labels for arrows (label="Yes"), and colors "color, fontcolor".

digraph G {

 comment="PL/SQL flowchart generated by ClearSQL";

 node [fontname="Arial", fontsize=8, height=.2, width=.25, color="#000000", fontcolor="#000000"];

 edge [fontname="Arial", fontsize=8, arrowsize=.8, color="#000000", fontcolor="#000000"];

  

 N0 [shape=plaintext, label="", style=invis];

 N1_COND [shape=diamond, conditional=true, label="P_MESSAGE_TYPE \>= LOG_LEVEL ?"];

 N2 [shape=box, label="ADD_LOG_RECORD(P_MESSAGE_TYPE, P_MESSAGE);"];

 EXIT_LABEL [shape=Msquare, label="END"];

  

 N0 -> N1_COND [color=darkgoldenrod];

 N1_COND -> N2 [label=" Yes " color="#228b22" fontcolor="#228b22"];

 N1_COND -> EXIT_LABEL [label=" No " color="#ff7e40" fontcolor="#ff7e40"];

 N2 -> EXIT_LABEL 

  

 subgraph "cluster_#1" {

  bgcolor="#ffffff";

  label="";

  fontname="Arial"; fontsize=9;

  fontcolor="#0000ff"; color="#0000ff"; labeljust="l";

  N1_COND; N2

 } 

}
The code looks pretty clear, even if you are not familiar with PL/SQL.
We also extended the standard interpreter to display the business comments inside the code, the so called 'pseudocode'. This brings extra value to the chart, as now it can also display the business logic behind the code, not just a listing visualisation. See below, the pseudocode starts with — ##:

PROCEDURE WRITE_STRING(

   P_MESSAGE_TYPE IN NUMBER

  , P_MESSAGE IN VARCHAR2

 )

 IS

 BEGIN

  —## Level associated with a message as compared with log level

  —##@true Higher

  —##@false Lower

  IF P_MESSAGE_TYPE >= LOG_LEVEL THEN

   —## Log the message

   ADD_LOG_RECORD(P_MESSAGE_TYPE, P_MESSAGE);

  END IF;

 END WRITE_STRING;


Business logic is displayed by adding pseudocode to the listing
~
Here it is!
~
Graphviz gave us a unique opportunity to make stunning detailed visuals for developers and business users. If you want to explore more of the amazing pro-functions in our tools, we'll be glad to present. Leave us a request or drop us a line at customer-support@conquest-us.com.
clearsql
sqldetective