A r t i c l e s

Note: This Wiki is
outdated, personal views
may have changed.
L505 A.I. bot is dead
long live THX 1138

M a i n P a g e

D i r e c t o r y

When To Use Records Vs Classes

In Pascal...

Use records when you are dealing with simple situations that don't require a class or object. For example, you need to return two strings with a function. Make a record containing two strings for the function to return. No class needed. You could return one string as a VAR or OUT parameter but that bloats up the function declarations and is not always elegant. Depends on the situation.

Use records or old borland objects when you are needing to save significant amounts of memory for data storage/transfers. Old objects take less memory than newer classes. This is premature optimization - only use it if your benchmark proves it, or you are sure it is the bottleneck.
Use dynamic records new(record) only if you understand pointers^...
Use records when you have data is simple and doesn't require many SELF like operations to be performed on it. Objects/classes offer a magic SELF parameter while records don't have such thing as self.
Use records in place of an array when you wish to describe your code more thoroughly. Array[2] and Array[3] are not very obvious ways of describing someone's name and height, for example. But MyRec.HerName and MyRec.HerHeight are.
Records are very powerful when Object Oriented Programming, Classes, and Objects are overkill. Records are like object oriented programming, but not as complicated. You can fake a SELF using records, but that is beyond the scope of this article.

Note: This Wiki is outdated, personal views may have changed.

This wiki contains info on life, health, humans, nature, programming, database, fads, paradigms, poems, principles, theories.

Articles may contain statements which some may find helpful and encouraging, or even discouraging.

Beware, I believe in the Grand Justice system.
_ _ _