Jump to page: 1 2
Thread overview
Whence came UFCS?
Jul 27, 2018
Sameer Pradhan
Jul 27, 2018
Joakim
Jul 27, 2018
Joakim
Jul 27, 2018
Jonathan M Davis
Jul 27, 2018
Simen Kjærås
Jul 27, 2018
Simen Kjærås
Jul 27, 2018
Mike Parker
Jul 27, 2018
Mike Parker
Jul 27, 2018
Mike Parker
Jul 27, 2018
Jonathan M Davis
Jul 27, 2018
Sameer Pradhan
Jul 27, 2018
Mike Parker
Jul 27, 2018
H. S. Teoh
Jul 27, 2018
Jesse Phillips
Jul 27, 2018
Meta
July 27, 2018
During our Boston D Meetup today, we went through and deconstructed Walter's wonderfully elegant blog post from 2012 called "Component Programming in D"

http://www.drdobbs.com/article/print?articleId=240008321&siteSectionName=architecture-and-design

I stumbled upon this gem (and another score or so articles on the digital mars site) a few days back, while following various hyperlinks, within and around the blog on Walter's take on what was C's biggest mistake which has been getting a lot of comments over the past few days.

This post which I have been trying to digest bit-by-bit over the past few days, made me realize why I fell in love with D in the first place. To top it all, Steven played a lightening talk from 2018, called "values as types" by Andreas (https://youtu.be/Odj_5_pDN-U?t=21m10s) which is a parody on C++ and is so utterly ludicrous, we could not stop laughing.  Anyway, back to the point.

During the same period, but independent of the thread on C's mistake, I found that Kotlin has something called "Extension Functions" and "Extension Properties" (https://kotlinlang.org/docs/reference/extensions.html) via. the following article on Medium

https://medium.com/@magnus.chatt/why-you-should-totally-switch-to-kotlin-c7bbde9e10d5

Specifically Item #14.

What I saw/read seemed eerily familiar. Almost like a "wolf in sheeps clothing". The example screamed of UFCS.  Then, later, while reading the above Kotlin documentation, I saw a reference being made to similar functionality in C# and Gosu (apparently a programming language that I have never heard of before today) called Extensions.

Furthermore, I found that Project Lombok (https://projectlombok.org/features/experimental/ExtensionMethod) has tried to make this idiom/functionality available in Java through a @ExtensionMethod annotation. This also almost exactly represent UFCS functionality, though much more cludgy, I must say.

Therefore, after reading the word "Extension" in three different contexts, I started wondering and various questions came to mind, starting with---Whence came UFCS?

a. Did Walter and/or Andrei invent it independently of C#?
b. Was it called UFCS in some other language?
c. Were they not aware of Extensions when they coined UFCS?
d. Are UFCS and Extensions really one and the same thing?
e. If not, what is/are the difference(s)?  And is this why a different term/acronym was coined?

As far as I can tell a Google search on UFCS leads to only material on D and a Wikipedia entry mentioning Stroustrup and Sutter's proposal from 2016 to extend C++ to have this facility. It is likely that the Wikipedia article is severely incomplete in its historical connections as there is no mention of C# or that of Walter's 2012 Dr. Dobbs post which already lists it towards the end---in the list of features that D has which allows the creation of elegant components---among other dozen or so features.

In the end I thought I might as well dump my thoughts on the D forum and hear straight from the horse's (or horses') mouth(s)---so to speak.

--
Sameer

July 27, 2018
On Friday, 27 July 2018 at 03:41:29 UTC, Sameer Pradhan wrote:
> During our Boston D Meetup today, we went through and deconstructed Walter's wonderfully elegant blog post from 2012 called "Component Programming in D"
>
> [...]

I remember reading somewhere that it's inspired from Nim. I might be wrong.
July 27, 2018
On Friday, 27 July 2018 at 03:41:29 UTC, Sameer Pradhan wrote:
> During our Boston D Meetup today, we went through and deconstructed Walter's wonderfully elegant blog post from 2012 called "Component Programming in D"
>
> [...]

Extension methods were added to C# 3.0 in 2007, UFCS was discussed as a generalization of the concept to free functions at that year's DConf, fully implemented years later:

https://forum.dlang.org/thread/htjuut$av2$1@digitalmars.com
July 27, 2018
On Friday, July 27, 2018 03:41:29 Sameer Pradhan via Digitalmars-d wrote:
> In the end I thought I might as well dump my thoughts on the D
> forum and hear straight from the horse's (or horses')
> mouth(s)---so to speak.

It evolved out of D's member function call syntax for arrays - basically, for years before we had UFCS in D, we had UFCS for arrays. However, when and how that was added to arrays, I don't know. I don't recall it ever not being in the language, but I never used D1, and I don't know if it had it. At minimum, it's been in D since early D2, if not much earlier. I'd have to do a lot of spelunking through old releases to figure out when it was added.

