Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the efficiency of an assign statement in progress-4gl

why is an assign statement more efficient than not using assign?

co-workers say that:

assign
  a=3
  v=7
  w=8.

is more efficient than:

a=3.
v=7.
w=8.

why?

like image 515
Bill Avatar asked Feb 17 '23 05:02

Bill


1 Answers

You could always test it yourself and see... but, yes, it is slightly more efficient. Or it was the last time I tested it. The reason is that the compiler combines the statements and the resulting r-code is a bit smaller.

But efficiency is almost always a poor reason to do it. Saving a micro-second here and there pales next to avoiding disk IO or picking a more efficient algorithm. Good reasons:

  1. Back in the dark ages there was a limit of 63k of r-code per program. Combining statements with ASSIGN was a way to reduce the size of r-code and stay under that limit (ok, that might not be a "good" reason). One additional way this helps is that you could also often avoid a DO ... END pair and further reduce r-code size.

  2. When creating or updating a record the fields that are part of an index will be written back to the database as they are assigned (not at the end of the transaction) -- grouping all assignments into a single statement helps to avoid inconsistent dirty reads. Grouping the indexed fields into a single ASSIGN avoids writing the index entries multiple times. (This is probably the best reason to use ASSIGN.)

  3. Readability -- you can argue that grouping consecutive assignments more clearly shows your intent and is thus more readable. (I like this reason but not everyone agrees.)

like image 137
Tom Bascom Avatar answered Mar 23 '23 11:03

Tom Bascom