digitalmars.D - Some operators in D...
- Sam (19/19) May 25 2005 Hey, what's with this:
- Derek Parnell (11/33) May 25 2005 Keep reading the specs. There is an 'is' operator which is an alias for
- Brad Beveridge (8/21) May 25 2005 D now has the "is" operator, with "!is" on the way. "===" and "!==" are
- =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= (15/34) May 26 2005 Yes. For now, at least... It's called '!==', though ?
- Sam (4/11) May 26 2005 a.makenull();
- Unknown W. Brackets (10/26) May 26 2005 But people used to C++ are going to appreciate it. And C# also uses nul...
- Sam (10/36) May 26 2005 You're right!! What was I smoking!! Sorry!
- Unknown W. Brackets (16/31) May 26 2005 Well, it would be:
- Sam (23/39) May 26 2005 Ok then why not put 'isnull' and 'nullify' into a namespace or make them
- Brad Beveridge (3/8) May 26 2005 Sorry, doesn't get my vote (not that this is a democracy :) - I don't
- Sam (4/12) May 26 2005 THAT'S IT!! I have it with all of these keywords!!!!
- Hasan Aljudy (17/51) May 26 2005 Sorry, doesn't get my vote.
- Sam (14/30) May 26 2005 But see you've already gotten in trouble with the 'null' keyword!
- Tom S (7/15) May 26 2005 Ok, you asked for it... Here it comes... WTF ?!
- Hasan Aljudy (27/75) May 26 2005 Where is the trouble if you are wrapping it? of course you HAVE to use
- Hasan Aljudy (3/5) May 26 2005 I meant: "you can't compare references against 0"
- Tom S (10/16) May 26 2005 So you propose a removal of 4 simple and short keywords and two
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (12/17) May 26 2005 You mean you would define some built-in properties for
Hey, what's with this: if(a === null) Then does that mean I can do this: if(a !=== null) ??? I'm sorry, this operator syntax looks stupid! Honestly! Why not create an operator 'is': if(a is null) Just like in SQL! Or better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull) I'm sorry, I don't like '==='. This is going too far!! I also don't like '<<<', and I have seen '<<<=' and '>>>=' in javascript. NOT PRETTY!! :( Sam- sam987883 yahoo.com
May 25 2005
On Wed, 25 May 2005 23:08:34 +0000 (UTC), Sam wrote:Hey, what's with this: if(a === null) Then does that mean I can do this: if(a !=== null) ??? I'm sorry, this operator syntax looks stupid! Honestly! Why not create an operator 'is': if(a is null) Just like in SQL!Keep reading the specs. There is an 'is' operator which is an alias for "===". The triple '=' operator is being phased out so I wouldn't use it any more. The "!==" operator is the negative of "is" but moves are afoot to have that replaced by a better operator too.Or better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull) I'm sorry, I don't like '==='. This is going too far!!You are not alone, and it was superseded. We are trying hard to get "!==" replaced too. -- Derek Melbourne, Australia 26/05/2005 9:10:09 AM
May 25 2005
Sam wrote:Hey, what's with this: if(a === null) Then does that mean I can do this: if(a !=== null)That would be !==??? I'm sorry, this operator syntax looks stupid! Honestly! Why not create an operator 'is': if(a is null)D now has the "is" operator, with "!is" on the way. "===" and "!==" are looking like they'll get deprecated.I also don't like '<<<', and I have seen '<<<=' and '>>>=' in javascript. NOTThere is no "<<<" expression, and ">>>", unsigned shift right, is a potentially useful operator in places. Though I doubt you'll see it often considering how rare << and >> are already. Brad
May 25 2005
Sam wrote:Hey, what's with this: if(a === null) Then does that mean I can do this: if(a !=== null)Yes. For now, at least... It's called '!==', though ? (compare with '==' and '!=' for equality expressions) Some people (like myself) think that's a *good* thing... (I happened to like the === [≡] and !== [≢], too bad)??? I'm sorry, this operator syntax looks stupid! Honestly! Why not create an operator 'is': if(a is null) Just like in SQL!Must be your lucky day then. Your wish has been granted, Walter has now deprecated the '===' identity expressions... "if (a is null)" is legal D code, since DMD 0.76 (Nov 2003). The naming jury is still out on the "not" version of 'is'.Or better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull)But you would still need 'null' for pointers ? And currently D uses: if (a) if (!a) But that might change too, some future day... --anders
May 26 2005
a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O Sam- sam987883 yahoo.comOr better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull)But you would still need 'null' for pointers ?
May 26 2005
I really don't see why having null is a problem. And I would never support anything that would make this: Class a; if (a.isnull) Legal, but this: Class a; if (a.prop) A segfault. Yuck, talk about confusing for newbies. -[Unknown]a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O Sam- sam987883 yahoo.comOr better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull)But you would still need 'null' for pointers ?
May 26 2005
You're right!! What was I smoking!! Sorry! What I meant was some static methods: class a {} if(!Object::isnull(a)) Object::makenull(a); How about these? They don't have to be under class Object: if(D::isnull(a)) D::nullify(a); D-licious!! In article <d74rpa$2miv$1 digitaldaemon.com>, Unknown W. Brackets says...I really don't see why having null is a problem. And I would never support anything that would make this: Class a; if (a.isnull) Legal, but this: Class a; if (a.prop) A segfault. Yuck, talk about confusing for newbies. -[Unknown]a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O Sam- sam987883 yahoo.comOr better yet, why not create a built-in operator, function or property on ALL classes that derive from Object called 'isnull'? If you do that, you can get rid of the 'null' keyword as it would become obsolete. if(a.isnull) if(!a.isnull)But you would still need 'null' for pointers ?
May 26 2005
Well, it would be: if (!Object.isnull(a)) ... else Object.nullify(a); But, still, that's longer than: if (a is null) ... else a = null; And also less clear. I don't think it is D's purpose to kill or hide pointers, either, and null is useful with pointers as well (essentially the same as 0, but much more clear.) What I'm having trouble understanding is really what problem this is meant to address; just that you don't like ===, is, and null? -[Unknown]You're right!! What was I smoking!! Sorry! What I meant was some static methods: class a {} if(!Object::isnull(a)) Object::makenull(a); How about these? They don't have to be under class Object: if(D::isnull(a)) D::nullify(a); D-licious!!
May 26 2005
Ok then why not put 'isnull' and 'nullify' into a namespace or make them built-in? Then: if(isnull(a)) .. else nullify(a); Granted it's not as small as the syntax with 'is' and 'null', but this eliminates the need for 'is' and 'null'. You see, to me my way is simpler: if(isnull(a)) // 1 isnull method, 1 argument if(a is null) // 1 is operator, 2 arguments (1 special keyword) nullify(a) // 1 method, 1 argument a = null // 1 operator, 2 arguments (1 special keyword) if(!isnull(a)) // 1 ! operator, 1 isnull method, 1 argument if(a !== null) // 1 !== operator, 2 arguments (1 special keyword) I am for a 'not' keyword though!! It's better than this '!' that carried over from c++! Recap of what I propose: Get rid of: 'null', 'true', 'false', '!', '!==', 'is' Add: 'not', 'isnull', 'nullify', 'truthify', 'falsify' ;-D In article <d7502f$2q6o$1 digitaldaemon.com>, Unknown W. Brackets says...Well, it would be: if (!Object.isnull(a)) ... else Object.nullify(a); But, still, that's longer than: if (a is null) ... else a = null; And also less clear. I don't think it is D's purpose to kill or hide pointers, either, and null is useful with pointers as well (essentially the same as 0, but much more clear.) What I'm having trouble understanding is really what problem this is meant to address; just that you don't like ===, is, and null? -[Unknown]
May 26 2005
Recap of what I propose: Get rid of: 'null', 'true', 'false', '!', '!==', 'is' Add: 'not', 'isnull', 'nullify', 'truthify', 'falsify'Sorry, doesn't get my vote (not that this is a democracy :) - I don't like that syntax at all. Brad
May 26 2005
THAT'S IT!! I have it with all of these keywords!!!! I'm coming up with MY OWN language called: E() In article <d754a6$2tpu$1 digitaldaemon.com>, Brad Beveridge says...Recap of what I propose: Get rid of: 'null', 'true', 'false', '!', '!==', 'is' Add: 'not', 'isnull', 'nullify', 'truthify', 'falsify'Sorry, doesn't get my vote (not that this is a democracy :) - I don't like that syntax at all. Brad
May 26 2005
Sam wrote:Ok then why not put 'isnull' and 'nullify' into a namespace or make them built-in? Then: if(isnull(a)) .. else nullify(a); Granted it's not as small as the syntax with 'is' and 'null', but this eliminates the need for 'is' and 'null'. You see, to me my way is simpler: if(isnull(a)) // 1 isnull method, 1 argument if(a is null) // 1 is operator, 2 arguments (1 special keyword) nullify(a) // 1 method, 1 argument a = null // 1 operator, 2 arguments (1 special keyword) if(!isnull(a)) // 1 ! operator, 1 isnull method, 1 argument if(a !== null) // 1 !== operator, 2 arguments (1 special keyword) I am for a 'not' keyword though!! It's better than this '!' that carried over from c++! Recap of what I propose: Get rid of: 'null', 'true', 'false', '!', '!==', 'is' Add: 'not', 'isnull', 'nullify', 'truthify', 'falsify' ;-DSorry, doesn't get my vote. Note that this is NOT Java, D is a systems programming language, not a scripting language or smalltalk. (note: I'm not implying that java is a scripting language) BUT ... You can always write the functions yourself .. bool isnull( void *p ) { return (p is null); } void nullify(out void *p) { p = null; } What's the problem with that? Why don't you write that yourself and stop using null if you don't like it?
May 26 2005
But see you've already gotten in trouble with the 'null' keyword! You can't do: a = null; or if(a == null) So as you see, it just spreads confusion! C++ is a systems language and it had no 'null' keyword, and nobody complained! Some defined their own null constant. I know D isn't C++ either, but if you're trying to invent the perfect language, the perfect language at least in my opinion wouldn't have the 'null' keyword. that they added them in purely for show and to make their languages look nice. cout << null; // Exception! In article <d755f4$2usp$1 digitaldaemon.com>, Hasan Aljudy says...Sorry, doesn't get my vote. Note that this is NOT Java, D is a systems programming language, not a scripting language or smalltalk. (note: I'm not implying that java is a scripting language) BUT ... You can always write the functions yourself .. bool isnull( void *p ) { return (p is null); } void nullify(out void *p) { p = null; } What's the problem with that? Why don't you write that yourself and stop using null if you don't like it?
May 26 2005
Sam wrote:But see you've already gotten in trouble with the 'null' keyword! You can't do: a = null;No ? Why ?believe that they added them in purely for show and to make their languages look nice.Ok, you asked for it... Here it comes... WTF ?!cout << null; // Exception!Exception ? It's C++. If null was #define'd to 0, it would print... "0", not raise an exception... -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
May 26 2005
Sam wrote:But see you've already gotten in trouble with the 'null' keyword! You can't do: a = null; or if(a == null)Where is the trouble if you are wrapping it? of course you HAVE to use it inside the function that wraps it .. what else would you expect?So as you see, it just spreads confusion!I don't see that. Where is the confusion? remember, you're probably the one who's gonna use "isnull" and "nullify" :PC++ is a systems language and it had no 'null' keyword, and nobody complained! Some defined their own null constant.heh .. so are you saying D shouldn't have a 0? I know you're not saying that, but if %99 percent of the people will define an alias for 'null' to zero, then what's the point? The only way we could do what you want is to remove 0 alltogether.I know D isn't C++ either, but if you're trying to invent the perfect language, the perfect language at least in my opinion wouldn't have the 'null' keyword.Why? huh? Why? just because /you/ don't like it?believe that they added them in purely for show and to make their languages look nice.and 1. 0 and 1 are integers, true and false are booleans, you CANNOT implicitly convert ints to booleans in Java. So it's not just for the language to look nice .. it's *strong* typing. Also, null in java is *NOT* an alias for 0, infact, you can't compare references against null. [Java code:] Object x; //x is a reference, not an object if( x == 0 ) //compiler error: x is not an int. ..... [/Java code]cout << null; // Exception!what the other guy said .. << is overloaded (I assume) for different types, so it's not like << expects objects. when you pass a null, it's not a null pointer, it's a 0 integer.In article <d755f4$2usp$1 digitaldaemon.com>, Hasan Aljudy says...Sorry, doesn't get my vote. Note that this is NOT Java, D is a systems programming language, not a scripting language or smalltalk. (note: I'm not implying that java is a scripting language) BUT ... You can always write the functions yourself .. bool isnull( void *p ) { return (p is null); } void nullify(out void *p) { p = null; } What's the problem with that? Why don't you write that yourself and stop using null if you don't like it?
May 26 2005
ouch, typo: I wrote:Also, null in java is *NOT* an alias for 0, infact, you can't compare references against null.I meant: "you can't compare references against 0"
May 26 2005
Sam wrote:Recap of what I propose: Get rid of: 'null', 'true', 'false', '!', '!==', 'is' Add: 'not', 'isnull', 'nullify', 'truthify', 'falsify'The less keywords a language has, the simpler it bacomes and the easier it is to learn.So you propose a removal of 4 simple and short keywords and two operators and want to add 5 new keywords, some of which I'd wonder if are valid English words at all. That will make the language definitely easier to learn! What's next ? Are you gonna tell us to remove char, wchar and dchar because they are sooooo redundant and then suggest adding char8859_1, char8859_2, char8859_3, charXXX, etc ? :\ -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
May 26 2005
Sam wrote:You mean you would define some built-in properties for regular pointers as well ? Like "isnull", for instance. And even add methods to them ? Like this "makenull" here. Without having it dereference it, like other such calls ? Sounds kinda confusing. Especially with any pointers to structs... (trying to guess which are built-in properties, which are fields ?) And I really don't think "p.isnull()" is clearer than "p == null". It might be a little clearer than "p", but that's another topic. --anders PS. void* p; // not an object, as '== null' segfaults with those.But you would still need 'null' for pointers ?a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O
May 26 2005