www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Proposal: isnot

reply "Achilleas Margaritis" <axilmar b-online.gr> writes:
I am currently writing some GUI application with D, and I found it is
tiresome and errorprone to write !(foo is null) all the time. I think D
would benefit from an 'isnot' operator. If it existed, I could write 'foo
isnot null' and be more productive, since it is easy to forget the ! and
makes the code more beautiful since less parentheses are needed.

It is a small change, easily done in my opinion. What do you think, Walter ?
May 09 2004
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
What's wrong with

    if(null !== foo)

?

"Achilleas Margaritis" <axilmar b-online.gr> wrote in message
news:c7lb26$1skj$1 digitaldaemon.com...
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, Walter ?

May 09 2004
next sibling parent reply resistor AT nospam DOT mac DOT com <resistor_member pathlink.com> writes:
As I recall, the specification seems to imply (incorrectly?) that one must
always compare against null 
with the 'is' operator.  Is this incorrect?  If so, I think we may need to
reexamine the spec because it 
seems like a certain percentage of people are misreading it.

Owen

In article <c7lcfs$1ugj$1 digitaldaemon.com>, Matthew says...
What's wrong with

    if(null !== foo)

?

"Achilleas Margaritis" <axilmar b-online.gr> wrote in message
news:c7lb26$1skj$1 digitaldaemon.com...
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, Walter ?


May 09 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 As I recall, the specification seems to imply (incorrectly?) that one must
 always compare against null
 with the 'is' operator.  Is this incorrect?  If so, I think we may need to
 reexamine the spec because it
 seems like a certain percentage of people are misreading it.

If that is so, then I am certainly one making such a mistake
 Owen

 In article <c7lcfs$1ugj$1 digitaldaemon.com>, Matthew says...
What's wrong with

    if(null !== foo)

?

"Achilleas Margaritis" <axilmar b-online.gr> wrote in message
news:c7lb26$1skj$1 digitaldaemon.com...
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, Walter ?



May 09 2004
prev sibling parent reply Andrew Edwards <edwardsac spamfreeusa.org> writes:
Matthew wrote:
 What's wrong with
 
     if(null !== foo)
 
 ?

I'd say the same thing that's wrong with if(foo === null) // as opposed to if(foo is null) Absolutely nothing! Except that it is clearer and less errorprone. Quite frankly I don't see much of a problem with the proposal. Of course I'm not the one engineering this beast, so I'll leave it up to the big boys to decide.
 "Achilleas Margaritis" <axilmar b-online.gr> wrote in message
 news:c7lb26$1skj$1 digitaldaemon.com...
 
I am currently writing some GUI application with D, and I found it is
tiresome and errorprone to write !(foo is null) all the time. I think D
would benefit from an 'isnot' operator. If it existed, I could write 'foo
isnot null' and be more productive, since it is easy to forget the ! and
makes the code more beautiful since less parentheses are needed.

It is a small change, easily done in my opinion. What do you think, Walter ?


May 09 2004
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
 Matthew wrote:
 What's wrong with

     if(null !== foo)

 ?

I'd say the same thing that's wrong with if(foo === null) // as opposed to if(foo is null) Absolutely nothing! Except that it is clearer and less errorprone. Quite frankly I don't see much of a problem with the proposal. Of course I'm not the one engineering this beast, so I'll leave it up to the big boys to decide.

No, I don't see much wrong either. Was just being orthogonal. However, I don't like isnot. I'd prefer "is not". I'd also like to be able to use "not" with "in" for searching containers.
 "Achilleas Margaritis" <axilmar b-online.gr> wrote in message
 news:c7lb26$1skj$1 digitaldaemon.com...

I am currently writing some GUI application with D, and I found it is
tiresome and errorprone to write !(foo is null) all the time. I think D
would benefit from an 'isnot' operator. If it existed, I could write 'foo
isnot null' and be more productive, since it is easy to forget the ! and
makes the code more beautiful since less parentheses are needed.

