Thread overview | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 02, 2007 The Is Operator | ||||
---|---|---|---|---|
| ||||
Hi, First time posting here on the NG, and certainly not my last. D has a good deal of syntactic sugar which results in easier to read code. However, there's one particular thing that has been bothering me for a while now: void foo(void[] var) { if (var !is null) // line of code } int main() { foo(null); } The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"? |
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle G. | Kyle G. wrote:
> Hi,
>
> First time posting here on the NG, and certainly not my last.
>
> D has a good deal of syntactic sugar which results in easier to read code. However, there's one particular thing that has been bothering me for a while now:
>
> void foo(void[] var) {
> if (var !is null)
> // line of code
> }
>
> int main() {
> foo(null);
> }
>
> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
Only reason is that it would require adding an extra keyword to the language.
More annoying to me is that !in doesn't work.
--bb
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle G. | Kyle G. wrote:
> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
A few hundred, search the newsgroup for more details...
If you hate it a lot, then just use "if (var)" instead.
--anders
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> More annoying to me is that !in doesn't work.
What's the logical negation of a pointer, anyway ?
But !in usually ranks high on the dwishlist thing.
--anders
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> Kyle G. wrote:
>> Hi,
>>
>> First time posting here on the NG, and certainly not my last.
>>
>> D has a good deal of syntactic sugar which results in easier to read code. However, there's one particular thing that has been bothering me for a while now:
>>
>> void foo(void[] var) {
>> if (var !is null)
>> // line of code
>> }
>>
>> int main() {
>> foo(null);
>> }
>>
>> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
>
> Only reason is that it would require adding an extra keyword to the language.
>
> More annoying to me is that !in doesn't work.
>
> --bb
Doing !(key in map) definitely causes me distress.
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote:
> Kyle G. wrote:
>
>> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
>
> A few hundred, search the newsgroup for more details...
>
> If you hate it a lot, then just use "if (var)" instead.
>
> --anders
It's not that I hate it. In fact, I use !is all the time where it applies. It just looks bad.
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle G. | Kyle G. wrote:
> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
I think the syntax is perfectly logical, because the negation applies to
the /operator/ and not the /operand/.Note the analogy of the statements:
(p == null) <--> (p is null)
(p != null) <--> (p !is null)
Nobody would ever get try to write (i == !null), so why (i is not null)?
Regards, Frank
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh wrote:
> Kyle G. wrote:
>> The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"?
>
> I think the syntax is perfectly logical, because the negation applies to
> the /operator/ and not the /operand/.Note the analogy of the statements:
>
> (p == null) <--> (p is null)
> (p != null) <--> (p !is null)
>
> Nobody would ever get try to write (i == !null), so why (i is not null)?
>
> Regards, Frank
Yeah, to me "a is not null" makes sense as an English sentence, but as an operator it seems like "a is (not null)". (not null) would have to evaluate to ... 1? So this would be a is 1, which isn't what we want at all.
Suffice to say D !is English.
- Gregor Richards
|
October 02, 2007 Re: The Is Operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kyle G. | On Tue, 02 Oct 2007 17:23:48 -0400, Kyle G. wrote: > The code I am concerned about is "var !is null" which appears to translate to "var not is null" when it actually means "var is not null." Is there any special reason why we are unable to do "var isnot null" or "var is not null"? This gets discussed every 6-months or so ... my favourite replacement keyword so far is "aint" as in "if (var aint null) " :-) -- Derek Parnell Melbourne, Australia skype: derek.j.parnell |
Copyright © 1999-2021 by the D Language Foundation