More About Records

Since records offer methods and properties they are often used to replace objects. This is possible if there is no need to use inheritance.

But there is a significant difference between both. References to objects are like pointers to a piece of memory whereas records are a piece of memory.

This makes a significant difference if you are using functions that return objects and records. Let’s have a look at one example.

This is really simply. The clone function returns the reference itself. This means that it doesn’t clone, it uses the same instance!

Now, we will do the same with an record.

Now you can see the differences.

  1. There is no need to create a record, the record is simply there.
  2. With point 1 there is no need to destroy the record.
  3. A function that returns a record automatically creates a new one.
This entry was posted in Tips and Tricks and tagged . Bookmark the permalink.