Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  breaking change to take advantage of virtual dispatch?

Guest
Posted: Sun May 25, 2008 10:54 pm Reply with quote
Guest
Hi,

I recently discovered in Erlang the capability to do OO-style method
dispatch. It's pretty neat. I had no idea it worked but it does. For
example, take an ErlyDB module, e.g. 'person', then type:

P = person:new_with({name, "Foo"}),
P:save().

It's equivalent to

P = person:new_with({name, "Foo"}),
Module = element(1, P),
Module:save(P).

That's very cool. It gives you a convenient way to write generic logic
with runtime type resolution. I prefer it to writing

P = person:new_with({name, "Foo"}),
person:save(P).

which is slightly more verbose and less generic.

Here's the problem: this works for the 'save()' function because it
takes only one parameter, but because of the way ErlyDB orders
parameters in generated code, it doesn't work with functions with
multiple parameters. Specifically, the Tuple:function() notation
passes the Tuple value as the *last* parameter to the function,
whereas ErlyDB expects it to be the _first_ parameter. E.g., to set
the name, you could write

person:name(P, "John")

but this wouldn't work:

P:name("John")

because of ErlyDB's parameter ordering. To make it work, we would have
to change the order of parameters in setters, e.g.

person:name("John", P).

So, to take advantage of this language feature, we would have to
change all of ErlyDB's functions that take a record as their first
parameter, and make it their last parameter. What do you think? This
change will break a lot of existing code, but I think in the long run
it'll be worth it.

Another option is to keep the old code generation style optional via a
compilation flag. It'll be more work to implement and will cause more
bloat in ErlyDB, but some people may appreciate the backwards
compatibility.

Yariv

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Mon May 26, 2008 9:40 am Reply with quote
Guest
Hi Yariv,

I would go for it (maybe it is just OO programming influence or
question of taste, or even lazyness - less to write ).
As I just started I am not really interested in backward
compatibility, not much to change for me. Let those who have already
running projects decide on that.
If you need help on that just let me know.

cheers,
Artur


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Mon May 26, 2008 10:35 am Reply with quote
Guest
2008/5/26, Yariv Sadan <yarivsadan@gmail.com (yarivsadan@gmail.com)>:
Quote:

Hi,

I recently discovered in Erlang the capability to do OO-style method
dispatch. It's pretty neat. I had no idea it worked but it does.
.....
Guest
Posted: Sat Jun 07, 2008 7:49 pm Reply with quote
Guest
I just noticed this the other day while playing around with erlydb and
I was really confused when it worked. Glad that someone figured out
what's going on. It seems like quite a coincidence that the first atom
in the tuple was the module name which is what the Erlang idiom for OO
would require. Then again, tagging the module/type at the beginning of
the tuple feels like the right thing to do (it has to go somewhere,
right?) and it makes a ton of sense that this idiom exists. Really
cool.

I was sure that you had set up erlydb to work this way by design Wink.

In the end it would lead to much cleaner code, so I'm all for
reordering the parameters in the other functions.

Dan

PS

Yariv,
Let me know if you don't have time. I can tackle that and it would
help me get up to speed on erlydb.

On May 26, 7:34
Guest
Posted: Sat Jun 07, 2008 11:24 pm Reply with quote
Guest
Dan, if you want to tackle this feature please go ahead. I have a long
list of Twoorl features I have to implement so I don't have a lot of
time to work on it.

Btw, so far I'm having a good experience with Git so I'm up for moving
ErlyWeb hosting to GitHub if it makes contributers' lives easier.

Yariv

On Sat, Jun 7, 2008 at 12:48 PM, Dan Bravender <dan.bravender@gmail.com> wrote:
>
> I just noticed this the other day while playing around with erlydb and
> I was really confused when it worked. Glad that someone figured out
> what's going on. It seems like quite a coincidence that the first atom
> in the tuple was the module name which is what the Erlang idiom for OO
> would require. Then again, tagging the module/type at the beginning of
> the tuple feels like the right thing to do (it has to go somewhere,
> right?) and it makes a ton of sense that this idiom exists. Really
> cool.
>
> I was sure that you had set up erlydb to work this way by design Wink.
>
> In the end it would lead to much cleaner code, so I'm all for
> reordering the parameters in the other functions.
>
> Dan
>
> PS
>
> Yariv,
> Let me know if you don't have time. I can tackle that and it would
> help me get up to speed on erlydb.
>
> On May 26, 7:34 pm, "Mikael Karlsson" <karlsson...@gmail.com> wrote:
>> 2008/5/26, Yariv Sadan <yarivsa...@gmail.com>:
>>
>>
>>
>> > Hi,
>>
>> > I recently discovered in Erlang the capability to do OO-style method
>> > dispatch. It's pretty neat. I had no idea it worked but it does.
>>
>> .....
>>
>> Hi,
>>
>> for those interested; there are som papers on this topic, called
>> parameterized modules:
>> Inheritance in erlang:http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
>> Parameterized modules in Erlang:http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf
>>
>> Mikael
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Sun Jun 08, 2008 7:39 pm Reply with quote
Guest
If you proceed with on the parameterized module track you should be aware that it is a not "officially supported feature" of OTP and I believe it is in OTP since the R12B release and not before. Your observation concerning tagging the first atom as the module could be extended to that the same thing is done for records - their names are the first atom of the tuple - so you can have a dual view of an "object" either as a record or as a parameterized module. One thing to consider could for instance be the yaws_headers.erl module in erlyweb.
/Mikael

