Deprecate `!a == b`
IchorDev
zxinsworld at gmail.com
Fri Aug 16 15:40:00 UTC 2024
On Thursday, 15 August 2024 at 16:40:31 UTC, Timon Gehr wrote:
> On 8/13/24 22:30, IchorDev wrote:
>> On Tuesday, 13 August 2024 at 10:14:29 UTC, Timon Gehr wrote:
>>> […]
>> […]
>
> The main issue is this is a typo that indeed happens now and
> then, not that people would think it works.
>
>> Do we really need to pander to people who don’t even
>> understand that logical operators only *return* `bool`?
>
> That's a strawman, and a bit insulting to anyone who has made
> this particular typo.
>
>> Maybe that seems harsh, but I have never even thought of doing
>> this because it’s just so obviously wrong—if I wrote it then I
>> must have meant what I wrote, and I was probably happy with
>> how it looked too.
>
> Your elitist attitude is somewhat common and I think used to
> make similar (if somewhat less strong) statements 10 years ago,
> but I think it was not particularly wise.
Sorry, I really had just never heard of people actually having
this problem before reading this thread.
> E.g., when you have:
>
> `foo() || function_call_long_name() == c`
>
> Now you negate the entire thing:
>
> `!(foo() || function_call_long_name() == c)`
>
> Now you think it would be more readable with individual
> negations.
>
> !foo() && !function_call_long_name() == c`
>
> This could easily happen, particularly if you are tired and you
> write a lot of Python.
I don’t really use Python very often, but I have done my fair
share of after-hours programming. Does being tired really impair
everyone else’s faculties of reasoning so much, or are you all
really really sleep deprived? I hope you're all getting enough
sleep! Anyway, I myself have made my fair share of other weird
errors when being tired, but I’m not sure I could blame the
language’s design for that.
> In the end, most code you'll run is not written by you. And
> most readers of your code do not want to read `!a==b`.
>
>> Having to wrap it in parenthesis would just negate that and
>> add to my code’s parenthesis hell.
>>
>> P.S. this isn’t a bug;
>
> This is a DIP idea, not a bug report.
Eh? As if I said this was a bug report? I am of course responding
to you saying that this a bug:
>>> A bug that crops up now and then in D is that someone negates
>>> `a == b` by prepending a `!`.
What you are describing is not a bug in D at all, it’s a
programming error wherein the programmer misuses the logical not
operator. Describing this arrangement as a bug in the language is
misleading if not entirely erroneous.
>> and `!` is ‘logical not’, not ‘negation’.
>
> Those are in fact synonyms.
> https://en.wikipedia.org/wiki/Negation
They are synonyms in Boolean logic, but not in programming, [or
in D](https://dlang.org/spec/expression.html#unary-expression).
This is why we place the prefix ‘logical’ before them, because
these are concepts from another area of study that uses
conflicting terms.
More information about the dip.ideas
mailing list