By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Debug behavior

P: n/a
Well, I' surprised by a thing in VB.NET
I have a property GetUniqueID as String in a class and a private member
UniqueID
This property only increment variable UniqueID (UniqueID+=1) and return new
value.
What I noticed is that in debug mode, every time I hover the mouse to a call
to that property in order to see the curent value, actualy the code is
executed and the variable remain changed

This is normal?

I whould espected only to simulte the execution of get block of my property
and return the value not effectively change the value in the class, so
instead having nice ordered ID's I have some much bigger values at every
debug test

What you think?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Crirus" <Cr****@datagroup.ro> schrieb
Well, I' surprised by a thing in VB.NET
I have a property GetUniqueID as String in a class and a private
member UniqueID
This property only increment variable UniqueID (UniqueID+=1) and
return new value.
What I noticed is that in debug mode, every time I hover the mouse to
a call to that property in order to see the curent value, actualy the
code is executed and the variable remain changed

This is normal?


Yes. A property should *always* return the same value when called twice - or
at least it should not return a different value just because of the call
itself. Use a function instead. The name "Get*" already expresses that it is
a function.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
Also including the debugging issue:
http://groups.google.com/groups?selm...tngp13.phx.gbl

;-)

--
Armin

Nov 20 '05 #3

P: n/a
* "Crirus" <Cr****@datagroup.ro> scripsit:
Well, I' surprised by a thing in VB.NET
I have a property GetUniqueID as String in a class and a private member
UniqueID
This property only increment variable UniqueID (UniqueID+=1) and return new
value.
What I noticed is that in debug mode, every time I hover the mouse to a call
to that property in order to see the curent value, actualy the code is
executed and the variable remain changed


That's a typical case for using a /method/ instead of a property.
Properties are used to model attributes of an entity. Calculating a new
ID is not an attribute, it's a thing the object can do (implemented as a
method).

\\\
Public Function GetUniqueId() As Integer
UniqueID = UniqueID + 1
Return UniqueID
End Function
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
"Crirus" <Cr****@datagroup.ro> schrieb
OK, I can work around that, but is normal?
Yes
I think not, a debug call as a warch shouldnt execute anything in the
same scope as programm itself, right?


It must execute the code. How else should it get the property value?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
I was thinking on executing but not modifying the data

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
OK, I can work around that, but is normal?


Yes
I think not, a debug call as a warch shouldnt execute anything in the
same scope as programm itself, right?


It must execute the code. How else should it get the property value?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6

P: n/a
"Crirus" <Cr****@datagroup.ro> schrieb
I was thinking on executing but not modifying the data

Executing what? I thought _you_ are modifying the data in the property get
procedure.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

P: n/a
No what I meant was kind of "simulating" the code execution in order to give
me the correct value, but without retaining in the real code the value
returned, so each time I hover the mouse on a property call, to see the same
value as the excution thread will get first time

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
I was thinking on executing but not modifying the data

Executing what? I thought _you_ are modifying the data in the property get
procedure.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8

P: n/a
"Crirus" <Cr****@datagroup.ro> schrieb
No what I meant was kind of "simulating" the code execution in order
to give me the correct value, but without retaining in the real code
the value returned, so each time I hover the mouse on a property
call, to see the same value as the excution thread will get first
time


Well, it doesn't work this way (I can't imagine how it could). To get the
property value the property-get procedure is called. Sorry, there's nothing
more I can say.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

P: n/a
Yes but any watch will comnpromise the real value that should be returned by
the property as if I dont wach it :(

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uW****************@tk2msftngp13.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
No what I meant was kind of "simulating" the code execution in order
to give me the correct value, but without retaining in the real code
the value returned, so each time I hover the mouse on a property
call, to see the same value as the excution thread will get first
time
Well, it doesn't work this way (I can't imagine how it could). To get the
property value the property-get procedure is called. Sorry, there's

nothing more I can say.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10

P: n/a
"Crirus" <Cr****@datagroup.ro> schrieb
Yes but any watch will comnpromise the real value that should be
returned by the property as if I dont wach it :(


It is your mistake that you change the value. As already mentioned, you must
use a function instead.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #11

P: n/a
I will :)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
Yes but any watch will comnpromise the real value that should be
returned by the property as if I dont wach it :(
It is your mistake that you change the value. As already mentioned, you

must use a function instead.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.