On Wed, 19 Mar 2025 at 16:41, Meta via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
On Wednesday, 19 March 2025 at 06:05:24 UTC, Manu wrote:
> On Wed, 19 Mar 2025 at 11:36, Meta via Digitalmars-d <
> digitalmars-d@puremagic.com> wrote:
>>
>> "This language is garbage collected, and they're _fucking
>> ashamed_ of that!"
>>
>> This guy is surprisingly perceptive and 100% accurate with his
>> cutting observations hahaha.
>>
>
> Why didn't his operator overloading experiment work?
>
> struct S {
>     int x;
> }
>
> // non-member opBinary
> S opBinary(string s : "+")(S lh, S rh) {
>     return S(lh.x + rh.x);
> }
>
> void main()
> {
>     S a, b;
>     S s1 = a.opBinary!"+"(b); // <- UFCS works, as expected
>     S s2 = a + b; // ERROR: doesn't work! why not? the rewrite
> should work
> via UFCS as above...
> }

I don't know the specific compiler details, but you make a good
point that this _should_ work via UFCS. Probably the compiler
first checks that it's a member function or something.

> I can't imagine any good reason his experiment should have
> failed. I would want this too when extern to a C lib; it hasn't
> come up for me before, but if it did, I would log a bug
> instantly.

Yeah, I've always wanted free-standing operator overload
functions in D, and I think the case for them has only gotten
stronger with better C and C++ integration, and _especially_ with
ImportC.

His other main gripe was that the compiler rejects .h files, even
though when he changed the extension to .c, it compiled and ran
just fine. In the footnote section he actually downloads the
source code and modifies it to compile .h files, and it's a
surprisingly simple change. I wonder if there's a specific reason
Walter didn't allow it.

Literally every single person that has ever tried to use ImportC instantly complained that it doesn't import .h files. There's no reason not to merge his patch.
There's been lots of discussion about this, and it seems that Walter just has some arbitrary opinion that it shouldn't work.
What Walter wants you to do is write a one-line .c file somewhere in your source tree, with `#include "the_header.h"`; completely pointless exercise, and as this guy points out, it breaks the cool tech-demo and instantly converts every person that touches this from "WOW!" to "WTF?!"... def should fix this.