Difference between revisions of "Procedural Programming"

m
m
Line 2: Line 2:
 
<breadcrumbs> Analytica User Guide > {{PAGENAME}}</breadcrumbs>
 
<breadcrumbs> Analytica User Guide > {{PAGENAME}}</breadcrumbs>
  
 +
Analytica is ''mostly'' a ''''declarative''' or '''non-procedural''' language. You create a model by defining variables, each with a definition expressing how to calculate it from other variables (or just a number or distribution).  Because it has no (global) assignments, you can understand each definition (or formula) without worrying about the sequence of execution. There is no required sequence to write or read the sequence of variables. Analytica figures out what sequence to evaluate them at runtime without you having to tell it. This frees you, as a model builder or reader of someone else's model, from having to worry about how to control the evaluation sequence. That gives Analytica a huge advantage in clarity and reliability over most conventional computer languages that  are procedural, like in Fortran, Visual Basic, C++, Javascript, and so on. Programming in such languages means spending a lot of effort designing (and then debugging) the flow of control using assignments, conditionals, and loops. That's why we say Analytica enables you to be a modeler without being a programmer.
  
A '''procedural program''' is a sequence of instructions for a computer to execute. Each instruction tells the computer what to do. It also might include a jump (go to) or loop that changes the sequence. Unlike conventional programs, Analytica models are (mostly) '''''non-procedural''''' — the model is a set of variables in no particular sequence, each with its own definition that expresses how to calculate its value. Each definition is usually a simple expression with functions, operators, constants, and other variables, but no procedural constructs controlling the sequence of execution. In this way, Analytica is like a standard spreadsheet application, in which each cell contains a simple formula with no procedural constructs. Analytica selects the sequence in which to evaluate variables based on the dependencies among them. Controlling the evaluation sequence via conditional statements and loops is a large part of programming in a language like in Fortran, Visual Basic, or C++. Analytica frees you from having to worry about sequencing. Non-procedural models or programs, like Analytica are usually much easier to write and understand than procedural programs. That's because you can understand each definition (or formula) without worrying about the sequence of execution.
+
However there are occasional situations where it's more convenient to express an algorithm in procedural form. For this reason, Analytica offers a set of programming constructs, described in this chapter, providing a general procedural programming language for those who want or need it. But most modelers can blissfully just ignore it!
  
However, procedural languages enable you to write more powerful functions that are hard or impossible without their procedural constructs. For this reason, Analytica offers a set of programming constructs, described in this chapter, providing a general procedural programming language for those who need it.
+
Analytica lets you use these constructs to control the flow of evaluation ''only within the definition'' of a variable or function. Evaluating one variable or function cannot (usually) change the value of another global variables or functions. In this way, these procedural constructs do not affect the simple declarative relationships among variables and functions. (There are a few exceptions, like assignments in the [[OnChange]] of a user input or [[OnClick]] attribute of a [[Button]], and the [[ComputedBy]] function, but even these are carefully designed to maintain the simple declarative structure.)
 
 
You can use these constructs to control the flow of execution only within the definition of a variable or function. Evaluating one variable or function cannot (usually) change the value of another variables or functions. Thus, these procedural constructs do not affect the simple non-procedural  relationship among variables and functions. The only exception is that a function called from an event handler such as [[OnChange]] or a button [[OnClick]] attribute can change the definition of a global variable (see [[Button creation]] for more details).
 
  
 
== Sections ==
 
== Sections ==

Revision as of 03:59, 17 January 2020

Analytica is mostly a 'declarative or non-procedural language. You create a model by defining variables, each with a definition expressing how to calculate it from other variables (or just a number or distribution). Because it has no (global) assignments, you can understand each definition (or formula) without worrying about the sequence of execution. There is no required sequence to write or read the sequence of variables. Analytica figures out what sequence to evaluate them at runtime without you having to tell it. This frees you, as a model builder or reader of someone else's model, from having to worry about how to control the evaluation sequence. That gives Analytica a huge advantage in clarity and reliability over most conventional computer languages that are procedural, like in Fortran, Visual Basic, C++, Javascript, and so on. Programming in such languages means spending a lot of effort designing (and then debugging) the flow of control using assignments, conditionals, and loops. That's why we say Analytica enables you to be a modeler without being a programmer.

However there are occasional situations where it's more convenient to express an algorithm in procedural form. For this reason, Analytica offers a set of programming constructs, described in this chapter, providing a general procedural programming language for those who want or need it. But most modelers can blissfully just ignore it!

Analytica lets you use these constructs to control the flow of evaluation only within the definition of a variable or function. Evaluating one variable or function cannot (usually) change the value of another global variables or functions. In this way, these procedural constructs do not affect the simple declarative relationships among variables and functions. (There are a few exceptions, like assignments in the OnChange of a user input or OnClick attribute of a Button, and the ComputedBy function, but even these are carefully designed to maintain the simple declarative structure.)

Sections

See Also


Comments


Lchrisman

29 months ago
Score 0
It says you can use these only within the definition of a variable or function, but in fact you can use procedural code in the OnClick of a button, which is a place where procedural style is often most likely to be useful.

You are not allowed to post comments.