Re: Structures; etc.
- Posted by Irv Mullins <irv at ELLIJAY.COM> Jan 31, 2000
- 481 views
----- Original Message ----- From: Lee West <leewest at ALTAVISTA.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Monday, January 31, 2000 3:08 PM Subject: Re: Structures; etc. > Hi All, > > I've been following the recent commentary on structures and OOP, especially > as it relates to preprocessors. Personally, I don't understand some of the > concerns that invoking these techniques via a preprocessor would somehow > negatively impact Euphoria's processing speed... or cause the "type" > command to be used. I have put together a simple example of a record > structure that could be processed by a preprocessor and the Euphoria code > that would result. It certainly doesn't require that the "type" command be > used, therefore, I can't see where the performance degradation would occur. > > As to whether this is preferable or even desirable... I'll let you decide. > But it does present an alternative to the, so called, MISSING language > elements of Euphoria, without the performance penalties that may occur if > they were incorporated into the Eu code itself. I believe an implementation > of this type is completely feasible, and can even see the possibility of a > full implementation of an OOP option as well. I'd love to hear your > thoughts. The example follows: > <snip code> > -------------------------------------------- > -- PreProcess the above code and generate -- > -- the following Euphoria code -- > -------------------------------------------- > > -- Define the variables > sequence temp, eeRecord > constant > Phone = 1, > Name = 2, > NameFirst = 1, > NameLast = 2, > Amount = 3, > WeeklyCnt = 4 > > -- Define the record counter > integer RecNo > RecNo = 0 > > -- Initialize the record and record template > eeRecord = {} > temp = {0,{"",""},0.0,{0,0,0,0}} -- Based on the record definition > > -- Populate the first eeRecord > eeRecord = append(eeRecord,temp) > RecNo += 1 > eeRecord[RecNo][Phone] = 1112223333 > eeRecord[RecNo][Name][NameFirst] = "John" > eeRecord[RecNo][Name][NameLast] = "Doe" > eeRecord[RecNo][Amount] = 1000.00 > eeRecord[RecNo][WeeklyCnt][1] = 25 > <snip more> Or, more likely, my program has bugs, so it assigns eeRecord[RecNo][Name][NameFirst] = 1, and eeRecord[RecNo][Amount] = 'Ralph". Nothing will stop it, until I try to do some math or format the record for printing, when I will get some strange results. I would prefer the error to occur at the point of invalid assignment, so I could fix the problem, not much later in the program. That's why some minimal type checking is needed. Sadly, the way user-defined type checking works in Euphoria doesn't help very much. First of all, it's slow, secondly, it can only abort the program with an error message. Far better would be a type() which incorporates some kind of graceful user-defined recovery. At least one step up from BASIC's "Redo from start" message, please! Secondly, the 3 programs I am currently working on have anywhere from 3 to 5 different ADDRESS, CITY, STATE, ZIP fields. (Customer address, shipping address, supplier address, customer's employment address... for example) This leads to awkwardly named constants, and makes it difficult to write generic routines to handle these otherwise similar constructs. Regards, Irv