tags:

views:

135

answers:

1

I ask this question as I have noticed that alot of OpenSource Erlang projects use "new" to pass parameters to Erlang modules, yet I hear at the same time that "new" is not part of the official language and may not be supported if it contains bugs. Before I use it in my own project I would like to clarify this issue.

Update: I have since asked on the official Erlang mailing list for an answer:

http://www.erlang.org/cgi-bin/ezmlm-cgi?4:mss:49535:201002:aicfhmngkhodmclhlnak

+3  A: 

There is no official Erlang standard, that makes it difficult to be part of it.

The OTP/Erlang team seem to only consider features as official if they have documented them. Parameterized modules (that is the feature's name) is not documented. What the OTP/Erlang team decide to do is as close to an Erlang standard as we have.

Personally I don't see the attraction to make Erlang appear like something it is not. It only makes the language have more rules to know and teach, and it only leads to disappointment from those that expect everything to be like their past OO background. It is not powerful to add complexity.

Implementation-wise (an abstraction that many exploit) the parameterized module is currently just a tuple of the module name and the parameterized module's "instance variables". So it is just an external function call that hide a few of the parameters.

Christian
But so many erlang projects use Parameterized modules isn't it time that the Erlang team documented them. If they were ever to remove them then alot of projects would break.
Zubair
+1: I so agree.
jldupont
Who should I contact to clarify this. Is is Erricson or Joe Armstrong?
Zubair
If a lot of project were to avoid using undocumented features, then they wouldn't break if the features were removed.
Christian
So how do I get "new" added to the standard as I think it is in Erlang's best interests.
Zubair
I would disagree about 'new' being in Erlang's best interests. One of the problems with it is that you have implicit arguments on every function call. This makes it harder to reason about that module vs. others; It doesn't necessarily play well with tools such as dialyzer or TypEr, etc.It's a hack on top of a previous way to call anonymous functions (before `fun Mod:Fun/Arity` and `fun() -> Exp end`), but not much more. It's not really idiomatic and to be honest, it worries me because it'll encourage people to try and program in an OO manner when this is not how it should be done in Erlang.
I GIVE TERRIBLE ADVICE
I agree with you Fred, it doesn't really fit in and it complicates the language. Unfortunately it has been "experimental" for so long it might be hard to get rid of. Of course if it was removed it could just as easily be fixed with a parse_transform.Perhaps it time to bring the old erlang spec/standard back to life and get it to mean something?
rvirding
Ok, so maybe it isn't good, but so many projects are using it already. For my own project what is the best alternative?
Zubair
Instead of `M = Mod:new(State)` along with using `THIS` and the `-module(Name,Params)`, keep handling the state in every function explicitely: `dict:find(Dict,Key)` (here, Dict is the state). This is really all that a parametrized module does. It hides `State` parameters in the variable you bind it to and then makes it implicit on each call.
I GIVE TERRIBLE ADVICE
Ok, thanks. I guess I'll put out another stack overflow question on this to see what alternatives there are.
Zubair
Why dict and not a record? :)
Zed
I've asked Erricson whether they will keep parameterised modules:http://www.erlang.org/cgi-bin/ezmlm-cgi?4:mss:49535:201002:aicfhmngkhodmclhlnak
Zubair