- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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=
Admin
Frist {Failed} Error: Max attempts reached! Skipping
Admin
This is a common thing to do on an embedded machine with no filesystem.
Admin
I like the fact that the "Representative Line" page linked to doesn't include this article.
Admin
Admin
CAPTCHA: sino. Yah, sino, it should be obvious if you read the title.
Admin
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.
Admin
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.
Admin
I also love how 2+2 always equals 4 but sometimes equals 5...
Admin
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.
Admin
Clearly this is C#, which you would be hard pressed to find on that class of device.
Admin
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
Admin
Admin
I program my toaster in visual basic.
Admin
Admin
The code will set the field to 5 AND return 5
Admin
Admin
You haven't heard of the Netduino (http://netduino.com/) ?
Admin
Surely it sets the field to 5 and returns true?
Admin
You're right, and don't call me Shirley.
Admin
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?
Admin
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.
Admin
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
Admin
Surely there's room for compromise here? I don't think our sick little friend will object. And zunesis won't mind, either.
Admin
Admin
True, but maybe they wanted it to be serializable :)
Admin
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."
Admin
Admin
Admin
Admin
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?
Admin
Admin
= != ==. Also,
wouldn't compile because the MaxRetry property is an int and it would be trying to return a boolean.Admin
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.
Admin
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.
Admin
Admin
It returns '5'.
Also, 'true' is not an int.
Admin
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.
Admin
Admin
Admin
Or you can just mark the setter as private and avoid this nonsense.
Admin
Void.
Admin
Admin
Congratulations. You have parsed an innuendo. Go, you.
(Could someone please post a less boring WTF? I'm dying here)
Admin
Admin
In order to prempt any more unnecessary arguing about what this code does:
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.
Admin
Admin
well it can do,
e.g.
bool b;
return b = true;
Admin
No, it returns FILE_NOT_FOUND.
Admin
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))