Comment On Representative Property: MaxRetry

"I’m a big fan of the Representative Line series," Rich writes, "it tells so much about an application in so little. While there are plenty of representative lines I could show about our application, I thought I’d show something else: a representative property." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: Representative Property: MaxRetry

2011-07-27 11:07 • by The Enterpriser
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.

VGhhdCBpcyBkb3VibGUgZW5jcnlwdGlvbi4=

Re: Representative Property: MaxRetry

2011-07-27 11:09 • by Omnomnonymous (unregistered)
Frist {Failed}
Error: Max attempts reached! Skipping

Re: Representative Property: MaxRetry

2011-07-27 11:17 • by Hooah (unregistered)
This is a common thing to do on an embedded machine with no filesystem.

Re: Representative Property: MaxRetry

2011-07-27 11:20 • by Warren (unregistered)
I like the fact that the "Representative Line" page linked to doesn't include this article.

Re: Representative Property: MaxRetry

2011-07-27 11:22 • by Some damn Yank (unregistered)
355018 in reply to 355009
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?

Re: Representative Property: MaxRetry

2011-07-27 11:25 • by Some damn Yank (unregistered)
355019 in reply to 355017
Warren:
I like the fact that the "Representative Line" page linked to doesn't include this article.
That's because this isn't a Representative Line example, it's the first of a new series: Representative Property.

CAPTCHA: sino. Yah, sino, it should be obvious if you read the title.

Re: Representative Property: MaxRetry

2011-07-27 11:26 • by GFK
I love how MaxRetry always equals maxRetry but sometimes maxRetry does not equal MaxRetry (but if you ask again, it will). You just defeated the symmetry of the equality operator, thanks for playing. I'm sure Resharper doesn't take in account this perversion when innocently proposing to switch equality operators.

Re: Representative Property: MaxRetry

2011-07-27 11:29 • by Steve The Cynic
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).

Sick. Whoever did this should be punished. Severely. With a baseball bat.

Re: Representative Property: MaxRetry

2011-07-27 11:31 • by VictorSierraGolf (unregistered)
355022 in reply to 355020
I also love how 2+2 always equals 4 but sometimes equals 5...

Re: Representative Property: MaxRetry

2011-07-27 11:33 • by Mister Cheese (unregistered)
355023 in reply to 355018
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.

Re: Representative Property: MaxRetry

2011-07-27 11:36 • by @Deprecated
355024 in reply to 355015
Hooah:
This is a common thing to do on an embedded machine with no filesystem.


Clearly this is C#, which you would be hard pressed to find on that class of device.

Re: Representative Property: MaxRetry

2011-07-27 11:38 • by The Enterpriser
355025 in reply to 355018
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


It isn't a lie. It is set to 5 each time it is read. This prevents outside use from having visibility of internal use.

e.g. if I want to use this from within the method I could set via the property and then retrieve through the private member:

 

//increase performance through larger maximum number of retries
lock(this) { //make it thread safe
MaxRetry = 20;
performAction(yhbt,maxRetry); //whatever it is
}


This way no outside code is going to ever interfere with your retries, and they cannot abuse the property to steal importante cpu cycles

Re: Representative Property: MaxRetry

2011-07-27 11:40 • by C-Octothorpe
355026 in reply to 355021
Steve The Cynic:
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).

Sick. Whoever did this should be punished. Severely. By zunesis.
FTFY

Re: Representative Property: MaxRetry

2011-07-27 11:41 • by VeryBestDeveloperNumber1 (unregistered)
355027 in reply to 355024
@Deprecated:
Hooah:
This is a common thing to do on an embedded machine with no filesystem.


Clearly this is C#, which you would be hard pressed to find on that class of device.


I program my toaster in visual basic.

Re: Representative Property: MaxRetry

2011-07-27 11:41 • by C-Octothorpe
355028 in reply to 355025
The Enterpriser:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


It isn't a lie. It is set to 5 each time it is read. This prevents outside use from having visibility of internal use.

e.g. if I want to use this from within the method I could set via the property and then retrieve through the private member:

 

//increase performance through larger maximum number of retries
lock(this) { //make it thread safe
MaxRetry = 20;
performAction(yhbt,maxRetry); //whatever it is
}