It is a small change, easily done in my opinion. What do you think, Walter ?



May 09 2004
next sibling parent "Bruno A. Costa" <bruno codata.com.br> writes:
Matthew wrote:

 
 However, I don't like isnot. I'd prefer "is not".
 
 I'd also like to be able to use "not" with "in" for searching containers.
 

Agreed. I didn't like the "isnot" operator. "is not" is much better, IMHO. Bruno.
May 10 2004
prev sibling parent "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
Why the need for an 'is' token for !== equivalence?

Simply using "not", as in (x not null) would seem reasonably orthogonal to
(x is null), and Walter would presumably be able to reuse the "not" keyword
elsewhere (alongside "in", as you suggest).

- Kris


"Matthew" <matthew.hat stlsoft.dot.org> wrote
 However, I don't like isnot. I'd prefer "is not".

 I'd also like to be able to use "not" with "in" for searching containers.

May 22 2004
prev sibling next sibling parent Hauke Duden <H.NS.Duden gmx.net> writes:
Achilleas Margaritis wrote:
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.
 
 It is a small change, easily done in my opinion. What do you think, Walter ?

I agree. It's not a critical issue, but having something like isnot would certainly improve readability (even if it sounds like a new kind of tissue that was designed by Apple ;)). D already has too many round parentheses in complex expressions anyway, even more than C++ because they are also used for templates. Getting rid of some of them will certainly be an improvement. Besides, not having a negative version of "is" is inconsistent, since == also has one. Hauke
May 09 2004
prev sibling next sibling parent reply Mike Swieton <mike swieton.net> writes:
On Sun, 09 May 2004 16:18:01 +0300, Achilleas Margaritis wrote:

 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.
 
 It is a small change, easily done in my opinion. What do you think, Walter ?

I'll throw in a vote for this. If === has !==, then is should have isnot. It would be more consistent. Mike Swieton __ Dare to be naive. - Buckminster Fuller
May 09 2004
parent reply Mr. Negative <Mr._member pathlink.com> writes:
<snip>
I'll throw in a vote for this. If === has !==, then is should have isnot. It
would be more consistent.

I'd rather get rid of "is" and have === and !== . The fewer "English" items in the language the better.
May 09 2004
parent reply Mike Swieton <mike swieton.net> writes:
On Sun, 09 May 2004 17:22:56 +0000, Mr.Negative wrote:
 I'd rather get rid of "is" and have === and !== . The fewer "English" items in
 the language the better.

This is certainly a valid consideration, but I disagree. Firstly, because 'is' is already there. I don't think there's a compelling enough reason to break code by removing it. Secondly, I like the english operators better than their symbol counterparts mostly because I think === gets a bit excessive. I understand the use of == over =, but I think that three equals characters is excessive. It is asking for bugs from typos, because it's misuse cannot be detected by the compiler. Do I think it's a big issue? No. But I think it is a big enough one to warrant inclusion, seeing as how it is a small change. Mike Swieton __ If the government wants us to respect the law, they should set a better example.
May 09 2004
parent "Achilleas Margaritis" <axilmar b-online.gr> writes:
"Mike Swieton" <mike swieton.net> wrote in message
news:pan.2004.05.09.17.38.26.464217 swieton.net...
 On Sun, 09 May 2004 17:22:56 +0000, Mr.Negative wrote:
 I'd rather get rid of "is" and have === and !== . The fewer "English"


 the language the better.

This is certainly a valid consideration, but I disagree. Firstly, because

 is already there. I don't think there's a compelling enough reason to

 code by removing it. Secondly, I like the english operators better than

 symbol counterparts mostly because I think === gets a bit excessive. I
 understand the use of == over =, but I think that three equals characters

 excessive. It is asking for bugs from typos, because it's misuse cannot be
 detected by the compiler.

 Do I think it's a big issue? No. But I think it is a big enough one to

 inclusion, seeing as how it is a small change.

 Mike Swieton
 __
 If the government wants us to respect the law, they should set a better
 example.

