Commonality between structures, objects, include files, and arrays
- Posted by jguy <jguy at ALPHALINK.COM.AU> Jan 31, 1999
- 432 views
I was rewriting part of my racing database. The need for structures hit me when I came to that sequence of 22 elements: TAB no., horse's name, finish, margin, jockey, trainer, trainer's home town, date, track,... Until then, I had blissfully referred to them as s[1], s[2],... the year as s[8][1], the month as s[8][2], etc. But when I sat down to rewrite it "properly"... merde alors! I collecte my thoughts, which see below.... .... .... Meantime, however, I think I'll just stick to referring to s[8][1] rather than s[DATE][YEAR] or something like that. There is no real difference between structures (or "records") and classes (or "objects"). An object (or a "class") is only a record (a structure) with inheritance and with methods. Conversely, a structure (or "record") is only a class (or "object"), but bereft of methods and incapable of inheritance. The fact is recognized and implemented in Oberon, a Pascal-like object-oriented language, which knows only "RECORD". (Once I tried rewriting a Pascal program, replacing all records with objects, objects without any methods. It worked) Turbo Pascal became object-oriented with TP5.5. But that was not such a great leap forward. The seeds for objects were already in TP4.0, which introduced units. TP units are very much like Euphoria .e files (only quite a bit more of a pain to write), with this one important feature that you can specify the unit you refer to. That would mean, in Euphoria: include graphics.e include my_graphics.e and being able to specify which draw_line() you mean, by prefixing it with "graphics" or "my_graphics": graphics.draw_line() my_graphics.draw_line() Ada lets you use aliases for the modules (a.k.a. units, a.k.a. include files) which you import (a.k.a. use, a.k.a. include). Like this: import graphics as gr import my_graphics as my gr.draw_line() my.draw_line() (At least I *think* it's Ada, I am only half-sure. If not, it must be Component Pascal, which, despite its name, is an offspring of Oberon) From there, there is only a small syntactic leap to records (structures) and classes (objects). For instance, borrowing from Ada syntax: include animal.e as donald, mickey, goofy donald.family="duck" mickey.family="mouse" mickey.home={20,12} donald.goto(mickey.home) Arrays? They are just a particular case of structures. Rather, arrays came first. Then structures, as a more general case. Then objects (classes) as structures (records) with functions and procedures, and with inheritance. Perhaps Robert Craig should think of the NEXT generalization before he introduces arrays (and structures, and objects) into Euphoria.