This way no outside code is going to ever interfere with your retries, and they cannot abuse the property to steal importante cpu cycles
You almost got me...

Re: Representative Property: MaxRetry

2011-07-27 11:41 • by XIU
355029 in reply to 355023
Mister Cheese:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.


The code will set the field to 5 AND return 5

Re: Representative Property: MaxRetry

2011-07-27 11:43 • by Zylon
355030 in reply to 355015
Hooah:
This is a common thing to do on an embedded machine with no filesystem.

I can tell from your pixels that you're pretty stupid, so I guess I need to inform you that the thing you just posted, even when posted ironically, has been beyond lame for months. It's not even "Ha ha he posted something deliberately unfunny" funny anymore.

Re: Representative Property: MaxRetry

2011-07-27 11:44 • by Out of Topic (unregistered)
355031 in reply to 355024
@Deprecated:
Hooah:
This is a common thing to do on an embedded machine with no filesystem.


Clearly this is C#, which you would be hard pressed to find on that class of device.


You haven't heard of the Netduino (http://netduino.com/) ?

Re: Representative Property: MaxRetry

2011-07-27 11:46 • by Anonymous Cow-Herd (unregistered)
355032 in reply to 355029
XIU:
Mister Cheese:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.


The code will set the field to 5 AND return 5


Surely it sets the field to 5 and returns true?

Re: Representative Property: MaxRetry

2011-07-27 11:50 • by Lowmack (unregistered)
355033 in reply to 355032
Anonymous Cow-Herd:
XIU:
Mister Cheese:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.


The code will set the field to 5 AND return 5


Surely it sets the field to 5 and returns true?


You're right, and don't call me Shirley.

Re: Representative Property: MaxRetry

2011-07-27 11:53 • by Robajob
355035 in reply to 355025
If the idea is really just to make the internal value writeable but not readable, wouldn't it be easier to omit the get accessor?

Re: Representative Property: MaxRetry

2011-07-27 11:54 • by ted (unregistered)
355036 in reply to 355030
Zylon:
Hooah:
This is a common thing to do on an embedded machine with no filesystem.

I can tell from your pixels that you're pretty stupid, so I guess I need to inform you that the thing you just posted, even when posted ironically, has been beyond lame for months. It's not even "Ha ha he posted something deliberately unfunny" funny anymore.


MaxRetry:

In case you can't tell, this is a grown up place. The fact that you continue to insist on being a faggoty square clearly shows that you're too out of touch and too stupid to appreciate good humor.

Go away and grow up.

Sincerely,
Go get fucked.

Re: Representative Property: MaxRetry

2011-07-27 11:58 • by Cheese (unregistered)
355037 in reply to 355024
@Deprecated:
Hooah:
This is a common thing to do on an embedded machine with no filesystem.


Clearly this is C#, which you would be hard pressed to find on that class of device.


Although there are faster alternatives, the .NET Micro Framework is used on quite a few machines with no file system.
http://en.wikipedia.org/wiki/.NET_Micro_Framework

Re: Representative Property: MaxRetry

2011-07-27 12:01 • by trtrwtf (unregistered)
355038 in reply to 355026
C-Octothorpe:
Steve The Cynic:
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).

Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY



Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.

Re: Representative Property: MaxRetry

2011-07-27 12:01 • by C-Octothorpe
355039 in reply to 355035
Robajob:
If the idea is really just to make the internal value writeable but not readable, wouldn't it be easier to omit the get accessor?
If you really want to seal up a class, just have get accessors (who cares if you can read it, unless it's a ref type of course), and set the internal private value via ctor overload.

Re: Representative Property: MaxRetry

2011-07-27 12:03 • by Cheese (unregistered)
355040 in reply to 355035
Robajob:
If the idea is really just to make the internal value writeable but not readable, wouldn't it be easier to omit the get accessor?


True, but maybe they wanted it to be serializable :)

Re: Representative Property: MaxRetry

2011-07-27 12:06 • by Some damn Yank (unregistered)
355041 in reply to 355033
Lowmack:
Anonymous Cow-Herd:
XIU:
The code will set the field to 5 AND return 5

Surely it sets the field to 5 and returns true?

