D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13579 - Add limitations to Uniform Function Call Syntax
Summary: Add limitations to Uniform Function Call Syntax
Status: RESOLVED MOVED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: spec
Depends on:
Blocks:
 
Reported: 2014-10-06 19:07 UTC by DBN
Modified: 2022-04-03 18:33 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description DBN 2014-10-06 19:07:37 UTC
I don't yet have much personal experience writing D code but I have a strong suspicion that "extension methods" are superior to UFCS.

First I want to note that the Dr. Dobb's UFCS article (http://www.drdobbs.com/blogs/cpp/232700394) describes extension methods incorrectly. Extension methods can be called with infix notation or with function notation; marking a method as an extension method only increases the ways it can be used.

1. UFCS is not self-documenting. I assume that in most use cases, a function is intended either to be called as a function, or to be called via UFCS. D doesn't give us a way to express this intention.
2. As a result of #1, UFCS will pollute auto-complete lists and similar tools. Tools will probably end up needing to add tool-specific ways to mark up UFCS functions.
3. I think UFCS has pitfalls similar to C++'s conversion constructors, except D doesn't even have the "explicit" keyword to opt out of it and it's not limited to single-parameter functions.

If breaking backward compatibility is at all an option, I suggest requiring functions to opt in to UFCS syntax in some way. Probably by adding an attribute. If someone wants to use UFCS on a function that doesn't allow it, they might be allowed to declare an identical function with the attribute added which forwards the call. A template or keyword could automate this. Perhaps when old-style UFCS is deprecated a DMD flag could be added that automatically generates source files with the attribute added to functions with UFCS usage.

If it's too late to fix it or opt-in is undesirable, I suggest something like C++'s "explicit" keyword which allows us to disable UFCS for specific functions.

I was unable to find any good pre-existing discussion on these problems but please close this Issue without warning if it has already been thoroughly considered.
Comment 1 Vladimir Panteleev 2014-10-06 19:25:44 UTC
Language design issues are best discussed in the newsgroups/forums.
Comment 2 Andrej Mitrovic 2014-10-07 13:27:50 UTC
> I don't yet have much personal experience writing D code

Well then, let's change the language and break all code while your seat hasn't even gotten warm yet.
Comment 3 DBN 2014-10-07 14:32:02 UTC
(In reply to Andrej Mitrovic from comment #2)
> Well then, let's change the language and break all code while your seat
> hasn't even gotten warm yet.

ad hominem...
Comment 4 bearophile_hugs 2014-10-07 14:36:39 UTC
(In reply to Vladimir Panteleev from comment #1)
> Language design issues are best discussed in the newsgroups/forums.

Yes, I suggest to open a discussion thread in the main D newsgroup, and show bug-prone examples, and some syntax and/or semantics to reduce such supposed source of bugs.
Comment 5 DBN 2014-10-07 14:58:43 UTC
Sorry, I don't personally have time for such a demanding discussion. (And I don't have any examples right now, other than this old thing http://redd.it/vvpfy) Please don't hesitate to start such a thread in my place if you want or just close/ignore this issue.
Comment 6 tyckesak 2022-04-03 18:33:23 UTC
Potentially moved already into forums as a Language Design Issue.