Am I evil for this?

H. S. Teoh hsteoh at qfbox.info
Thu Oct 13 21:20:23 UTC 2022


On Thu, Oct 13, 2022 at 08:28:52PM +0000, solidstate1991 via Digitalmars-d wrote:
> So I watched this video:
> 
> https://youtu.be/G6b62HmsO6M
> 
> And Walter talked about using operator overloading for nonstandard
> purposes.
> 
> So in my collections library, I used it to implement set operators,
> but since set operators don't exist in the D standard (and require
> unicode, which would upset a lot of people, especially those who don't
> know what Win + '.' does), I had to use operators that have similar
> function in other spaces.

I've also written set operators for one of my projects.  I also
succumbed to the temptation of overloading bit operators (`|` for set
union and `&` for set intersection), because of the obvious analogy to
bit vectors.  Originally I wanted to use `+` and `*`, but on second
thoughts that's too remote from the usual meaning of + and *, and would
make the resulting code too easy to misread, so I settled on | and &
instead.  At least the meaning corresponds, if you think of your set in
terms of a glorified set of bits indicating the presence/absence of each
element.  `*` would be too easy to misunderstand as a Cartesian product
in the context of sets.


> I personally haven't used them yet in my projects (except for the
> unittests), so it's not too late to remove them, but I don't know if
> anyone else might be using them or not.
> 
> Link to my library with an example offense: https://github.com/ZILtoid1991/collections-d/blob/master/source/collections/treemap.d#L356

My personal opinion -- keep | and &, get rid of + and *.


T

-- 
It is the quality rather than the quantity that matters. -- Lucius Annaeus Seneca


More information about the Digitalmars-d mailing list