473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Better way

Hi

I'm curious - which is the better ".NET" method to use if needing to know if
an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...

TIA
Steve
Dec 12 '05 #1
16 1224
"Steve Peterson" <sp*******@nospam.com> schrieb:
I'm curious - which is the better ".NET" method to use if needing to know
if an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...


I believe the decision should be based on personal preference. I prefer the
latter one.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #2
Me too. My favorite part is when I can write:

If Not MyObject is Nothing ...

Take that all you english teachers :P

"Herfried K. Wagner [MVP]" wrote:
"Steve Peterson" <sp*******@nospam.com> schrieb:
I'm curious - which is the better ".NET" method to use if needing to know
if an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...


I believe the decision should be based on personal preference. I prefer the
latter one.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #3
If Not MyObject is Nothing ...

Take that all you english teachers :P
this is cool :-)
but serious now ... i prefer IsNothing(myobject) as it is more clear in my
opinion , but as said by the others it is more a personal preference
maybe because i also program a lot in T-sql where simular syntax is used
( isnull etc etc function calls ) i just automaticly typ this in

regards

Michel Posseth [MCP]

"TrtnJohn" <Tr******@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com... Me too. My favorite part is when I can write:

If Not MyObject is Nothing ...

Take that all you english teachers :P

"Herfried K. Wagner [MVP]" wrote:
"Steve Peterson" <sp*******@nospam.com> schrieb:
> I'm curious - which is the better ".NET" method to use if needing to
> know
> if an object is Nothing?
>
> 1: If IsNothing(myobject) ...
>
> or
>
> 2. If myobject Is Nothing ...


I believe the decision should be based on personal preference. I prefer
the
latter one.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #4
"TrtnJohn" <Tr******@discussions.microsoft.com> schrieb:
Me too. My favorite part is when I can write:

If Not MyObject is Nothing ...

Take that all you english teachers :P


VB 2005 supports the patented 'IsNot' operator:

\\\
If MyObject IsNot Nothing Then...
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Dec 12 '05 #5
Let's not forget, new to VB 2005:

If MyObject IsNot Nothing

You can also do this:

If Not MyObject IsNot Nothing

What would your english teacher say now?

Dec 12 '05 #6

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Let's not forget, new to VB 2005:

If MyObject IsNot Nothing

You can also do this:

If Not MyObject IsNot Nothing

What would your english teacher say now?
Get back in school! Either that or "Oh, my gawd!"

Dec 12 '05 #7
After seeing all the English lessons, I guess I should clarify:

Performance-wise which is better?
Which method is the backward-compatible method to the VB6 days..
Which method should I get in the habit of using to be ".NET" correct?

Steve

PS Just to throw in my 2 cents worth - I have been using the
"IsNothing(myobject)" method.. IN my mind it sounds more "rational". If I
want to negate it it is: If Not IsNothing(myobject).. I dunno - just sounds
more logical...

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

I'm curious - which is the better ".NET" method to use if needing to know
if an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...

TIA
Steve

Dec 12 '05 #8
Steve,
In addition to the other comments. Its largely personal preference.

However:
| 1: If IsNothing(myobject) ...

