2-D programming structures

I have been writing about my discomfort with “language-only” style of programming.

I often think in terms of a picture of actions rather than a compound statement. It is kind of difficult to explain to the “used to” programmers.

Interestingly, when I talk about “programming by pictures”, people think about “drag-and-drop” style of programming. I don’t mean that!

Then, a picture is better than a thousand words, right? Let us see some examples:
The first example is about nesting. The following code is expressed in 1-D:

	for (int i = 0; i < 36; i++) {
		for (int j = 0; j < 36; j++) {
			cout << screen[i][j];
		cout << endl;

This code can be easily expressed (and pre-processed unambiguously) with the following table like 2-D structure:

for (int i = 0; i < 36; i++)
for (int j = 0; j < 36; j++) cout << screen[i][j];
cout << endl;

Then there is execution exclusivity paths also. For example, you will never execute “if” and “else” paths together. Why do “languages” force them to list them in one line?

Take for example the following code:

			if (i%4 == 3) {
				if (j%4 == 3) {
					screen[i][j] = '+';
				} else if (i%12 == 11) {
					screen[i][j] = '-';
			} else if (j%12 == 11) {
				screen[i][j] = '|';
cout << "Hello world!" << endl;

can be expressed as:

if (i%4 == 3) else if (j%12 == 11)
if (j%4 == 3) screen[i][j] = ‘+’;
else if (i%12 == 11) screen[i][j] = ‘-‘;
screen[i][j] = ‘|’;
cout << "Hello world!" << endl;

So far as there are “drop-down” statements, use the new line, otherwise add a table.

Within a table,

  • A row header is a “nested”
  • A column header is “nester”
  • A cell represents the “intersection of conditions” and may contain any complexity of code
  • When the code can take alternate path in a “nester” or “nested”, add a column or a row respectively
  • Order of insertion into one-dimension is – left to right and top to bottom

The advantages are:

  • It suddenly becomes possible to correctly code and grasp a complex decision structure
  • Take for example the above code of ‘if’s. Just compare adding an action for (j%12 == 11) && (i%12==11) in the one-dimension code and 2D code!

The disadvantages or challenge are:

  • “do-while” may be a problem. We can introduce a convention of “do…while(condition)” in the column/row header
  • Labelled “break”s will work fine – rather, loop breaking becomes more evident
  • Case fall-through is not visualized using this scheme. But hey! do we really need it? Some switches don’t even have a switch-case – and most don’t have fall through
  • This approach is no silver bullet for understanding a 17 level deep indented code. This approach works for simpletons like me, who prefer the design absorbing decisions rather than the code

As you can see, I am not inventing a new language. I am just doing away with the tyranny  of one-dimension. A spreadsheet parser-cum-IDE should be very easy to write – FOR ANY (imperative/OO) PROGRAMMING LANGUAGE!

What do you say?


4 comments on “2-D programming structures

  1. gnumanth says:

    For all these year people have been used to 1D programming and this paradigm of 2D can be introduced for debugging / tracing first!

  2. luke says:

    Congrats on possessing one of the most superior blogs You will find arrive around in some moment! Its merely incredible how very much you’ll be able to take away coming from anything due to how aesthetically beautiful it’s. Youve set with each other a wonderful weblog area -great graphics, video clips, layout. This really is absolutely the must-see weblog!

  3. arunyogeesh says:

    Programming using 2-D structures


    Flowchart programming?!!


    • Bhushit says:

      Originally I thought of flow chart programming. The link you post is very promising. Thank you!
      The linked solution limits itself to C/C++. It is not hard to extend it to other languages also.

      I realized later that flow chart programming may just be the first step.

      You might agree that 2-D programming will be a step forward and will be more succinct as it “compresses” at least 2 loops and also provides a grid of logic rather than a spaghetti of branches.

      BTW, you also inspired me with some ideas for fine tuning the “if” table. More later.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s