[erlang-questions] Fear and Loathing in Programming La La Land

ok@REDACTED ok@REDACTED
Fri Mar 30 15:25:56 CEST 2012


> harder to debug. So in my mind, if you have the luxury of working with
> very good code in familiar territory, "initialize everything" is the
> preferable style. But if you are condemned to working with inferior
> code, or code that uses unfamiliar libraries, the alternative will
> prove to be more merciful.

You seem to be confounding two things, as indeed did the authors of
the original study.  The difference we are considering is that
between
   var p = new Point(x: 1, y: 2); // C# 4.0
and
   var p = new Point() {x = 1, y = 2}; // C# 3.0

BOTH provide EQUAL amounts of information about which
argument is which.
BOTH provide EQUAL freedom to reorder or omit arguments.

The problem is that the C# 3.0 approach
* forces the interface to be more complex:
  you have to have constructor AND setter for x AND setter for y,
  whereas the C# 4.0 approach needs only the constructor
* forces objects to be mutable that could otherwise be
  immutable (and thus be safe to share between threads)
* makes objects vulnerable to having their guts twisted
  by strangers ANY TIME, not just during setup.

Even without keyword parameters,

   var p = Point.Builder().SetX(1).SetY(2).Build();

provides all the clues about what is what that the
create-set-call antipattern does, without ever once releasing
an incompletely initialised object into the wild.

There _is_ room for some analogue of keyword parameters in
Erlang, and I have a proposal for that...






More information about the erlang-questions mailing list