For anyone developing robust enterprise applications with Rocket Uniface, a solid grasp of fundamental concepts is paramount. Today, we’re diving deep into a core element of Uniface’s ProcScript: the boolean data type. This essential building block dictates the flow of your application, making it crucial to understand its nuances.
What is a Boolean in Uniface?
At its heart, a boolean represents a simple binary choice: TRUE or FALSE. It’s the foundational type for all logical operations within your Uniface applications. Whether you’re managing application states, controlling execution paths with if/else statements, or checking the success of an operation, booleans are indispensable.
Declaring Booleans in ProcScript
Uniface offers straightforward ways to declare booleans, either as variables within your script or as parameters for component operations.
As a Variable
For internal script logic or temporary state management, declare a boolean within a variables block:
variables
boolean isActiveFlag
endvariables
; Later in your script, assign a value
isActiveFlag = "1" ; Sets the flag to TRUE
As a Parameter
To pass true/false values between different parts of your application or operations, define booleans as parameters within a params block. These can be input (IN), output (OUT), or input/output (INOUT):
params
boolean pOperationSuccess : OUT
endparams
; The pOperationSuccess parameter can be set to indicate outcome
The “Truthy” and “Falsy” Dynamics of Uniface Booleans
Uniface’s interpretation of boolean values offers a degree of flexibility that is important to understand. Unlike some languages with strict boolean typing, Uniface employs a specific set of rules to determine whether a value is TRUE or FALSE.
What Uniface Considers FALSE ❌
Uniface will interpret the following values as FALSE:
- An empty string (
"") - The number
0 - The characters
Forf - The characters
Norn
What Uniface Considers TRUE ✅
This is where Uniface truly stands out: any value not explicitly listed as FALSE will be interpreted as TRUE!
This includes a wide array of values, such as:
- The number
1(the most common and recommended representation for TRUE) - Any other non-zero number (e.g.,
-1,42) - The characters
Tort - The characters
Yory - Any non-empty string (e.g.,
"Hello World","some_status_message")
For instance, if you assign vStatus = "Pending", Uniface will evaluate vStatus as TRUE in a conditional statement, because "Pending" is not in the list of FALSE values.
Key Takeaway and Best Practices 🚀
The flexibility of Uniface’s boolean interpretation can be a powerful feature, but it also presents a potential source of unexpected behavior if not handled carefully.
Our strong recommendation for clear, predictable, and maintainable code is to consistently use 1 for TRUE and 0 for FALSE in your Uniface applications. This practice eliminates ambiguity and makes your boolean logic immediately understandable to anyone reading your ProcScript.
By adhering to this simple best practice, you can harness the power of Uniface booleans effectively, ensuring your application behaves exactly as intended.