Here are various representations based on widespread syntaxes
S-expressions
Based on saeidw's representation, I only slightly modified it to include a Scheme-like
if as the requirements clearly made a distinction between
decisions and
switches.
Pros:
- Very easy to parse.
- Very easy to write.
Cons:
- Deeply nested branches will have too many parenthesis. It will make you dizzy.
- Lisp has a bad reputation in entreprise. Your boss won't like it.
((a1)
(if (= B true)
((a2) (a3))
((a4)
(cond
((= N 0) (a5))
((= N 1) (a6))
((= N 2) (a7)))
(a8))))
C-like syntax
Based on xterm's representation, I slightly modified it to include semi-colons (makes it easier to parse) and adopting saeidw's
ai naming conventions.
Pros:
- Very easy to write, it feels natural to most programmers.
Cons:
a1();
if B {
a2();
a3();
}
else {
a4();
switch N {
case 0:
a5();
break;
case 1:
a6();
break;
case 2:
a7();
break;
}
a8();
}
XML
We all hate XML, yet we all thought of it first when we saw this exercise. Verbosity can be very easily increased by an order of magnitude in order to inflict sadistic pain on your coworkers.
Pros:
- Supports meta-attributes for tags very easily.
- Plays nicely with entreprise-y software.
- It's a pain to parse, but you'll never have to do it because of XSD, XSLT and a lot of other acronyms.
- Your boss will approve of it, because she won't get into troubles for picking it.
Cons:
- Highly verbose.
- Was never meant for humans to read. If the file is over 100 lines, it will make your eyes bleed.
- Was never meant for humans to write. Repeating all these '<' and '>' while writing those redundant closing tags effectively makes you a bit dumber each time.
- If it isn't meant to be read by humans nor written by them, why would you use textual representation (instead of binaries)?
<workflow>
<activity name="a1" />
<decision name="B" type="bool">
<branch value="True">
<activity name="a2" />
<activity name="a3" />
</branch>
<branch value="False">
<activity name="a4" />
<switch name="N" type="int">
<case value=1>
<activity name="a5" />
</case>
<case value=2>
<acrivity name="a6" />
</case>
<case value=3>
<acrivity name="a7" />
</case>
</switch>
<activity name="a8" />
</branch>
</decision>
</workflow>
Shell and boolean logic
Inspired by the syntax of Unix shell scripts, it relies on boolean AND and OR for conditional branching. Like this:
- A && B: B is evaluated only if A is true
- A || B: B is evaluated only if A is false
Switches are implemented as a succession of
ifs. If order of evaluation is important, a mix of parenthesis and boolean operators can implement a succession of
elifs (else if). This can be useful for handling switches with
default behaviors.
Pros:
- Easier to write and parse than the C-like syntax.
- Fun.
Cons:
- No proper implementation of switches.
- Even though it's easier than C-like, it's still a pain to parse.
a1;
[ B = True ]
&& {
a2;
a3; }
|| {
a4;
[ N = 1 ] && a5;
[ N = 2 ] && a6;
[ N = 3 ] && a7;
a8; }
CSV
This format is loosely based on a diagram representation I used at work once.
Each element is an entry in the following comma-separated table. Each column represents:
- TYPE: can be either Activity, Decision or Switch.
- NAME: a string representing the name.
- IN_DEPEND: A semi-colon separated values of possible parent elements.
- OUT_DEPEND: A list of possible children.
The syntax of Switches and Decisions in the DEPEND columns is defined by the example.
Pros:
Cons:
- IN_DEPEND column is redundant. It could be taken out, but experience showed that it solves more problems than it adds.
- Very little flexibility for corner cases.
- Becomes a pain when it gets too large.
TYPE , NAME , IN_DEPEND , OUT_DEPEND ,
#########,######,############,########################,
Activity , a1 , , B ,
Decision , B , a1 , { True: a2; False: a4} ,
Activity , a2 , B , a3 ,
Activity , a3 , a2 , ,
Activity , a4 , !B , N ,
Switch , N , a4 , { 1: a5; 2: a6; 3: a7} ,
Activity , a8 , a5; a6; a7 , ,
Analysis
- Every alternative seems good when dealing with trivial cases like this one. To get a real comparison between models, more complex requirements should be considered.
- Implementing a parser for each representation would be a wonderful exercise.
- We should come up with a new standard that is even better. (obligatory xkcd reference)