You're right, and don't call me Shirley.
OK, first off he didn't call you "Shirley", he called Anonymous Cow-Herd "Shirley", and for all you know that's her name.

Second, the more I look at this the more I realize this code isn't devious, it's evil.

"What's the maximum number of retrys?" "True." "No, I need a number; what's the maximum number of retrys?" "True." "Your answer doesn't make any sense." "True." "OK, let's set maxRetry to 23. Now, what's the value of maxRetry?" "True."

Re: Representative Property: MaxRetry

2011-07-27 12:08 • by zunesis (the one, the only, the well-hung, yada yada yada) (unregistered)
355044 in reply to 355038
trtrwtf:
C-Octothorpe:
Steve The Cynic:
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).
Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
What does it mean that my most irritating and despicable sockpuppet is also the most beloved around here?

Re: Representative Property: MaxRetry

2011-07-27 12:09 • by hoodaticus
355045 in reply to 355032
Anonymous Cow-Herd:
XIU:
Mister Cheese:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.


The code will set the field to 5 AND return 5


Surely it sets the field to 5 and returns true?
That's the C++ behavior. But I don't think it would compile in C#.

Re: Representative Property: MaxRetry

2011-07-27 12:10 • by hoodaticus
355046 in reply to 355039
C-Octothorpe:
Robajob:
If the idea is really just to make the internal value writeable but not readable, wouldn't it be easier to omit the get accessor?
If you really want to seal up a class, just have get accessors (who cares if you can read it, unless it's a ref type of course), and set the internal private value via ctor overload.
This is a lesson for people who want immutability.

Re: Representative Property: MaxRetry

2011-07-27 12:10 • by E. Pesker (unregistered)
I'm not sure I see the problem here.

Clearly there was a bug in where under some condition this "maxRetries" (which i'm guessing was used to control logging or something) needed to be 5, and luckily that was only condition in which the getter was being called (probably just used to check that the value was indeed 5).

So- this is really a quite elegant surgical fix here: it works, and doesn't hurt anything. Where's the wtf?

Re: Representative Property: MaxRetry

2011-07-27 12:11 • by Some damn Yank (unregistered)
355048 in reply to 355035
Robajob:
If the idea is really just to make the internal value writeable but not readable, wouldn't it be easier to omit the get accessor?
I don't think the idea is to make it writeable but not readable. I think the idea was to limit the value to 5. But that's not what this code does. It sets maxRetry to 5 when you read it; you can write it to anything you like, which to me is the real WTF. In effect, there is no max. The fact that maxRetry is 1 until someone wants to know what it is, at which point you make it 5, is just a sidebar WTF.

Re: Representative Property: MaxRetry

2011-07-27 12:12 • by Robajob
355049 in reply to 355032
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.

Re: Representative Property: MaxRetry

2011-07-27 12:12 • by @Deprecated
355050 in reply to 355037
Cheese:
@Deprecated:
Hooah:
This is a common thing to do on an embedded machine with no filesystem.


Clearly this is C#, which you would be hard pressed to find on that class of device.


Although there are faster alternatives, the .NET Micro Framework is used on quite a few machines with no file system.
http://en.wikipedia.org/wiki/.NET_Micro_Framework


Initial hardware released in 2010... so that's like 1 device out of 5.3 skillion other devices.

So I stand by my original statement, which was: Hooah's post is lame.

Re: Representative Property: MaxRetry

2011-07-27 12:13 • by The Enterpriser
355051 in reply to 355047
E. Pesker:
I'm not sure I see the problem here.

Clearly there was a bug in where under some condition this "maxRetries" (which i'm guessing was used to control logging or something) needed to be 5, and luckily that was only condition in which the getter was being called (probably just used to check that the value was indeed 5).

So- this is really a quite elegant surgical fix here: it works, and doesn't hurt anything. Where's the wtf?


There's a lot of wtfs with this, but if you wanted to actually understand how this came to be - it (the "= 5") is probably just someone's quick debugging code which they forgot to remove. Without it, the code would be fine.

Re: Representative Property: MaxRetry

2011-07-27 12:13 • by hoodaticus
355052 in reply to 355049
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...

Re: Representative Property: MaxRetry

2011-07-27 12:15 • by The Enterpriser
355053 in reply to 355032
Anonymous Cow-Herd:
XIU:


The code will set the field to 5 AND return 5


Surely it sets the field to 5 and returns true?


It returns '5'.

Also, 'true' is not an int.

Re: Representative Property: MaxRetry

2011-07-27 12:17 • by trtrwtf (unregistered)
355056 in reply to 355044
zunesis (the one, the only, the well-hung, yada yada yada):
trtrwtf:
C-Octothorpe:
Steve The Cynic:
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).
Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
What does it mean that my most irritating and despicable sockpuppet is also the most beloved around here?


In my case, it means I'm doing my best to defuse the shock value and take some of the fun out of it. Seems to be working.

Re: Representative Property: MaxRetry

2011-07-27 12:18 • by zunesis (the one, the only, the well-hung, yada yada yada) (unregistered)
355057 in reply to 355038
trtrwtf:
C-Octothorpe:
Steve The Cynic:

Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
Indeed, I think the answer is pretty obvious - use the baseball bat, just don't simply swing it at him.

Re: Representative Property: MaxRetry

2011-07-27 12:19 • by C-Octothorpe
355058 in reply to 355052
hoodaticus:
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...
He was trying to correct someone else who thought that
 {return maxRetry = 5}
returns a bool.

Re: Representative Property: MaxRetry

2011-07-27 12:22 • by spivonious (unregistered)
355060 in reply to 355025
The Enterpriser:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


It isn't a lie. It is set to 5 each time it is read. This prevents outside use from having visibility of internal use.

e.g. if I want to use this from within the method I could set via the property and then retrieve through the private member:

 

//increase performance through larger maximum number of retries
lock(this) { //make it thread safe
MaxRetry = 20;
performAction(yhbt,maxRetry); //whatever it is
}


This way no outside code is going to ever interfere with your retries, and they cannot abuse the property to steal importante cpu cycles


Or you can just mark the setter as private and avoid this nonsense.

Re: Representative Property: MaxRetry

2011-07-27 12:24 • by hoodaticus
355061 in reply to 355058
C-Octothorpe:
hoodaticus:
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...
He was trying to correct someone else who thought that
 {return maxRetry = 5}
returns a bool.
The only part of that that I agree with is that assignment returns.

Void.

Re: Representative Property: MaxRetry

2011-07-27 12:28 • by C-Octothorpe
355062 in reply to 355061
hoodaticus:
C-Octothorpe:
hoodaticus:
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...
He was trying to correct someone else who thought that
 {return maxRetry = 5}
returns a bool.
The only part of that that I agree with is that assignment returns.

Void.
In this case
{return maxRetry = 5}
it returns a 5 and in this case
{return maxRetry == 5}
it returns a bool. Sorry, I'm not sure if I'm following (got 2 hour of sleep last night, again).

Re: Representative Property: MaxRetry

2011-07-27 12:30 • by trtrwtf (unregistered)
355063 in reply to 355057
zunesis (the one, the only, the well-hung, yada yada yada):
trtrwtf:
C-Octothorpe:
Steve The Cynic:

Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
Indeed, I think the answer is pretty obvious - use the baseball bat, just don't simply swing it at him.


Congratulations. You have parsed an innuendo. Go, you.

(Could someone please post a less boring WTF? I'm dying here)

Re: Representative Property: MaxRetry

2011-07-27 12:30 • by hoodaticus
355064 in reply to 355062
C-Octothorpe:
hoodaticus:
C-Octothorpe:
hoodaticus:
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...
He was trying to correct someone else who thought that
 {return maxRetry = 5}
returns a bool.
The only part of that that I agree with is that assignment returns.

Void.
In this case
{return maxRetry = 5}
it returns a 5 and in this case
{return maxRetry == 5}
it returns a bool. Sorry, I'm not sure if I'm following (got 2 hour of sleep last night, again).
Well I'll be damned. I learn something new here every year. Apparently assignment returns the thing being assigned. Which I would know if M$ would let me overload the sucker.

Re: Representative Property: MaxRetry

2011-07-27 12:31 • by someguy (unregistered)
In order to prempt any more unnecessary arguing about what this code does:

namespace PropertyTest2{

class Program{
private int maxRetry = 1;
public int MaxRetry{
get { return maxRetry = 5; }
set { maxRetry = value; }
}
public int GetMaxRetry(){return maxRetry;}
static void Main(string[] args){
Program p = new Program();
Console.WriteLine(p.GetMaxRetry());
Console.WriteLine(p.MaxRetry);
Console.WriteLine(p.GetMaxRetry());
p.MaxRetry = 2;
Console.WriteLine(p.GetMaxRetry());
Console.WriteLine(p.MaxRetry);
Console.WriteLine(p.GetMaxRetry());
Console.ReadKey();
}
}
}


Output:

1
5
5
2
5
5

Yes, it builds. No, the get of the property does not return true. No, it does not return the previous value.

Re: Representative Property: MaxRetry

2011-07-27 12:33 • by zunesis (the one, the only, the well-hung, yada yada yada) (unregistered)
355066 in reply to 355056
trtrwtf:
zunesis (the one, the only, the well-hung, yada yada yada):
trtrwtf:
C-Octothorpe:
Steve The Cynic:
The amusing thing here is that when I read the article, there were already 5 comments...

For the previous posters who clearly didn't get it... The single = operator is assignment, not equality, so every time you *read* the property, the assigned value is replaced by 5 (and then you see the 5 come out of the property).
Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
What does it mean that my most irritating and despicable sockpuppet is also the most beloved around here?

In my case, it means I'm doing my best to defuse the shock value and take some of the fun out of it. Seems to be working.

Well, if by "fun" you mean my dick and by "it" you mean your lovely pale ass, which is how I usually refer to things, then no, it's not happening.

Re: Representative Property: MaxRetry

2011-07-27 12:34 • by c# guy (unregistered)
355067 in reply to 355052
hoodaticus:
Robajob:
= != ==. Also,
 {return maxRetry == 5}
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.
I didn't think assignment returned a boolean in C#...


well it can do,

e.g.

bool b;

return b = true;

Re: Representative Property: MaxRetry

2011-07-27 12:38 • by Your Name (unregistered)
355068 in reply to 355032
Anonymous Cow-Herd:
XIU:
Mister Cheese:
Some damn Yank:
The Enterpriser:
This is actually very useful for when you want to make use of the set value from within the method whilst limiting out of scope use to '5'.

I have seen very effective use of this pattern in the security industry. The strength of this lies in the way that the get is also secretly a setter too.
So, let me get this straight. maxRetry is 1 internally, and someone outside can set it to whatever they want, but if they ask they're always told it's 5? What's the point of that? I guess what I'm missing here is what really happens (sorry, I'm a tester not a coder). Is maxRetry always 1, or do you really let it be set to something else? And if so, why do you lie and say it's 5?


Is it more like maxRetry is set to 1 initially, you can set it to a new value, and when you read it once, it returns the value it's set to and then sets itself to 5?

The health+safety executive advises people in ivory towers not to ride high horses.


The code will set the field to 5 AND return 5


Surely it sets the field to 5 and returns true?


No, it returns FILE_NOT_FOUND.

Re: Representative Property: MaxRetry

2011-07-27 12:45 • by zunesis (the one, the only, the well-hung, yada yada yada) (unregistered)
355069 in reply to 355063
trtrwtf:
zunesis (the one, the only, the well-hung, yada yada yada):
trtrwtf:
C-Octothorpe:
Steve The Cynic:

Sick. Whoever did this should be punished. Severely. With a baseball bat. By zunesis.
FTFY

Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
Indeed, I think the answer is pretty obvious - use the baseball bat, just don't simply swing it at him...

Congratulations. You got the jo...

...you abduct him and his family and restrain them. Make him choose whose ass gets the bat (he is not allowed to choose himself), tell him if he refuses, you'll do it to all of them.

Who would he choose? His wife? His daughter? His son? An interesting scenario to consider, especially for those of us who do have kids.

Make him choose one at a time, so you end up doing it to all of them anyway.

(P.S. I'm sorry when I sometimes take the easy way out. Thank you for encouraging me to go the extra mile and think up something more refreshing. I couldn't do it without your support and constructive criticism, trtrwtf. Love, Zunesis(not that way, queer))
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment