| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |
|
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 |
|
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)
|
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)
|
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. |
|
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.
|
|
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)
|
|
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)
|
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
|
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
|
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:
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
|
FTFY |
Re: Representative Property: MaxRetry
2011-07-27 11:41
•
by
VeryBestDeveloperNumber1
(unregistered)
|
I program my toaster in visual basic. |
Re: Representative Property: MaxRetry
2011-07-27 11:41
•
by
C-Octothorpe
|
You almost got me... |
Re: Representative Property: MaxRetry
2011-07-27 11:41
•
by
XIU
|
The code will set the field to 5 AND return 5 |
Re: Representative Property: MaxRetry
2011-07-27 11:43
•
by
Zylon
|
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)
|
You haven't heard of the Netduino (http://netduino.com/) ? |
Re: Representative Property: MaxRetry
2011-07-27 11:46
•
by
Anonymous Cow-Herd
(unregistered)
|
Surely it sets the field to 5 and returns true? |
Re: Representative Property: MaxRetry
2011-07-27 11:50
•
by
Lowmack
(unregistered)
|
You're right, and don't call me Shirley. |
Re: Representative Property: MaxRetry
2011-07-27 11:53
•
by
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?
|
Re: Representative Property: MaxRetry
2011-07-27 11:54
•
by
ted
(unregistered)
|
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)
|
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)
|
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
|
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)
|
True, but maybe they wanted it to be serializable :) |
Re: Representative Property: MaxRetry
2011-07-27 12:06
•
by
Some damn Yank
(unregistered)
|
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)
|
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
|
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
|
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)
|
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
|
|
= != ==. 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
|
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
|
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
|
I didn't think assignment returned a boolean in C#... |
Re: Representative Property: MaxRetry
2011-07-27 12:15
•
by
The Enterpriser
|
It returns '5'. Also, 'true' is not an int. |
Re: Representative Property: MaxRetry
2011-07-27 12:17
•
by
trtrwtf
(unregistered)
|
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)
|
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
|
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)
|
Or you can just mark the setter as private and avoid this nonsense. |
Re: Representative Property: MaxRetry
2011-07-27 12:24
•
by
hoodaticus
|
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
|
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)
|
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
|
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{
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)
|
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)
|
well it can do, e.g. bool b; return b = true; |
Re: Representative Property: MaxRetry
2011-07-27 12:38
•
by
Your Name
(unregistered)
|
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)
|
...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)) |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |