Comment On Multiplied Denomination

Hannes lucked out: he wasn't assigned to the .NET Migration Project. 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 --?!" [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Multiplied Denomination

2007-06-25 09:06 • by matt (unregistered)
I do this all the time. Is this... bad then?

Re: Multiplied Denomination

2007-06-25 09:11 • by Cyrus (unregistered)
142416 in reply to 142414
matt:
I do this all the time. Is this... bad then?


Please enlighten me as to its purpose.

Re: Multiplied Denomination

2007-06-25 09:15 • by 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.

Re: Multiplied Denomination

2007-06-25 09:15 • by Welbog
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...

Re: Multiplied Denomination

2007-06-25 09:15 • by Bob (unregistered)
Its obviously a check to see if IOffset is zero....

Re: Multiplied Denomination

2007-06-25 09:23 • by Look at me! I'm on the internets! (unregistered)
142420 in reply to 142418
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?

Re: Multiplied Denomination

2007-06-25 09:24 • by 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...

Re: Multiplied Denomination

2007-06-25 09:24 • by sibtrag
142422 in reply to 142419
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.

Re: Multiplied Denomination

2007-06-25 09:25 • by 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...)

Re: Multiplied Denomination

2007-06-25 09:25 • by Mike (unregistered)
Aww, crap. Double post.

I'm an idiot.

Re: Multiplied Denomination

2007-06-25 09:31 • by zip
142425 in reply to 142422
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!

Re: Multiplied Denomination

2007-06-25 09:37 • by Volmarias
142426 in reply to 142425
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.

Re: Multiplied Denomination

2007-06-25 09:41 • by Welbog
142427 in reply to 142426
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.

Re: Multiplied Denomination

2007-06-25 09:43 • by Thief^
142428 in reply to 142426
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)"?

Divided Anonymization

2007-06-25 09:43 • by 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 /.

Re: Multiplied Denomination

2007-06-25 09:46 • by My Name (unregistered)
To do integer division in VB you use the backslash '\'. Don't know why.

Re: Multiplied Denomination

2007-06-25 09:47 • by Welbog
142431 in reply to 142429
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"...

Re: Multiplied Denomination

2007-06-25 09:48 • by 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...)

Re: Multiplied Denomination

2007-06-25 09:53 • by akatherder
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.

Re: Multiplied Denomination

2007-06-25 10:10 • by Grauenwolf
142435 in reply to 142420
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 (\).

Re: Multiplied Denomination

2007-06-25 10:16 • by 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.

Re: Multiplied Denomination

2007-06-25 10:20 • by Ancient_Hacker
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.

Re: Multiplied Denomination

2007-06-25 10:41 • by 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 :).

Re: Multiplied Denomination

2007-06-25 10:42 • by Zylon
142439 in reply to 142424
Mike:
I'm an idiot.


We knew that the moment you posted your captcha.

Re: Multiplied Denomination

2007-06-25 10:46 • by Scott Duensing (unregistered)
142440 in reply to 142437
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

Re: Multiplied Denomination

2007-06-25 10:51 • by 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.

Re: Multiplied Denomination

2007-06-25 10:53 • by Evo (unregistered)
142442 in reply to 142433
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 :-|

Re: Multiplied Denomination

2007-06-25 10:58 • by 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?

Re: Multiplied Denomination

2007-06-25 11:05 • by Juan O. (unregistered)
It's original purpose IMHO was to check if iOffset was any multiple of iStart...

In C, of course XD

Re: Multiplied Denomination

2007-06-25 11:08 • by Jeff (unregistered)
142449 in reply to 142443
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.

Re: Multiplied Denomination

2007-06-25 11:11 • by random_garbage
142451 in reply to 142443
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...

Re: Multiplied Denomination

2007-06-25 11:13 • by 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

Re: Multiplied Denomination

2007-06-25 11:16 • by random_garbage
142456 in reply to 142447
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...)

Re: Multiplied Denomination

2007-06-25 11:17 • by Sgt. Preston (unregistered)
142457 in reply to 142451
Good answers, folks. Thanks. So, to sum up:

This Visual Basic statement:
x = y = 3

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

Re: Multiplied Denomination

2007-06-25 11:18 • by 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.

Re: Multiplied Denomination

2007-06-25 11:19 • by Look at me! I'm on the internets! (unregistered)
142459 in reply to 142447
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.

Re: Multiplied Denomination

2007-06-25 11:58 • by Steve (unregistered)
142471 in reply to 142424
> Aww, crap. Double post.

> I'm an idiot.

Here's your sign.

Re: Multiplied Denomination

2007-06-25 12:40 • by Denis Troller
142480 in reply to 142443
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

2) 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.

Re: Multiplied Denomination

2007-06-25 12:54 • by 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.

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.

Re: Multiplied Denomination

2007-06-25 12:55 • by akatherder
142488 in reply to 142442
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).

Re: Multiplied Denomination

2007-06-25 13:04 • by Denis Troller
142491 in reply to 142488

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 :)

Re: Multiplied Denomination

2007-06-25 13:13 • by Someone You Know
142494 in reply to 142480
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.

Re: Multiplied Denomination

2007-06-25 13:25 • by Denis Troller
142496 in reply to 142494
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).

Re: Multiplied Denomination

2007-06-25 13:27 • by Shinobu (unregistered)
142497 in reply to 142458
In C you would have to use casts, I think.

Re: Multiplied Denomination

2007-06-25 13:54 • by Spectre
142502 in reply to 142487
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.

Re: Multiplied Denomination

2007-06-25 13:55 • by number6 (unregistered)
142503 in reply to 142436
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.

Re: Multiplied Denomination

2007-06-25 14:00 • by Someone You Know
142504 in reply to 142496
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.

Re: Multiplied Denomination

2007-06-25 14:03 • by Denis Troller
142506 in reply to 142504
Woops, did not see you were registered.

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

Re: Multiplied Denomination

2007-06-25 14:18 • by Thuenor (unregistered)
142507 in reply to 142453
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).

Re: Multiplied Denomination

2007-06-25 14:29 • by 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
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment