Four Js Development Tools Forum

General => Ask Reuben => Topic started by: Reuben B. on July 09, 2020, 02:11:21 am

Title: Ask Reuben 36 - Length of Array and Char
Post by: Reuben B. on July 09, 2020, 02:11:21 am
Many years ago when I first transformed an Informix-4gl application to Genero, one of the things we investigated and actioned was changing CHAR variables to STRING variables, and similarly static ARRAY to DYNAMIC ARRAY‘s.  In particular we paid a lot of attention to CHAR and ARRAY that were an arbitrary length e.g. 1000, and said that if there was not a sound underlying reason for that length to be what it was, then we should consider using a STRING or DYNAMIC ARRAY instead.  The STRING and DYNAMIC ARRAY datatypes rather than having a fixed length allow for an unlimited length and allocate memory as required, as well as allowing better code practises and more functionality.

Advantages of using STRING and DYNAMIC ARRAY over CHAR and static ARRAY include

   • improved memory usage
   • more reliable code as don’t run into possibility of arbitrary length being exceeded.
   • less code as I don’t have to explicitly avoid arbitrary length being exceeded
   • access to methods for STRING and DYNAMIC ARRAY  datatypes
   • pass by reference, not by value

I still see a lot of code that uses CHAR and static ARRAY of arbitrary length that could be coded using STRING and DYNAMIC ARRAY respectively.