digitalmars.D - Some operators in D...
- Sam <Sam_member pathlink.com> May 25 2005
- Derek Parnell <derek psych.ward> May 25 2005
- Brad Beveridge <brad somewhere.net> May 25 2005
- =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= <afb algonet.se> May 26 2005
- Sam <Sam_member pathlink.com> May 26 2005
- "Unknown W. Brackets" <unknown simplemachines.org> May 26 2005
- Sam <Sam_member pathlink.com> May 26 2005
- "Unknown W. Brackets" <unknown simplemachines.org> May 26 2005
- Sam <Sam_member pathlink.com> May 26 2005
- Brad Beveridge <brad somewhere.net> May 26 2005
- Sam <Sam_member pathlink.com> May 26 2005
- Hasan Aljudy <hasan.aljudy gmail.com> May 26 2005
- Sam <Sam_member pathlink.com> May 26 2005
- Tom S <h3r3tic remove.mat.uni.torun.pl> May 26 2005
- Hasan Aljudy <hasan.aljudy gmail.com> May 26 2005
- Hasan Aljudy <hasan.aljudy gmail.com> May 26 2005
- Tom S <h3r3tic remove.mat.uni.torun.pl> May 26 2005
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> May 26 2005
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)
??? I'm sorry, this operator syntax looks stupid! Honestly! Why not create an operator 'is': if(a is null)
looking like they'll get deprecated.I also don't like '<<<', and I have seen '<<<=' and '>>>=' in javascript. NOT
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
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 ?
a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O Sam- sam987883 yahoo.com
May 26 2005
But people used to C++ are going to appreciate it. And C# also uses null. 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]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 ?
a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O Sam- sam987883 yahoo.com
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...
But people used to C++ are going to appreciate it. And C# also uses null.
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]
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 ?
a.makenull();
How about this??? I still believe the 'null' keyword can be deprecated! :-O
Sam-
sam987883 yahoo.com
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' ;-D
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
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. I know C# and java have 'true', 'false', and 'null' keywords but I truly believe 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 ?I know C# and java have 'true', 'false', and 'null' keywords but I truly 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)
it inside the function that wraps it .. what else would you expect?So as you see, it just spreads 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.
just because /you/ don't like it?I know C# and java have 'true', 'false', and 'null' keywords but I truly believe that they added them in purely for show and to make their languages look nice.
I don't know about C#, but in Java, true and false are not aliases for 0 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.
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:But you would still need 'null' for pointers ?
a.makenull(); How about this??? I still believe the 'null' keyword can be deprecated! :-O
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.
May 26 2005









Derek Parnell <derek psych.ward> 