Bug 13579 – Add limitations to Uniform Function Call Syntax
Status
RESOLVED
Resolution
MOVED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-06T19:07:37Z
Last change time
2022-04-03T18:33:23Z
Keywords
spec
Assigned to
No Owner
Creator
DBN
Comments
Comment #0 by DeathByNukes — 2014-10-06T19:07:37Z
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 by dlang-bugzilla — 2014-10-06T19:25:44Z
Language design issues are best discussed in the newsgroups/forums.
Comment #2 by andrej.mitrovich — 2014-10-07T13:27:50Z
> 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 by DeathByNukes — 2014-10-07T14:32:02Z
(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 by bearophile_hugs — 2014-10-07T14:36:39Z
(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 by DeathByNukes — 2014-10-07T14:58:43Z
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 by josipp — 2022-04-03T18:33:23Z
Potentially moved already into forums as a Language Design Issue.