It is very easy to make a mistake with '===' and '=='. After lots of D typing, I found out that I should not use '==='; I should always use 'is', because it is much clearer that I check for identity. It is not a big issue. I think Walter will spend about 10 minutes to incorporate this into the language. But it will save developers lots of time, otherwise spent in tracking down silly typing mistakes.
May 09 2004
prev sibling next sibling parent "Walter" <newshound digitalmars.com> writes:
"Achilleas Margaritis" <axilmar b-online.gr> wrote in message
news:c7lb26$1skj$1 digitaldaemon.com...
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, Walter

It is a small change and easilly done, but once made, we're stuck with it. I'd like to run with the current scheme for a while longer first.
May 09 2004
prev sibling next sibling parent reply "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
Achilleas Margaritis wrote:
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.
 
 It is a small change, easily done in my opinion. What do you think, Walter ?
 
 
 

I would prefer: a !is b And: a !== b But that's just my personal opinion. -[Unknown]
May 09 2004
next sibling parent J C Calvarese <jcc7 cox.net> writes:
Unknown W. Brackets wrote:
 Achilleas Margaritis wrote:
 
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, 
 Walter ?

I would prefer: a !is b

I like that.
 
 And:
 
     a !== b

I don't like that so much (especially not "==="). But they're a whole bunch more consistant with D than "isnot" or "not is". I like BASIC okay, but I don't want D to morph into BASIC.
 
 But that's just my personal opinion.
 
 -[Unknown]

-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 09 2004
prev sibling parent reply Helmut Leitner <helmut.leitner wikiservice.at> writes:
"Unknown W. Brackets" wrote:
         a === null
         a !== null
         a === b
         a !== b

