[erlang-questions] (Non)Parametrized modules, inheritance, and R15B02 issues?
Gleb Peregud
gleber.p@REDACTED
Fri Oct 12 10:04:23 CEST 2012
On Thu, Oct 11, 2012 at 11:52 PM, Evan Miller <emmiller@REDACTED> wrote:
> I designed BossDB around parameterized modules because pmods allow one
> to develop with a familiar ORM pattern in Erlang. I wanted a
> record-oriented API that was simple, succinct, and comprehensible.
> With pmods I was able to succeed in these goals. For example, to
> create a new record:
>
> Person = person:new(id, "Joe", "Armstrong")
>
> To save it:
>
> case Person:save() of
> {ok, SavedPerson} -> % do something ...
> {error, ValidationErrors} -> % do something else ...
> end
>
> To access an attribute:
>
> Person:first_name().
> "Joe"
>
> Person:last_name().
> "Armstrong"
I believe that someone from OTP team mentioned that the parametrized
modules are to be deleted, but tuple modules will stay. Essentially
this will mean that instead of writing:
-module(person, [FirstName, LastName]).
-compile(export_all).
first_name() ->
FirstName.
You will have to write:
-module(person).
-record(person, {first_name, last_name}).
-compile(export_all).
new(FirstName, LastName) ->
#person{first_name = FirstName, last_name = LastName}.
first_name(Person) ->
Perosn#person.first_name.
but you will still be able to do:
Person = person:new("Joe", "Armstrong").
Person:first_name().
"Joe"
case Person:save() of
{ok, SavedPerson} -> % do something ...
{error, ValidationErrors} -> % do something else ...
end.
So from point of view of readability there will be no change,
althought the amount of code in the model module (person.erl) will
slightly increase.
Please correct me if I am wrong.
Cheers,
Gleb
More information about the erlang-questions
mailing list