[erlang-questions] Dynamically access record fields

ok <>
Tue Feb 12 02:06:56 CET 2013


"Loïc Hoguin" <> wrote

> - Micro optimization. Most applications wouldn't care for it either
  Applications cannot care or not care for anything.
  If people are willing to pay the price, fine;
  my problem was that I saw no evidence that any proponent
  realised that there _was_ a price "I just don't see the harm".

> - That's a developer's choice
  Making code less readable may be a developer's _choice_,
  but if anyone else might be required to read the code,
  it isn't a developer's _right_.

> - BS, you have the same issue with Var = #rec.field, no difference there
  Reducing the effectiveness of type checking?
  Yes, we do have the same issue with Var = #rec.field,
  BUT I don't say that using that is a good idea either.

> - See previous point
  Inadvertently providing wider access?  No, this one is
  quite different from #rec.field.  You can only use
  #rec.field within the compile-time scope of a -record
  declaration for 'rec'.  If #rec.Field were allowed,
  Field could be created at a point where the record
  declaration was _not_ visible.  #rec.field has to be
  inside the module; use of it is not inadvertent; and
  you can _find_ it trivially with a text editor, so
  you can very easily check which fields might be accessed
  that way.  As far as I can see, that's not true of
  #rec.Field, where Field comes from some unknown arbitrary
  module.

The key point is that we just plain DON'T NEED #rec.Field;
anything we could do with it can be done without it more
clearly using existing mechanisms, with better control over
access and all sorts of other programmer-liked goodness.

Erlang needs dynamic field access like oysters need shooting-sticks.





More information about the erlang-questions mailing list