Is two function calls into a library, which may or may not be in-lined by
the JIT compiler.
//000038: If IsNothing(myobject) Then
IL_0003: ldloc.2
IL_0004: call object
[mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::Ge tObjectValue(object)
IL_0009: call bool
[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
IL_000e: stloc.s VB$CG$t_bool$S0
IL_0010: ldloc.s VB$CG$t_bool$S0
IL_0012: brfalse.s IL_0014
//000039:
//000040: End If
IL_0014: nop
While:

| 2. If myobject Is Nothing ...

Is inline IL code.
//000041: If myobject Is Nothing Then
IL_0015: ldloc.2
IL_0016: ldnull
IL_0017: ceq
IL_0019: stloc.s VB$CG$t_bool$S0
IL_001b: ldloc.s VB$CG$t_bool$S0
IL_001d: brfalse.s IL_001f
//000042:
//000043: End If
IL_001f: nop
FWIW: the "patented" IsNot operator also generates IL code. Oddly enough it
generates the same code that C#'s reference inequality operator has been
generating since C# 1.0.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
| Hi
|
| I'm curious - which is the better ".NET" method to use if needing to know
if
| an object is Nothing?
|
| 1: If IsNothing(myobject) ...
|
| or
|
| 2. If myobject Is Nothing ...
|
| TIA
| Steve
|
|
Dec 12 '05 #9
I should add that the IL code I gave is for the Debug build, the Release
build's IL is optimized slightly. Plus the JIT will optimize the Release
build even more, such as inlining the GetObjectValue and/or the IsNothing
method themselves. So performance wise you really need to profile the
routine & determine if that routine needs to be "micro optimized" by
choosing IsNothing() over Is Nothing.

As I & others stated, its personal preference.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:eN**************@TK2MSFTNGP09.phx.gbl...
| Steve,
| In addition to the other comments. Its largely personal preference.
|
| However:
|| 1: If IsNothing(myobject) ...
|
| Is two function calls into a library, which may or may not be in-lined by
| the JIT compiler.
| //000038: If IsNothing(myobject) Then
| IL_0003: ldloc.2
| IL_0004: call object
|
[mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::Ge tObjectValue(object)
| IL_0009: call bool
|
[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
| IL_000e: stloc.s VB$CG$t_bool$S0
| IL_0010: ldloc.s VB$CG$t_bool$S0
| IL_0012: brfalse.s IL_0014
| //000039:
| //000040: End If
| IL_0014: nop
|
|
| While:
|
|| 2. If myobject Is Nothing ...
|
| Is inline IL code.
| //000041: If myobject Is Nothing Then
| IL_0015: ldloc.2
| IL_0016: ldnull
| IL_0017: ceq
| IL_0019: stloc.s VB$CG$t_bool$S0
| IL_001b: ldloc.s VB$CG$t_bool$S0
| IL_001d: brfalse.s IL_001f
| //000042:
| //000043: End If
| IL_001f: nop
|
|
| FWIW: the "patented" IsNot operator also generates IL code. Oddly enough
it
| generates the same code that C#'s reference inequality operator has been
| generating since C# 1.0.
|
| --
| Hope this helps
| Jay [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
|
|
| "Steve Peterson" <sp*******@nospam.com> wrote in message
| news:%2****************@TK2MSFTNGP14.phx.gbl...
|| Hi
||
|| I'm curious - which is the better ".NET" method to use if needing to know
| if
|| an object is Nothing?
||
|| 1: If IsNothing(myobject) ...
||
|| or
||
|| 2. If myobject Is Nothing ...
||
|| TIA
|| Steve
||
||
|
|
Dec 12 '05 #10
Chris,

I never understand (beside that it is something more difficult to build for
the ones who have to translate the source to the code), that never is used

If MyObject Is Something

It seems for me that for English speaking people Something means something
different from Not Nothing or IsNot Nothing.

Cor
Dec 13 '05 #11
Steve,
Performance-wise which is better?
Which method is the backward-compatible method to the VB6 days..
Which method should I get in the habit of using to be ".NET" correct?

In 2005, for me it is more important that the program is easy to understand
when it has to be maintanance than those (not even realistic) 10 seconds
that we can win with 1000 users in a year. (Not realistic because users have
their natural wait moments).

Backwards compatible is only important for old programs. New programs have
no backward compatible problems, only forward compatible problems, which is
the problem from Microsoft, not ours, they have to keep an eye on that or
write converters.

Every method that can be used in Net is .Net correct.

Just my thought,

Cor
"Steve Peterson" <sp*******@nospam.com> schreef in bericht
news:es*************@TK2MSFTNGP14.phx.gbl... After seeing all the English lessons, I guess I should clarify:

Performance-wise which is better?
Which method is the backward-compatible method to the VB6 days..
Which method should I get in the habit of using to be ".NET" correct?

Steve

PS Just to throw in my 2 cents worth - I have been using the
"IsNothing(myobject)" method.. IN my mind it sounds more "rational". If I
want to negate it it is: If Not IsNothing(myobject).. I dunno - just
sounds more logical...

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

I'm curious - which is the better ".NET" method to use if needing to know
if an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...

TIA
Steve


Dec 13 '05 #12
> In 2005, for me it is more important that the program is easy to
understand

In the year 2005, for ..........

It can be confuse with the Visual Studio version, therefore this message
Dec 13 '05 #13
>>
1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...


I believe the decision should be based on personal preference. I prefer
the latter one.

me too

Cor
Dec 13 '05 #14
Cor,
| It seems for me that for English speaking people Something means something
| different from Not Nothing or IsNot Nothing.
I don't know, I would have preferred "Something" to be an alias for "IsNot
Nothing", however with the IsNot you can compare two distinct instances.:

Dim obj1 As New ...
Dim obj2 As New ...

If obj1 IsNot obj2 Then
' do this
End If

Personally I would like to see both IsNot & Something.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
| Chris,
|
| I never understand (beside that it is something more difficult to build
for
| the ones who have to translate the source to the code), that never is used
|
| If MyObject Is Something
|
| It seems for me that for English speaking people Something means something
| different from Not Nothing or IsNot Nothing.
|
| Cor
|
|
Dec 13 '05 #15
Jay,

I agree although I tend still more for

If Not obj1 Is obj2 Then

You know probably already that I don't like created not English words in
VB.Net.

One of the reasons, they are not to find for people for who English is daily
not the first language in a (translation) dictionary, and because those are
never complete, we are never sure if the word exist, although I use now
than Internet.

:-)

Cor

Dim obj1 As New ...
Dim obj2 As New ...

If obj1 IsNot obj2 Then
' do this
End If

Personally I would like to see both IsNot & Something.

--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
| Chris,
|
| I never understand (beside that it is something more difficult to build
for
| the ones who have to translate the source to the code), that never is
used
|
| If MyObject Is Something
|
| It seems for me that for English speaking people Something means
something
| different from Not Nothing or IsNot Nothing.
|
| Cor
|
|

Dec 13 '05 #16
On 2005-12-12, Steve Peterson <sp*******@nospam.com> wrote:
After seeing all the English lessons, I guess I should clarify:

Performance-wise which is better?
In theory, myObject Is Nothing is slightly faster, since IsNothing
requires a function call. In reality, the function call is likely to get
Jitted away, and even if it didn't you're just not going to notice any
difference.
Which method is the backward-compatible method to the VB6 days..
Which method should I get in the habit of using to be ".NET" correct?
Like others have said, it's personal preference. But "object Is
Nothing" does correspond a bit more closely to the way other .Net
languages tend to handle this construct.

Whether that matters is up to you.

Steve

PS Just to throw in my 2 cents worth - I have been using the
"IsNothing(myobject)" method.. IN my mind it sounds more "rational". If I
want to negate it it is: If Not IsNothing(myobject).. I dunno - just sounds
more logical...

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

I'm curious - which is the better ".NET" method to use if needing to know
if an object is Nothing?

1: If IsNothing(myobject) ...

or

2. If myobject Is Nothing ...

TIA
Steve


Dec 14 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18803
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
2021
by: Muhd | last post by:
<usualDisclaimer>Please forgive me if this is in the wrong group, and if so, what is the right group.</usualDisclaimer> Let me start off by first saying im a newb. Ok, with that out of the way I...
24
3406
by: Faith Dorell | last post by:
I really don´t like C.You can write better programs in BASIC than in C, if you don´t like this language. I don´t understand how C became so popular, although much better programming languages...
43
3358
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
33
2523
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
22
2684
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
19
1849
by: Alexandre Badez | last post by:
I'm just wondering, if I could write a in a "better" way this code lMandatory = lOptional = for arg in cls.dArguments: if arg is True: lMandatory.append(arg) else: lOptional.append(arg)...
23
2329
by: mike3 | last post by:
Hi. (posted to both newsgroups since I was not sure of which would be appropriate for this question or how specific to the given language it is. If one of them is inappropriate, just don't send...
20
3043
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
3
3563
by: Ryan Liu | last post by:
Hi, Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than synchronous I/O? At least as good? When I don't concern about easy or difficult to write code, should I always...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.