Certainly, the origins of UFCS in D do not come from making it possible to extend user-defined types with member functions. It comes from wanting member function call syntax when using arrays (probably aimed primarily at strings, but I don't know). It's just that later it was proposed to extend it so that it would work with any type and thus make the member function call syntax universal.

- Jonathan M Davis

July 27, 2018
On Friday, 27 July 2018 at 10:30:07 UTC, Jonathan M Davis wrote:
> It evolved out of D's member function call syntax for arrays - basically, for years before we had UFCS in D, we had UFCS for arrays. However, when and how that was added to arrays, I don't know. I don't recall it ever not being in the language, but I never used D1, and I don't know if it had it. At minimum, it's been in D since early D2, if not much earlier. I'd have to do a lot of spelunking through old releases to figure out when it was added.
>
> Certainly, the origins of UFCS in D do not come from making it possible to extend user-defined types with member functions. It comes from wanting member function call syntax when using arrays (probably aimed primarily at strings, but I don't know). It's just that later it was proposed to extend it so that it would work with any type and thus make the member function call syntax universal.

This compiles in DMD 0.50 (oldest version on the download page, nov 20, 2002), so I think it's safe to say it's been around for a while:

void fun(int[] arr) {}

void main() {
    int[] a;
    a.fun();
}

Arrays' .reverse, .sort and others were added in 0.24, but I can't find a download for anything before 0.50.

--
  Simen
July 27, 2018
On 7/27/18 7:24 AM, Simen Kjærås wrote:
> On Friday, 27 July 2018 at 10:30:07 UTC, Jonathan M Davis wrote:
>> It evolved out of D's member function call syntax for arrays - basically, for years before we had UFCS in D, we had UFCS for arrays. However, when and how that was added to arrays, I don't know. I don't recall it ever not being in the language, but I never used D1, and I don't know if it had it. At minimum, it's been in D since early D2, if not much earlier. I'd have to do a lot of spelunking through old releases to figure out when it was added.
>>
>> Certainly, the origins of UFCS in D do not come from making it possible to extend user-defined types with member functions. It comes from wanting member function call syntax when using arrays (probably aimed primarily at strings, but I don't know). It's just that later it was proposed to extend it so that it would work with any type and thus make the member function call syntax universal.
> 
> This compiles in DMD 0.50 (oldest version on the download page, nov 20, 2002), so I think it's safe to say it's been around for a while:
> 
> void fun(int[] arr) {}
> 
> void main() {
>      int[] a;
>      a.fun();
> }
> 
> Arrays' .reverse, .sort and others were added in 0.24, but I can't find a download for anything before 0.50.

Reverse and sort were properties (compiler built-ins), not extensions. If it existed in 2002, it's safe to say it was there pretty much from the beginning.

-Steve
July 27, 2018
On Friday, 27 July 2018 at 05:22:17 UTC, Joakim wrote:
> On Friday, 27 July 2018 at 03:41:29 UTC, Sameer Pradhan wrote:
>> During our Boston D Meetup today, we went through and deconstructed Walter's wonderfully elegant blog post from 2012 called "Component Programming in D"
>>
>> [...]
>
> Extension methods were added to C# 3.0 in 2007, UFCS was discussed as a generalization of the concept to free functions at that year's DConf, fully implemented years later:
>
> https://forum.dlang.org/thread/htjuut$av2$1@digitalmars.com

The DConf slides linked from that old thread list this 2000 Scott Meyers article as an inspiration for UFCS:

http://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197
July 27, 2018
On Friday, 27 July 2018 at 13:38:26 UTC, Steven Schveighoffer wrote:
> On 7/27/18 7:24 AM, Simen Kjærås wrote:
>> Arrays' .reverse, .sort and others were added in 0.24, but I can't find a download for anything before 0.50.
>
> Reverse and sort were properties (compiler built-ins), not extensions. If it existed in 2002, it's safe to say it was there pretty much from the beginning.

From what I recall, UFCS for arrays were essentially a bug - an unintended side effect of how the properties were implemented. But it's been 15 years, so I can't really trust my memory. :p

--
  Simen
July 27, 2018
On Friday, 27 July 2018 at 13:38:26 UTC, Steven Schveighoffer wrote:


> Reverse and sort were properties (compiler built-ins), not extensions. If it existed in 2002, it's safe to say it was there pretty much from the beginning.
>
> -Steve

I came to D in 2003. I recall this coming up in the forums now and again by people discovering it for the first time and wondering why it only worked with arrays. I remember thinking it was a pretty big deal when it was expanded to work in the general case. I'm sure I wrote about it on my old blog, but now I can't find my database backup to verify.
July 27, 2018
On Friday, 27 July 2018 at 14:09:02 UTC, Simen Kjærås wrote:

>
> From what I recall, UFCS for arrays were essentially a bug - an unintended side effect of how the properties were implemented. But it's been 15 years, so I can't really trust my memory. :p
>

You're not alone! That's how I remember it as well.
« First   ‹ Prev
1 2