Skip to content

Athenizer use cases examples

Raviv Rachmiel edited this page Jul 1, 2017 · 7 revisions

Many times we find ourselves struggling with some complicated, hard for debugging code - not with the Athenizer!
Using the Athenizer would convert some code to much more debuggable equivalent code.
Here are a few examples of complicated original code and much more debuggable athenized code:


Original code:

return iz.nodeTypeEquals($, PREFIX_EXPRESSION) ? peel((PrefixExpression) $)
    : iz.nodeTypeEquals($, PARENTHESIZED_EXPRESSION) ? peel(core($))
        : iz.nodeTypeEquals($, INFIX_EXPRESSION) ? peel((InfixExpression) $)
            : iz.nodeTypeEquals($, NUMBER_LITERAL) ? peel((NumberLiteral) $)
                : $;

Would be converted by the Athenizer to:

if (iz.nodeTypeEquals($, PREFIX_EXPRESSION)) {
  Expression x1;
  x1 = peel((PrefixExpression) $);
  return x1;
}
if (iz.nodeTypeEquals($, PARENTHESIZED_EXPRESSION)) {
  Expression x2;
  Expression x1;
  x1 = core($);
  x2 = peel(x1);
  return x2;
}
if (iz.nodeTypeEquals($, INFIX_EXPRESSION)) {
  Expression x3;
  x3 = peel((InfixExpression) $);
  return x3;
}
if (iz.nodeTypeEquals($, NUMBER_LITERAL)) {
  Expression x4;
  x4 = peel((NumberLiteral) $);
  return x4;
}
return $;

The original single very complicated code line, using the Athenizer, was seperated to many lines of code, much more debuggable


Original code:

final InfixExpression $ = ast.newInfixExpression();
$.setOperator(¢);
$.setLeftOperand(make.plant(left).intoLeft($));
$.setRightOperand(¢ != op.PLUS2 ? make.plant(right).into($)
    : !precedence.greater($, right)
        && !precedence.equal($, right)
        && !iz.simple(right) ? subject.operand(right).parenthesis() : right);

After a few applications:

final InfixExpression $;
$ = ast.newInfixExpression();
$.setOperator(¢);
Expression x1;
PlantingExpression x2;
x2 = make.plant(left);
x1 = x2.intoLeft($);
$.setLeftOperand(x1);
Expression x3 = ¢ != op.PLUS2 ? make.plant(right).into($)
    : !precedence.greater($, right) && !precedence.equal($, right) && !iz.simple(right) ? subject.operand(right).parenthesis() : right;
$.setRightOperand(x3);

After few more applications we would end up with:

final InfixExpression $;
$ = ast.newInfixExpression();
$.setOperator(¢);
Expression x1;
PlantingExpression x2;
x2 = make.plant(left);
x1 = x2.intoLeft($);
$.setLeftOperand(x1);
Expression x3;
if (¢ != op.PLUS2) {
  PlantingExpression x4;
  x4 = make.plant(right);
  x3 = x4.into($);
} else {
  if (!precedence.greater($, right) && !precedence.equal($, right) && !iz.simple(right)) {
    x3 = subject.operand(right).parenthesis();
  } else {
    x3 = right;
  }
}
$.setRightOperand(x3);

The Athenized code is much easier for analyzing with debugger - the programmer is able to put breakpoints on simple, not composed commands, inspect the intermediate values of complicated computations and debug the code much more comfortably. More practical info on the athenizer plugin and installation assistance can be found here

Clone this wiki locally