2008/6/7 Dan Bravender <dan.bravender@gmail.com (dan.bravender@gmail.com)>:
Quote:

I just noticed this the other day while playing around with erlydb and
I was really confused when it worked. Glad that someone figured out
what's going on. It seems like quite a coincidence that the first atom
in the tuple was the module name which is what the Erlang idiom for OO
would require. Then again, tagging the module/type at the beginning of
the tuple feels like the right thing to do (it has to go somewhere,
right?) and it makes a ton of sense that this idiom exists. Really
cool.

I was sure that you had set up erlydb to work this way by design Wink.

In the end it would lead to much cleaner code, so I'm all for
reordering the parameters in the other functions.

Dan

PS

Yariv,
Let me know if you don't have time. I can tackle that and it would
help me get up to speed on erlydb.

On May 26, 7:34
Guest
Posted: Mon Jun 09, 2008 5:50 am Reply with quote
Guest
I must say I really like parameterized modules but I think the
convention for passing in the "object" as the last parameter for its
"methods" is strange. In ErlyDB as in other APIs the last parameters
of a function are often optional for overriding default behavior. It's
unintuitive for me to pass the most important/consistent parameter
last when I don't use parameterized module style invocation. I'm not
saying we shouldn't use this convention in ErlyDB because I do like
being able to write e.g. 'Person:name("dan")' instead of
'person:name(Person, "dan")' but I wish this language feature were
done differently...

Yariv

On Sun, Jun 8, 2008 at 12:38 PM, Mikael Karlsson <karlsson.rm@gmail.com> wrote:
> If you proceed with on the parameterized module track you should be aware
> that it is a not "officially supported feature" of OTP and I believe it is
> in OTP since the R12B release and not before. Your observation concerning
> tagging the first atom as the module could be extended to that the same
> thing is done for records - their names are the first atom of the tuple - so
> you can have a dual view of an "object" either as a record or as a
> parameterized module. One thing to consider could for instance be the
> yaws_headers.erl module in erlyweb.
> /Mikael
>
> 2008/6/7 Dan Bravender <dan.bravender@gmail.com>:
>>
>> I just noticed this the other day while playing around with erlydb and
>> I was really confused when it worked. Glad that someone figured out
>> what's going on. It seems like quite a coincidence that the first atom
>> in the tuple was the module name which is what the Erlang idiom for OO
>> would require. Then again, tagging the module/type at the beginning of
>> the tuple feels like the right thing to do (it has to go somewhere,
>> right?) and it makes a ton of sense that this idiom exists. Really
>> cool.
>>
>> I was sure that you had set up erlydb to work this way by design Wink.
>>
>> In the end it would lead to much cleaner code, so I'm all for
>> reordering the parameters in the other functions.
>>
>> Dan
>>
>> PS
>>
>> Yariv,
>> Let me know if you don't have time. I can tackle that and it would
>> help me get up to speed on erlydb.
>>
>> On May 26, 7:34 pm, "Mikael Karlsson" <karlsson...@gmail.com> wrote:
>> > 2008/5/26, Yariv Sadan <yarivsa...@gmail.com>:
>> >
>> >
>> >
>> > > Hi,
>> >
>> > > I recently discovered in Erlang the capability to do OO-style method
>> > > dispatch. It's pretty neat. I had no idea it worked but it does.
>> >
>> > .....
>> >
>> > Hi,
>> >
>> > for those interested; there are som papers on this topic, called
>> > parameterized modules:
>> > Inheritance in
>> > erlang:http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
>> > Parameterized modules in
>> > Erlang:http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf
>> >
>> > Mikael
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Tue Jun 10, 2008 7:08 am Reply with quote
Guest
Yariv,

