[erlang-questions] Deriving records from one another?

Roger Lipscombe roger@REDACTED
Mon Jun 23 16:44:33 CEST 2014


On 23 June 2014 15:08, Garrett Smith <g@REDACTED> wrote:
> How many fields are actually shared? Is it really a problem to just
> duplicate the values?

About 15. Granted, some of these go around together (ID has three
parts, for example), so could be in a smaller number of subrecords.

> I've managed some pretty complex state in the past but it never
> occurred to me to use separate records. I would tend to use a single
> record field to represent this "lifecycle" state (I think that's what
> you're describing) and just load the record up with whatever fields
> are needed for all of the various lifecycle states.

That's what I'm doing now, but it feels unwieldy -- and I'm in the
middle of refactoring it -- so I'm exploring options.

> If your motivation here is to model your state, as you would in an OO
> or other type system, you might just try not doing that and see what
> happens.

Sure "not doing that" is definitely an option. It's also probably the
one I'll choose eventually :-)

> Maps might be your friend -- I'm starting to use them and dealing with
> nested maps is 100x better than dealing with nested records.

We're still on R16, so I've not started playing with maps yet. We plan
to move to R17 in a few weeks' time.

> Probably not a very clear answer :)

Seems like it fits with my usual style -- find the ugliest piece of
code and clean it up. Repeat until pub time.

Thanks.



More information about the erlang-questions mailing list