If I would dislike such things (which I don't) then I would write the equivalent of C macros (D functions optimized away): IsNull(a) NotNull(a) PtrEqu(a,b) PtrCmp(a,b) Best done as part of the standard library. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
May 09 2004
parent reply Hauke Duden <H.NS.Duden gmx.net> writes:
Helmut Leitner wrote:
 
 "Unknown W. Brackets" wrote:
 
        a === null
        a !== null
        a === b
        a !== b

If I would dislike such things (which I don't) then I would write the equivalent of C macros (D functions optimized away): IsNull(a) NotNull(a) PtrEqu(a,b) PtrCmp(a,b) Best done as part of the standard library.

Urgh! You propose that the built-in syntax should not be used and one should have to create functions for these most basic operations? I would much rather have the normal syntax be readable and not rely on a library to fix a design fault. I also don't think that PtrEqu(a,b) is particularly well readable. The Windows API does this kind of thing a lot and IMHO this is merely the lesser of two evils in most cases. Better use the good solution while you still can. Hauke
May 10 2004
parent reply "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
Hauke Duden wrote:
 Helmut Leitner wrote:
 
 "Unknown W. Brackets" wrote:

        a === null
        a !== null
        a === b
        a !== b



Heh, I did?
 If I would dislike such things (which I don't) then I would
 write the equivalent of C macros (D functions optimized away):

   IsNull(a)
   NotNull(a)
   PtrEqu(a,b)
   PtrCmp(a,b)

 Best done as part of the standard library.


I agree, if someone must have their ugly code they can. D doesn't stop that, nor does any other language. I like studlyCaps myself though.
 
 Urgh! You propose that the built-in syntax should not be used and one 
 should have to create functions for these most basic operations? I would 
 much rather have the normal syntax be readable and not rely on a library 
 to fix a design fault.
 
 I also don't think that PtrEqu(a,b) is particularly well readable. The 
 Windows API does this kind of thing a lot and IMHO this is merely the 
 lesser of two evils in most cases. Better use the good solution while 
 you still can.
 
 Hauke

No, not at all. I read it as, "if they are freako VB programmers they can write hateful looking code... no reason to punish us all with ugly code for just the poor VB'ers" except not in those words or probably even exact meaning. -[Unknown]
May 11 2004
next sibling parent Helmut Leitner <leitner hls.via.at> writes:
"Unknown W. Brackets" wrote:
 If I would dislike such things (which I don't) then I would
 write the equivalent of C macros (D functions optimized away):

   IsNull(a)
   NotNull(a)



 Best done as part of the standard library.


I agree, if someone must have their ugly code they can.

You don't know what you are talking about. Function call syntax isn't more or less ugly than operator syntax. Is {/} uglier than begin/end? Is != uglier than <>? You just get have to get used to it, that's all. Important is: to be able to do your job with a minimum of complexity. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
May 11 2004
prev sibling parent reply Juan C <Juan_member pathlink.com> writes:
If == is for testing the contents and === is for testing the address, then "is"
shouldn't be one of those -- oh wouldn't it be neat if "is" were used to test
the type of the item:  if ( x is int ) ...

I don't think an operator that's for testing for one special situation is very
useful, I would prefer a property:  MyRef.IsNull
May 11 2004
parent reply James McComb <alan jamesmccomb.id.au> writes:
Juan C wrote:

 I don't think an operator that's for testing for one special situation is very
 useful, I would prefer a property:  MyRef.IsNull

This IsNull property idea intrigues me (no foolin', this time). But it should probably be isNull, rather than IsNull. It could be defined for all object references. Example: /* x is an object reference */ if (!x.isNull) { //etc.. } What do you think? James McComb
May 11 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
James McComb wrote:

 Juan C wrote:

 I don't think an operator that's for testing for one special 
 situation is very
 useful, I would prefer a property:  MyRef.IsNull

This IsNull property idea intrigues me (no foolin', this time). But it should probably be isNull, rather than IsNull. It could be defined for all object references. Example: /* x is an object reference */ if (!x.isNull) { //etc.. } What do you think? James McComb

Might as well define your own function to do it: if (!isNull(x)) -- -Anderson: http://badmama.com.au/~anderson/
May 11 2004
parent reply James McComb <alan jamesmccomb.id.au> writes:
J Anderson wrote:

 Might as well define your own function to do it:
 
 if (!isNull(x))
 

Sure, you could that. But isNull is a function that a. is used extremely often b. is well-defined for all references. If there was an isNull property, I'd use it. Otherwise !== is fine by me. James McComb
May 11 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
James McComb wrote:

 J Anderson wrote:

 Might as well define your own function to do it:

 if (!isNull(x))

Sure, you could that. But isNull is a function that a. is used extremely often b. is well-defined for all references. If there was an isNull property, I'd use it. Otherwise !== is fine by me. James McComb

I don't think there should be any sort of alias for testing null like your talking about. If you wanted to do it yourself you could always put it in your common tools lib (that you carry around and use with all code your write). All adding a .isNull property is doing is making the language harder to learn. -- -Anderson: http://badmama.com.au/~anderson/
May 12 2004
prev sibling parent reply Derek Parnell <derek psych.ward> writes:
On Wed, 12 May 2004 13:29:02 +1000, James McComb wrote:

 Juan C wrote:
 
 I don't think an operator that's for testing for one special situation is very
 useful, I would prefer a property:  MyRef.IsNull

This IsNull property idea intrigues me (no foolin', this time). But it should probably be isNull, rather than IsNull. It could be defined for all object references. Example: /* x is an object reference */ if (!x.isNull) { //etc.. } What do you think? James McComb

The D compiler would have to treat such a property differently than other properties. Normally it would use 'x' as a reference to an object and inspect its property value. But in this case, 'x' may not be a valid reference. So even though it looks like a property it is really a pseudo one that the compiler treats differently. -- Derek 12/May/04 3:42:32 PM
May 11 2004
parent James McComb <alan jamesmccomb.id.au> writes:
James McComb wrote:
This IsNull property idea intrigues me (no foolin', this time).
But it should probably be isNull, rather than IsNull.> 


Derek Parnell wrote:
 The D compiler would have to treat such a property differently than other
 properties. Normally it would use 'x' as a reference to an object and
 inspect its property value. But in this case, 'x' may not be a valid
 reference. So even though it looks like a property it is really a pseudo
 one that the compiler treats differently.

Thanks for this explanation. OK, so it's not worth introducing an isNull property. James McComb
May 12 2004
prev sibling next sibling parent "Tu Nam" <dreamweaver mail15.com> writes:
Well so D will become DASIC , not just D.
Basic has them all . Is , Not , TypeOf etc ... I don't think we would
implement more English word in a programming language , let's it has
something common for everyone . != and == are good . If we want code more
clean , why don't we implement isEqual() and notEqual() in our object
"Achilleas Margaritis" <axilmar b-online.gr> wrote in message
news:c7lb26$1skj$1 digitaldaemon.com...
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

 It is a small change, easily done in my opinion. What do you think, Walter


May 09 2004
prev sibling parent reply JamesMcComb <alan jamesmccomb.id.au> writes:
Achilleas Margaritis wrote:
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

+1 for this proposal if the operator becomes ain't. Example: if(a ain't b) // etc.. James McComb
May 10 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
JamesMcComb wrote:

 Achilleas Margaritis wrote:

 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 
 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

+1 for this proposal if the operator becomes ain't. Example: if(a ain't b) // etc.. James McComb

Is this a joke? The ' would cause also kinds of parsing errors. -- -Anderson: http://badmama.com.au/~anderson/
May 10 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
J Anderson wrote:
 JamesMcComb wrote:
 
 Achilleas Margaritis wrote:

 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write 
 'foo
 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

+1 for this proposal if the operator becomes ain't. Example: if(a ain't b) // etc.. James McComb

Is this a joke? The ' would cause also kinds of parsing errors.

I reckon that the parsin' would be all mussed up by that. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 10 2004
parent "Phill" <phill pacific.net.au> writes:
"J C Calvarese" <jcc7 cox.net> wrote in message
news:c7pkr1$23lg$1 digitaldaemon.com...
 J Anderson wrote:
 JamesMcComb wrote:

 Achilleas Margaritis wrote:

 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think




 would benefit from an 'isnot' operator. If it existed, I could write
 'foo
 isnot null' and be more productive, since it is easy to forget the !




 makes the code more beautiful since less parentheses are needed.

+1 for this proposal if the operator becomes ain't. Example: if(a ain't b) // etc.. James McComb

Is this a joke? The ' would cause also kinds of parsing errors.

I reckon that the parsin' would be all mussed up by that.

LOL
May 11 2004
prev sibling next sibling parent "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
JamesMcComb wrote:

 +1 for this proposal if the operator becomes ain't.
 
 Example:
 if(a ain't b) // etc..
 
 James McComb

I concur. +1 -[Unknown]
May 11 2004
prev sibling parent "Phill" <phill pacific.net.au> writes:
"JamesMcComb" <alan jamesmccomb.id.au> wrote in message
news:c7ph9t$1u2a$1 digitaldaemon.com...
 Achilleas Margaritis wrote:
 I am currently writing some GUI application with D, and I found it is
 tiresome and errorprone to write !(foo is null) all the time. I think D
 would benefit from an 'isnot' operator. If it existed, I could write


 isnot null' and be more productive, since it is easy to forget the ! and
 makes the code more beautiful since less parentheses are needed.

+1 for this proposal if the operator becomes ain't. Example: if(a ain't b) // etc..

Are you an Aussie? LOL You might not believe this, but I was going to reply to Mathews post with this same suggestion the other day. Phill.
May 11 2004