I use Delphi, but this is a question that I think is valid for any object-oriented programming language.
When should I use records over objects. I used to think that you used records when you had some simple definition of a set of related data that you wanted to store together that didn't need to be able to manipulate itself. However every time I decided that a piece of data should be placed along with other data into a record, I came up with reasons for why it should be a fully blown object.
- There is almost always a reason that a piece of data needs some properties or methods.
- Memory management (creation and destruction) is much, much simpler with Objects (at least in Delphi).
- Using objects is probably no more expensive in terms of speed and memory but much much more flexible.
In fact I have recently come to the conclusion that possibly the only time you should use records over objects in modern applications is if you are reading a binary file from disk that can be read directly into an array of records.
I inherited a 10 year old project that uses records extensively over objects for small pieces of data, and I wonder is it just me or should these concepts be consigned to the recycle bin of experience.
Discuss.