• (cs) in reply to C-Octothorpe
    C-Octothorpe:
    Matt Westwood:
    That's not the point. C++ has two addition characters in its name, and C# has a character that is often confused with the sharp sign in conventional musical notation. This is important. Wars have been fought over less.
    Good point.
    Bad point. C#, the INTENDED character, IS the same sharp sign in conventional musical notation. The only reason it is displayed as a number sign in most places is because it's not on the keyboard.s

    http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name

  • (cs) in reply to Sutherlands
    Sutherlands:
    C-Octothorpe:
    Matt Westwood:
    That's not the point. C++ has two addition characters in its name, and C# has a character that is often confused with the sharp sign in conventional musical notation. This is important. Wars have been fought over less.
    Good point.
    Bad point. C#, the INTENDED character, IS the same sharp sign in conventional musical notation. The only reason it is displayed as a number sign in most places is because it's not on the keyboard.s

    http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name

    That's even worse then. Giving a language a name that can't even be rendered on a standard keyboard has to be a pretty tasty little WTF all of its own.

  • (cs) in reply to Jaime
    Jaime:
    The Enterpriser:
    Some damn Yank:
    method1:
    Some damn Yank:
    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."

    Why would it return "true"? I think it will return the value of maxRetry, which has been assigned to 5. Its an int property not a bool anyway. Or are you just trolling/bullshitting/joking etc.?
    I said it returns "True" because Anonymous Cow-Herd said it does. Then I ran with that. It doesn't return "5" because you think it does, it returns whatever its value is and then it gets set to 5, as several others have pointed out. Oh, if only the code did what we think it does - then all we'd need do is think what we want it to do and it would do it on its own! Here's another clue for you all: I don't troll, I sometimes bullshit, and I often joke. I rarely etc.

    I suggest you read up on order of precedence

    the '+' and '=' operators are evaluated right to left.

    Hence:

    return maxRetry = 5;

    is evaluated like so..

    1. maxRetry = 5
    2. return maxRetry (which is now 5)
    This is easy to prove false.
    Code mixing up what properties and fields are
    

    If you were right, it would display "4", because p1 can never have any value other than 4. However, it displays "7".

    The fact that the property setter has the same syntax before MSIL interpretation than the assignment operator and that most property setters do assign a value to a field can be confusing, but The Entepriser's point is valid as long as you don't mix up different things just because they look the same. A setter is just C# eye candy for a method:

    int set_p1(int value)

    A method being something different than an operator:

    • the order of precedence is not the same
    • what Microsoft guys decided it would return does not a priori has anything to do with what the assignment statement yields.
  • (cs) in reply to boog
    boog:
    Matt Westwood:
    boog:
    Anonymous Cow-Herd:
    I thought assignment returned true unless the assignment failed - hence the problems with errors like if (x=5). I guess I was wrong, at least for C#.
    Uh, no, it's been a little while since I've used C++, much less the below construct, but I'm fairly certain that assignment returns the value to which the left side was set. That's why you can do crazy shit like this:
    x = y = 42;
    which will set both x and y to 42.

    if(x=5) passes because C++ treats 5 as true. Try if(x=0) and see what you get.

    Addendum (2011-07-28 12:50): Not just C++, this applies to C as well. Java too. It seems to be pretty common.

    In fact, I'm not sure of any languages that return on assignments in the way you described. There may be some, but I can't recall any at this time.

    It's not C++ you stupid cunty little retard, it's C#. Now FOCUS.

    A number of posts from this guy and others explicitly refer to C++ behaving the same misunderstood way. Furthermore, he admitted he was wrong at least for C#. Actually, he's wrong about C++ as well, and that's what my comment was directed at; maybe I should have made that more clear.

    Still, why the disrespect, my douchey little dipshit?

    Mistook you for someone else. Soz.

  • Adrian Veidt (unregistered) in reply to Sutherlands
    Sutherlands:
    Bad point. C#, the INTENDED character, IS the same sharp sign in conventional musical notation. The only reason it is displayed as a number sign in most places is because it's not on the keyboard.s

    http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name

    So you want us to blindly believe what's written on a wikipedia page?

    The only "reference" that wikipedia gives us for that myth is the blog of a criminal vigilante!

  • Jaime (unregistered) in reply to GFK
    GFK:
    Jaime:
    The Enterpriser:
    Some damn Yank:
    method1:
    Some damn Yank:
    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."

    Why would it return "true"? I think it will return the value of maxRetry, which has been assigned to 5. Its an int property not a bool anyway. Or are you just trolling/bullshitting/joking etc.?
    I said it returns "True" because Anonymous Cow-Herd said it does. Then I ran with that. It doesn't return "5" because you think it does, it returns whatever its value is and then it gets set to 5, as several others have pointed out. Oh, if only the code did what we think it does - then all we'd need do is think what we want it to do and it would do it on its own! Here's another clue for you all: I don't troll, I sometimes bullshit, and I often joke. I rarely etc.

    I suggest you read up on order of precedence

    the '+' and '=' operators are evaluated right to left.

    Hence:

    return maxRetry = 5;

    is evaluated like so..

    1. maxRetry = 5
    2. return maxRetry (which is now 5)
    This is easy to prove false.
    Code mixing up what properties and fields are
    

    If you were right, it would display "4", because p1 can never have any value other than 4. However, it displays "7".

    The fact that the property setter has the same syntax before MSIL interpretation than the assignment operator and that most property setters do assign a value to a field can be confusing, but The Entepriser's point is valid as long as you don't mix up different things just because they look the same. A setter is just C# eye candy for a method:

    int set_p1(int value)

    A method being something different than an operator:

    • the order of precedence is not the same
    • what Microsoft guys decided it would return does not a priori has anything to do with what the assignment statement yields.
    The order of operations does not depend on what is being ordered.

    x = 1 * 2 + 3 x = 1 * c1.randomfield + 3 x = 1 * c1.randomproperty + 3

    These all evaluate in the same order. I substituted a property for a field because you cannot get a differentiating behavior from a field. It does not invalidate the results.

  • (cs) in reply to GFK
    GFK:
    The fact that the property setter has the same syntax before MSIL interpretation than the assignment operator and that most property setters do assign a value to a field can be confusing, but The Entepriser's point is valid as long as you don't mix up different things just because they look the same. A setter is just C# eye candy for a method:
    int set_p1(int value)
    A method being something different than an operator: - the order of precedence is not the same - what Microsoft guys decided it would return does not a priori has anything to do with what the assignment statement yields.
    No, but what C and C++ did before it (and which I already quoted the standard about) has to do with what MS "a priori" decided, and the ECMA spec provides a formal definition of what = evaluates to:

    The result of a simple assignment expression is the value assigned to the left operand. The result has the same type as the left operand, and is always classified as a value. (ECMA 334, June '06 version, section 14.14.1 para 2.)

    You can also demonstrate to yourself that it is not allowed to reread the value from the left operand through my example with a volatile field.

  • ahoka (unregistered) in reply to @Deprecated

    wasnt so hard: http://www.microsoft.com/en-us/netmf/default.aspx

  • (cs) in reply to Adrian Veidt
    Adrian Veidt:
    Sutherlands:
    Bad point. C#, the INTENDED character, IS the same sharp sign in conventional musical notation. The only reason it is displayed as a number sign in most places is because it's not on the keyboard.s

    http://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Name

    So you want us to blindly believe what's written on a wikipedia page?

    The only "reference" that wikipedia gives us for that myth is the blog of a criminal vigilante!

    I don't particularly care if you believe it. I think I first learned about it from reading Eric Lippert's blog.

  • Klash (unregistered)

    The real WTF here is they already named this the "bait and switch". What poor client are they abusing?!

    captcha - illum as in shining light on the matter!

  • Zizekbert (unregistered)

    Properly dialectic code!

  • JB (unregistered) in reply to GFK
    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.

    Schrödinger explains it all...

  • Max (unregistered)

    Oh, so that's what Write Only Memory is for.

  • SillyG (unregistered)

    The sad thing is, I've had to deal with this. I recently made a bugfix to a relatively large, poorly maintained codebase by adding one line of code:

    void DoHorriblyLongProcess() { ....snip.... HostName = HostName; ....snip.... }

Leave a comment on “Representative Property: MaxRetry”

Log In or post as a guest

Replying to comment #:

« Return to Article