Stateless Programming

Visual LANSA Framework

Stateless Programming

The fundamental difference between Web programming and LANSA for i or Visual LANSA programming has to do with understanding stateless programs.

Programs are stateless when they do not maintain any state between their interactions with the browser user (or anything else out there on the Internet). This means that the variables defined in the program cannot be used to remember things between interactions. Other more subtle states cannot be kept intact either, such as the location of a file cursor, an open file connection or an allocated resource.

To illustrate the impact of stateless programming to consider this simple program specification:

  • Display a field called #NUMBER that starts with value 0. Every time the user presses enter increment #NUMBER and display the new result.

In 5250 programs (LANSA/RPG) or in a Windows programs (Visual LANSA/Visual Basic) the logic would be:

Define #NUMBER with a default value of zero

Change #NUMBER to #NUMBER + 1

Display the incremented #NUMBER value

 

In stateless programs #NUMBER (and in fact your whole program and all its state) ceases to exist between interactions with the user. Therefore the variable cannot be used to remember it's previous value between interactions with the user.

The change to your programming approach is easy enough. You simply need to do this: 

Define #NUMBER

Restore the current value (i.e. state) of #NUMBER

Change #NUMBER to #NUMBER + 1

Save the new value (i.e. state) of #NUMBER

Display the new #NUMBER value (at which point your program ceases to exist)

 

LANSA for the Web and the Framework both provide facilities to save and restore state for you (more on that later). Maintaining state is easy, but you need to understand that it is happening and how it impacts your applications.