Block-related tips
- Last Updated: December 20, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
This topic offers some advice on creating blocks of code.
Use DO instead of REPEAT
Back in Procedure Blocks and Data Access you learned about the various properties of
different kinds of blocks. Remember that the DO block, by default,
does not provide you with many of the default services that the
REPEAT block does (for example, transaction management and
default frame management). The flip side of this is that a DO block
is much faster than a REPEAT block if you don’t need these
services. So, use a simple DO block whenever possible for any kind
of iterating block that does not need to manage a transaction or iterate through a
DOWN frame.
Minimize block nesting
DO
blocks. For this reason, you should avoiding unnecessary block nesting wherever
possible. Therefore, always use the form:
|
|
Remember that there can be an additional benefit to combining multiple assignments
into a single statement. If you turn several assignments into a single
ASSIGN statement, a DO block that would
otherwise have several statements can be reduced to just one statement with no block
header.
Minimize nesting of procedure calls
Procedures, whether internal or external, are blocks as well, and relatively expensive ones. Obviously, you should use procedures as necessary to structure your application properly. However, if you run a relatively small procedure or invoke a function many times in a performance-sensitive loop, you should consider moving the code directly into the procedure that calls it to execute it inline. If it is executed many times, this can make a significant difference in performance. If a procedure of this type is invoked from multiple places, you can make it into an include file and include it each place where it would otherwise be run. In this way, the code remains reusable but it is compiled directly in place wherever it is used. This can make the code much faster.