Clear Analytica code

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler

Analytica has huge advantages in clarity over other computer languages:

  • Influence diagrams give clear visual documentation of how variables and functions affect each other. With most computer languages that are not visual, someone has to draw up flow charts or other visual representations in a separate application -- which are usually become incorrect as changes are made, since they are not functionally connected to the code. You can draw influence arrows to define the dependencies as you formulate an Analytica model (program). And when you add or modify Definitions, the influence arrows update automatically to reflect the actual dependencies.
  • Analytica is a Declarative language, meaning that each variable has a single definition from which it is computed. It disallows assignments to global variables -- i.e. side-effects. So, you can understand how each variable is computed simply by looking at its definition, without having to worry about whether it might be affected by an assignment in some other part of the program (model). This 'locality' property is quite unlike most programming languages. (Spreadsheets, like MS Excel, are also declarative, if you ignore VB macros.)
  • Analytica variables have meaningful names, such as Earnings_before_tax, unlike spreadsheets where most "variables" are referred to by a meaningless cell address, like "AZ32". (Yes, you can assign names to cells and ranges in Excel, but the design makes it impractical to do that to more than a small fraction of them.)
  • Each variable (or other object) has an Object view, with a title, units, and description to supplement its identifier and definition (formula).

Despite these great advantages, it is entirely possible to create an Analytica model that is quite incomprehensible with meaningless identifiers, empty descriptions, and spaghetti diagrams. For hints on avoiding spaghetti, see Creating Lucid Influence Diagrams. For tips on how to write clear Analytica definitions that humans can understand, read on.

Comments


You are not allowed to post comments.