records

Chris Pressey <>
Wed Dec 5 01:37:13 CET 2001


On Tue, 04 Dec 2001 12:46:52 +0100
Robert Virding <> wrote:

> Seriously, how many people/apps would be severely burned if records
> *were* made their own datatype?  It is possible to do but you have to
> determine which solution hurts the most.
> 
> Robert

I am absolutely in favour of records graduating from syntactic sugar to
semantic data type.  I try to take abstraction to heart when I program, so
practically nothing I've written would break.

The one exception is where I have written a "general-purpose" module to
manipulate "records of any type" in a limited fashion.  I do this by
checking the first element of the tuple with element/2 and using it as a
type and/or module identifier.  This is certainly not the best practice,
and my code should probably be rethought anyway.

Ideally, the representation of a record should not be defined.

At the same time, records should probably have metadata, in the form of
functions (sort of like record_info, but which operate on a variable) in
the interests of writing generalized code that really can work on records
of any type.  (Unless generalizability is explicitly traded off for
efficiency - perhaps orddicts and dicts would be more suited for people
who want metadata.)

It might hurt less if a new way of structuring data is added to the
language, instead of replacing records.  For example, 'records' could be
left alone for backwards compatibility and a new 'struct' or 'aggregate'
or 'object' language feature could appear.

Lastly, although this next suggestion is far from crucial, I think it is a
neat idea that fits in with improved records.  That is, it would be nice
if there could be guards on fields in records much like there are guards
on functions.  Imagine:

-record(person,
[
  age when integer(age),
  name = "John Doe" when list(name),
  etc
]).

An association between record name and module name and/or mnesia table
name could also be further exploitable.

But please, consider that I *am* a mad scientist who is also of the
opinion that the restriction that guards operate in constant time be a
compile-time option, so take what I say with a grain of salt :)

Chris

"There's definately, definately, definately no logic to human behaviour"
  -- Bjork



More information about the erlang-questions mailing list