​

DRAKON-Erlang: Visual Functional Programming

Home|Download

By Stepan Mitkin

Part 4 of 10

Previous|Contents|Next

Advanced Branching with Switch

The "If" icon is good for questions that can be answered "yes" or "no". For example:

  • Is X greater than Y?
  • Did you party last night?
  • Is it Tuesday today?

But not all questions are so simple. There are questions that may have multiple answers. For example:

  • What is the value of X? 10? 20? 30? Greater than 30?
  • When did you party last? Last night? Two days ago? A week ago? Ages ago?
  • Which day of the week is it today? Monday? Tuesday? Wednesday? Some other day?

The common thing about such questions is that they split one algorithm path into several. DRAKON handles multiple choice questions with the "Switch" construct. The "Switch" construct consists of one "Switch" icons and several "Case" icons.

Switch example

The rightmost "Case" icon can be empty. An empty "Case" icon means "all other values". It is similar to the "default" clause of "switch" statements in procedural languages.

Switch example with the default clause

"The further to the right ⎯ the worse" rule also applies to the "Switch" construct.

If some branches are worse than others, the "Case" icons should be sorted left-to-right.

The "Case" icon that corresponds to the luckiest scenario should be at the left.

The worst "Case" will be the rightmost one. This is similar to how the "If" exits are arranged.

Regardless of the way of branching, the happy path goes on the main vertical and error handling is placed on the right side.

Sometimes all branches are equally good. In this situation the "Case" icons should be sorted by the ascending order. Then the rule becomes "the further to the right ⎯ the greater". Depending on the problem, other rules could be devised.

The key thing to remember is to sort the "Case" icons in some monotonous way.

Previous|Contents|Next


Contact: drakon.editor@gmail.com