Now that I realize that this is an undocumented/unsupported feature I
am a little worried about rewriting ErlyDB to take advantage of it. It
feels so right and is much more aesthetically pleasing. Would it be a
good idea to ask the core Erlang team if there is a reason they
implemented passing the module as the last argument and if it would be
possible to change Erlang's behavior to make it behave more like I
think most people would expect it to behave?

Dan

On Jun 8, 10:39
Guest
Posted: Sun Jun 15, 2008 4:38 am Reply with quote
Guest
I see your concern. I'm not too worried about future support for this
feature because I get the sense that although it's "unsupported" it's
unlikely to be removed or changed somehow because some people already
use it. I think ideally we could pass into erlyweb:compile() an option
to use the parameterized modules convention instead of the current
ErlyDB convention. I actually think it wouldn't be too hard to do -- I
would add to smerl a function to move the first parameter to the last
position, then in erlydb:code_gen() I would apply this function to all
generated functions that have 'Rec' as the first parameter (after all
other code generation steps).

If you want to implement it, let me know.

Thanks,
Yariv

On Tue, Jun 10, 2008 at 12:01 AM, Dan Bravender <dan.bravender@gmail.com> wrote:
>
> Yariv,
>
> Now that I realize that this is an undocumented/unsupported feature I
> am a little worried about rewriting ErlyDB to take advantage of it. It
> feels so right and is much more aesthetically pleasing. Would it be a
> good idea to ask the core Erlang team if there is a reason they
> implemented passing the module as the last argument and if it would be
> possible to change Erlang's behavior to make it behave more like I
> think most people would expect it to behave?
>
> Dan
>
> On Jun 8, 10:39 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
>> I must say I really like parameterized modules but I think the
>> convention for passing in the "object" as the last parameter for its
>> "methods" is strange. In ErlyDB as in other APIs the last parameters
>> of a function are often optional for overriding default behavior. It's
>> unintuitive for me to pass the most important/consistent parameter
>> last when I don't use parameterized module style invocation. I'm not
>> saying we shouldn't use this convention in ErlyDB because I do like
>> being able to write e.g. 'Person:name("dan")' instead of
>> 'person:name(Person, "dan")' but I wish this language feature were
>> done differently...
>>
>> Yariv
>>
>> On Sun, Jun 8, 2008 at 12:38 PM, Mikael Karlsson <karlsson...@gmail.com> wrote:
>> > If you proceed with on the parameterized module track you should be aware
>> > that it is a not "officially supported feature" of OTP and I believe it is
>> > in OTP since the R12B release and not before. Your observation concerning
>> > tagging the first atom as the module could be extended to that the same
>> > thing is done for records - their names are the first atom of the tuple - so
>> > you can have a dual view of an "object" either as a record or as a
>> > parameterized module. One thing to consider could for instance be the
>> > yaws_headers.erl module in erlyweb.
>> > /Mikael
>>
>> > 2008/6/7 Dan Bravender <dan.braven...@gmail.com>:
>>
>> >> I just noticed this the other day while playing around with erlydb and
>> >> I was really confused when it worked. Glad that someone figured out
>> >> what's going on. It seems like quite a coincidence that the first atom
>> >> in the tuple was the module name which is what the Erlang idiom for OO
>> >> would require. Then again, tagging the module/type at the beginning of
>> >> the tuple feels like the right thing to do (it has to go somewhere,
>> >> right?) and it makes a ton of sense that this idiom exists. Really
>> >> cool.
>>
>> >> I was sure that you had set up erlydb to work this way by design Wink.
>>
>> >> In the end it would lead to much cleaner code, so I'm all for
>> >> reordering the parameters in the other functions.
>>
>> >> Dan
>>
>> >> PS
>>
>> >> Yariv,
>> >> Let me know if you don't have time. I can tackle that and it would
>> >> help me get up to speed on erlydb.
>>
>> >> On May 26, 7:34 pm, "Mikael Karlsson" <karlsson...@gmail.com> wrote:
>> >> > 2008/5/26, Yariv Sadan <yarivsa...@gmail.com>:
>>
>> >> > > Hi,
>>
>> >> > > I recently discovered in Erlang the capability to do OO-style method
>> >> > > dispatch. It's pretty neat. I had no idea it worked but it does.
>>
>> >> > .....
>>
>> >> > Hi,
>>
>> >> > for those interested; there are som papers on this topic, called
>> >> > parameterized modules:
>> >> > Inheritance in
>> >> > erlang:http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
>> >> > Parameterized modules in
>> >> > Erlang:http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf
>>
>> >> > Mikael
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum