Arbitrary sized array

My understanding is that the block construct simply allows programmers to organise code by grouping declarations and statements together within a defined local scope. This can have some advantages:

  • It avoids large declaration blocks at the beginning of programs and procedures;

  • it is easier to reason which variables are used in which execution statements when reading the code;

  • it limits the scope of variables so they can’t accidentally be used elsewhere;

  • it can be useful for objects with finalizers since these will be called at end block if the objects are declared within the block.

I don’t believe there is any tacit memory or speed advantage to using block constructs, they are just for programmer comfort.
The main argument against using block constructs IMHO is that a procedure would provide the same advantages in terms of code organisation, while also being reusable (callable) whereas a block construct is not.

3 Likes