• matt (unregistered)

    I do this all the time. Is this... bad then?

  • Cyrus (unregistered) in reply to matt
    matt:
    I do this all the time. Is this... bad then?

    Please enlighten me as to its purpose.

  • Mike (unregistered)

    I don't know what's worse, the fact that you're wasting precious time doing a calculation on a value that (ultimately) equals itself, or the fact that on the next line you're doing a calculation that (ultimately) equals..itself.

  • (cs)

    At first I was thinking it was some kind of elaborate multiple check, but then I remembered that in VB (int)/(int) returns a double, so the result, barring floating-point error, is always going to be the value of iStart. I'm scared of how this code snippet makes sense to someone...

  • Bob (unregistered)

    Its obviously a check to see if IOffset is zero....

  • Look at me! I'm on the internets! (unregistered) in reply to Welbog
    Welbog:
    ...but then I remembered that in VB (int)/(int) returns a double, ...

    Well, there's the biggest WTF yet!

    How do you do integer division?

  • Mike (unregistered)

    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    of course, if VB treats int/int as a double, as pointed out above, then all bets are off...

  • (cs) in reply to Bob
    Bob:
    Its obviously a check to see if IOffset is zero....

    Or, with higher optimization levels, it is a check as to whether iStart is 0, assuming that is really an assignment instead of an equality check.

  • Mike (unregistered)

    For those not aware, in a language like C, that'd be perfectly logical. Assuming that everything is an int, then the line

    i=j*(i/j)

    can be used to set i to the greatest multiple of j that is less than or equal to i.

    of course, if VB treats int/int as a double, as pointed out above, then all bets are off...

    Captcha: kungfu (and not code fu...)

  • Mike (unregistered)

    Aww, crap. Double post.

    I'm an idiot.

  • (cs) in reply to sibtrag
    sibtrag:
    Bob:
    Its obviously a check to see if IOffset is zero....

    Or, with higher optimization levels, it is a check as to whether iStart is 0, assuming that is really an assignment instead of an equality check.

    Single equals sign IS the equality check in VB. Party on!

  • (cs) in reply to zip
    zip:
    Single equals sign IS the equality check in VB. Party on!

    And you've just hit upon one of the many reasons why I hate VB.

  • (cs) in reply to Volmarias
    Volmarias:
    zip:
    Single equals sign IS the equality check in VB. Party on!
    And you've just hit upon one of the many reasons why I hate VB.
    Don't worry, you're not alone.
  • (cs) in reply to Volmarias
    Volmarias:
    zip:
    Single equals sign IS the equality check in VB. Party on!

    And you've just hit upon one of the many reasons why I hate VB.

    You mean "a=b=c" being confusing as to whether it's the same as "a=c:b=c" or "a=(b=c)"?

  • Random832 (unregistered)
    if iStart = iOffset*(iStart/iOffset) then value = aResults(2, iOffset*(iStart/iOffset)) summary = summary & ". " & value end if

    While Hannes wasn't able to provide any insight into the purpose of that IF statement, he did notice out that iStart is always twenty and iOffset is always a multiple of twenty. But it wasn't until his coworker replied "oooh, well that makes sense, then" that he realized how much he had truly lucked out.

    That code was clearly not originally in VB, because that code would not do what the story claims it does in VB - the operator required for that would be , not /.

  • My Name (unregistered)

    To do integer division in VB you use the backslash ''. Don't know why.

  • (cs) in reply to Random832
    Random832:
    if iStart = iOffset*(iStart/iOffset) then value = aResults(2, iOffset*(iStart/iOffset)) summary = summary & ". " & value end if

    While Hannes wasn't able to provide any insight into the purpose of that IF statement, he did notice out that iStart is always twenty and iOffset is always a multiple of twenty. But it wasn't until his coworker replied "oooh, well that makes sense, then" that he realized how much he had truly lucked out.

    That code was clearly not originally in VB, because that code would not do what the story claims it does in VB - the operator required for that would be , not /.
    Wait, what? The story doesn't claim anything about the code other than "it makes sense"...

  • Aaron (unregistered)

    It just wouldn't be a TDWTF post without pointless complaints about the equality operator in VB (or Delphi, or SQL, or FORTRAN, or any functional language, or...)

  • (cs)

    It isn't clear WHAT the code is doing and the story doesn't make a claim to know either.

    \ is integer division (Divide and the remainder disappears) / is normal division (Divide and the expected result is returned)

    4\2 = 2 4/2 = 2

    5/2 = 2.5 5\2 = 2

    iOffset can be eliminated from the code as long as it is not 0. Same with the if-statement and equality comparison.

  • (cs) in reply to Look at me! I'm on the internets!
    Look at me! I'm on the internets!:
    Welbog:
    ...but then I remembered that in VB (int)/(int) returns a double, ...

    Well, there's the biggest WTF yet!

    How do you do integer division?

    Interger division is with a backslash ().

  • AdT (unregistered)

    In C, such an if would check whether iStart is aligned to iOffset boundaries. This assumes iStart and iOffset are integers. (The Hungarian notation would suggest this, but given the overall quality of the code, I would not be surprised to read something like "Dim iMyInteger As Double".) "if (iStart % iOffset == 0)" would be more legible and possibly more efficient, though. In Visual Basic, as was mentioned, this doesn't work at all because integer/integer returns a double. This check would return true or false in an unpredictable way depending on floating-point rounding. This is a Real WTF(tm).

    And if it actually worked, then, since we already established that iStart is aligned, the iOffset*(iStart/iOffset) could be replaced with iStart. This is a also Real WTF.

    The name of the function called in this line (aResults) is also a big WTF - no indication of what it does whatsoever. Let alone calling a variable iOffset that obviously doesn't store an offset but an alignment.

    All this taken together makes the code unintelligible and dysfunctional. A worthy submission to Error'd.

  • (cs)

    If these are float variables, then iStart is often not equal to ioffset * ( iStart / ioffset ). It's going to be a few LSB off sometimes.

    Of course,t hat assumes the equality operator does exact comparison, which isn't true in every language.

  • Steve Syfuhs (unregistered)

    What's WTFed is the bad play on words: Hannes...truly lucked out. Hans in Luck...what a bad fairy tale. Fitting though, considering the fairy tale is a WTF in its own. +2 points for creativity :).

  • (cs) in reply to Mike
    Mike:
    I'm an idiot.

    We knew that the moment you posted your captcha.

  • Scott Duensing (unregistered) in reply to Ancient_Hacker

    Float? In old ASP code? Surely you jest! Everything in "classic" ASP is a "variant". We'll have none of those confusing "type thingies" here!

    Scott

  • Stormy (unregistered)
    Of course, that doesn't mean he's free from it, as several hours each day, he hears the unmistakable signs of his officemate working on the project: "oh you've got to be kidding me," "why would they do that," "what the --?!"

    Shouldn't that be..

    "oh you've got be kidding me," "why whould they do that," "worse than failure --?!"

    /Still don't like the name change.

  • Evo (unregistered) in reply to akatherder
    akatherder:
    \ is integer division (Divide and the remainder disappears) / is normal division (Divide and the expected result is returned)

    PLEASE tell me you're kidding me...... Damn I hate VB :-|

  • Sgt. Preston (unregistered)

    This discussion of equality and assignment operators has me wondering. What is the value of an assignment in Visual Basic?

    For example, in this snippet...

    x = (y = 3)

    ...what is the value of the expression "(y = 3)"? Is the equal sign in this context treated as an assignment or as an evaluation? It's not a normal way to write a statement in VB, but what if one did?

    I suspect that one of these cases would apply:

    1. x gets the value True if the value of y is 3. Otherwise x gets the value False.

    2. y gets the value 3, which is then assigned to x.

    3. Every assignment yields the same value -- perhaps True. So y gets the value 3 and x gets the value True.

    4. The compiler would kak. You're just not allowed to do this.

    Anyone know for sure?

  • Juan O. (unregistered)

    It's original purpose IMHO was to check if iOffset was any multiple of iStart...

    In C, of course XD

  • Jeff (unregistered) in reply to Sgt. Preston

    x = y = 3 is equivalent to saying:

    Compare y to 3, and take the boolean result of that comparison and assign it to x.

    Program in VB for any length of time and you don't even have to think about it. It's perfectly regular.

    I still have to think about if I'm doing integer or floating division, though. I can never remember which "/" or "" is which.

    AdT: you mention the function "aResults". I'm sure that's not a poorly-named function, it's an equally poorly named array.

  • (cs) in reply to Sgt. Preston
    Sgt. Preston:
    For example, in this snippet... x = (y = 3) [...snip...] I suspect that one of these cases would apply:
    1. x gets the value True if the value of y is 3. Otherwise x gets the value False.
    This is what happens in VB. (The same applies in most BASIC variants, from memory...)

    The leftmost equals sign in statement context is an assignment operator, and sets up an expression context on its righthand side. In an expression context, equals signs are comparison/equality operators.

    Sgt. Preston:
    2. y gets the value 3, which is then assigned to x.
    This is what happens in C-like languages, and so is probably what most people on here expect...
  • (cs)

    Just to clarify some of the VB6.0 questions:

    Dim x As Integer Dim y As Integer

    Private Sub Form_Load() x = (y = 3) MsgBox x 'This displays 0 y = 3 x = (y = 3) MsgBox x 'This displays -1 MsgBox (y = 3) 'This displays True End Sub

  • (cs) in reply to Juan O.
    Juan O.:
    It's original purpose IMHO was to check if iOffset was any multiple of iStart...

    In C, of course XD

    And in reverse, no less - in C the code as presented would be checking whether iStart was a multiple of iOffset!

    (Which kind of makes me wonder if the values in the article got switched during anonymisation...)

  • Sgt. Preston (unregistered) in reply to random_garbage

    Good answers, folks. Thanks. So, to sum up:

    This Visual Basic statement: x = y = 3

    ...is equivalent to this Java statement: x = y == 3;

  • Timothy Baldridge (unregistered)

    "\ is integer division (Divide and the remainder disappears) / is normal division (Divide and the expected result is returned) "

    This is a carry-over from the old days (QBasic, GWBasic, etc.) when doing a floating point divide was more expensive than a integer one (actually it it still is, but it's all so fast, it doesn't matter anyway). There are some times (can't think of them now), when I wanted these features in C, normally there is a better way around the problem.

  • Look at me! I'm on the internets! (unregistered) in reply to Juan O.
    Juan O.:
    It's original purpose IMHO was to check if iOffset was any multiple of iStart...

    In C, of course XD

    Still won't work.
    iStart = 20 iOffset = k*20 (assume k>1) iStart/iOffset = 1/k which is zero in integer division.

    So, depending on how integer division is handled, there are two possible answers to iOffset*(iStart/iOffset) 0, or iStart.

    Neither of which appears to be a very useful result.

    Now, if the parentheses were removed, it would be a different story.

    So what the original coder was doing is some very subtle code that tests whether or not the system performs integer division or not. This makes the code completely cross platform, and can be easily ported to any one of the multiple implementations of VB used in production.

  • Steve (unregistered) in reply to Mike

    Aww, crap. Double post.

    I'm an idiot.

    Here's your sign.

  • (cs) in reply to Sgt. Preston

    In VB the rules are simple:

    1. '=' is both the equality and assignation operator, depending on context.

    ---> 2) If this is an expression, then it is equality ---> 3) If this is a statement, then it is assignation

    1. There is NO multiple assignation in VB (because of rule number 1, or the grammar would be unparsable I guess). Assignation are not L-Values.

    So to answer your question: x = y = 3

    In that case, the first = is clearly a statement and thus an assignation. The second = is an expression and thus a comparison.

    This means that

    1. if y equals 3, x will be set to TRUE
    2. if y does not equal 3, x will be set to FALSE

    Using parentheses in that instance does not change anything else than readability (I sometimes use that kind of constructs, and in that case I use parentheses).

    Addendum (2007-06-25 13:41): As someone was kind enough to point out my error, I guess I should correct myself on the assignation word. You would have to read assignment, obviously.

    Please excuse the errors of a non-native English speaker/writer. And if you don't, well too bad.

  • (cs)

    I guess WTF would not be the same if people were to stop arguing about VB's syntax.

    Now if those same people could spare one hundredth of the energy they use for complaining, and use it to actually try to understand how VB operators work, that would be a nice change. Obviously this is not going to happen since people have been trying to explain that for as long as I can remember on this site.

    You don't like using the same operator for equality and assignation? Fine, I don't like having the opportunity to shoot myself in the foot every time I write a condition by forgetting an equal sign. But you don't see people like me complaining about it every third post. VB syntax on this makes perfect sense, as far as VB programmers are concerned (and please, VB programmers actually DO now other languages).

    It seems to me that the more we see VB stuff, the quicker the focus changes from the code to the fact that people don't even try to understand VB's syntax and forget about what the article is about.

    In any case, as the saying goes: a good programmer will be good whatever the language. A bad one will be bad whatever the language. You can write WTFs (original meaning) in whatever language you choose, they all offer plenty of ways to shoot yourself in the foot. Just because you can't be bothered trying to undertand the syntax (which would require about 1 minute of half concentration) does not mean the language is the WTF.

    If you want to discuss the pros and cons of VB (and then please state the version because VB 6 and .NET are almost as different as C and C++) then fine, be my guest, I'll entertain you. But try to get your facts straight and don't argue on stupid syntax differences that don't matter.

    This is why I prefer architectural WTFs. They are usually a much better insight into humanity's insanity.

    Sorry, needed to vent this time.

  • (cs) in reply to Evo
    Evo:
    akatherder:
    \ is integer division (Divide and the remainder disappears) / is normal division (Divide and the expected result is returned)

    PLEASE tell me you're kidding me...... Damn I hate VB :-|

    Sad but true. I'm maintaining a couple old ASP websites right now and I've worked with ASP in the past. As far as practical use, I've never actually seen '' used (on purpose).

  • (cs) in reply to akatherder
    Sad but true. I'm maintaining a couple old ASP websites right now and I've worked with ASP in the past. As far as practical use, I've never actually seen '\' used (on purpose).

    I use it regularly for the kind of project I do, which are not web based (control systems for test stands). You could perfectly argue that this actually make sense since in that case you don't rely on the type of the operands (which might be defined completely somewhere else) to know what kind of operation you are actually performing. All the context you need is right here. Again, a matter of taste and habits.

    The fact that VB.net uses accounting rules for rounding floats into integers (alternating rounding to lower / rounding to upper based on the evenness of the operand), now THAT is painful in my line of work :)

  • (cs) in reply to Denis Troller
    Denis Troller:
    In VB the rules are simple:
    1. '=' is both the equality and assignation operator, depending on context. ... ---> 3) If this is a statement, then it is assignation

    2. There is NO multiple assignation in VB...Assignation are not L-Values.

    ...

    In that case, the first = is clearly a statement and thus an assignation.

    You keep using that word. I do not think it means what you think it means.

  • (cs) in reply to Someone You Know
    You keep using that word. I do not think it means what you think it means.

    Yeah, sorry, french word creeping up :( I realized that after the fact and was too lazy to edit my post :p

    Addendum (2007-06-25 13:37): posted by "someone I know" ? Wonder who that could be... Care to give some clues ? (geographic location is not accepted as it would not narrow the field of possibilities at all).

  • Shinobu (unregistered) in reply to Timothy Baldridge

    In C you would have to use casts, I think.

  • (cs) in reply to Denis Troller
    Denis Troller:
    I guess WTF would not be the same if people were to stop arguing about VB's syntax.

    Now if those same people could spare one hundredth of the energy they use for complaining, and use it to actually try to understand how VB operators work, that would be a nice change. Obviously this is not going to happen since people have been trying to explain that for as long as I can remember on this site.

    <lots of words...>

    Oh, finally a sane post. Glad to see I'm not alone.

  • number6 (unregistered) in reply to AdT
    AdT:
    (The Hungarian notation would suggest this, but given the overall quality of the code, I would not be surprised to read something like "Dim iMyInteger As Double".)

    That is precisely why Hungarian notation is a bad idea.

  • (cs) in reply to Denis Troller
    Denis Troller:
    posted by "someone I know" ? Care to give some clues ? (geographic location is not accepted as it would not narrow the field of possibilities at all).

    Clue #1: I'm a registered user. Clue #2: You're not the only person who's read my posts.

  • (cs) in reply to Someone You Know

    Woops, did not see you were registered.

    I guess that might make me a bit self-centered then...

  • Thuenor (unregistered) in reply to Lazy-lump
    Lazy-lump:
    Just to clarify some of the VB6.0 questions:

    Dim x As Integer Dim y As Integer

    Private Sub Form_Load() x = (y = 3) MsgBox x 'This displays 0 y = 3 x = (y = 3) MsgBox x 'This displays -1 MsgBox (y = 3) 'This displays True End Sub

    If you change type x to Variant it returns True as well... True equals -1 (at least in VB it does).

  • sol (unregistered)

    I do something like this to find out what part of the map the mouse is over...

    I have an array of stuff that I need to access when the user clicks some where. The map is a grid of 16x16 squares(tiles)...

    int id_x = Convet.ToInt32(Math.Floor(Mouse.X/16) * 16); int id_y = Convet.ToInt32(Math.Floor(Mouse.Y/16) * 16); Bitmap tile = (Bitmap)tiles[id_x][id_y]; //I'm not sure that is how I have the array hashed...

    That isn't exact code... but that is the general idea... I think I pulled out most of my hair before I said you idiot Floor the value....

    captcha: smile.. I'll try but it makes my face hurt

Leave a comment on “Multiplied Denomination”

Log In or post as a guest

Replying to comment #:

« Return to Article