On Friday, 4 March 2016 at 02:09:25 UTC, Era Scarecrow wrote:
On Friday, 4 March 2016 at 01:56:34 UTC, user001 wrote:
Was just wondering why UFCS only works in one direction, that is why functions can be used as if it were part of a struct/class but not the other way around.

int dot;

float value = dot(a, b); // would be same as a.dot(b)
                         // doesn't try to use local "int dot"

Immediately looking at only that part of the code, i have to ask 'how the hell are you calling the int???'. Of course i can tell from your source dot is also a function in the vector.

Considering dot could now shadow the variables or function names, it would quickly QUICKLY become annoying. A hierarchy of how the call is used plus the documentation of what it's obviously doing is a much better approach. Not to mention we've been using . and -> and * so long for accessing/de-referencing members that are attached so long that changing it is probably not an option.

You can say the same thing about how it is currently implemented.

        int[] arr = [ 0, 1, 2, 3 ];
        
        static map(alias F)(int[])
        {
        }
        
writeln(arr.map!(a => a * 2)); // what does this mean array doesnt have a map function, does it use the local map function or the global one?

MAYBE if you were starting a language from scratch, but in this case i would firmly say no, this is ugly and confusing.

Well it could possibly be happening with C++17 so it's not that big of stretch to add it to an existing language, especially if that language already has it half implemented.


Reply via email to