Go Back  DVD Talk Forum > General Discussions > Tech Talk
Reload this Page >

More Microsoft idiocy (C#)

Tech Talk Discuss PC Hardware, Software, Internet and Other Technology

More Microsoft idiocy (C#)

Old 11-09-04, 11:46 PM
  #1  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
More Microsoft idiocy (C#)

I can't believe this shit.

Microsoft provides a lot of pre-cooked classes in the System hierarchy to eliminate needless coding. Among these is a BitArray class: a lightweight collection of bits (actually boolean values) in case you want to store a bunch of flags, etc.

The collection includes AND.
It includes OR.
It includes NOT.
It includes XOR.
It includes Set(index, value), and SetAll(value) if you want to set the whole array to true or false.

It doesn't seem to include SHIFT or ROLL functions, either (incredibly common for bit manipulation.)

And you know what else it doesn't include? It doesn't include any kind of comparison operators. You can't check if it's zero. If you want the number of TRUE values in the array, you have to iterate across the whole goddamn thing and count 'em yourself.

What the hell? Isn't the whole purpose of a bit array the ability to do a bunch of ops on it, and then check the value of the whole thing? (That's exactly what I want to do: I want to AND together two bit arrays and compare it with zero.)

This is downright idiocy. How could they omit that?

- David Stein
Old 11-12-04, 12:35 AM
  #2  
DVD Talk Legend
 
Join Date: Jun 2000
Location: NYC
Posts: 17,018
Likes: 0
Received 0 Likes on 0 Posts
I don't understand your outrage or whatever. Can't you just extend the class with your own function? Since I don't do C#, I'm assuming you mean comparing the values of the BitArray keys and seeing if they match, well... their function is going to do the same thing as if you wrote it.
Old 11-12-04, 12:01 PM
  #3  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
Of course I could. But one of the much-touted advantages of C# (as well as Java and every other modern language) is a collection of pre-cooked container classes. Want a hashtable? "Hashtable h = new Hashtable();" should do the trick.

So it's frustrating when you start using that class, and then discover that it doesn't support a very basic and common use of that class. It speaks of a ridiculous lack of attention to detail. Having to write a new implementation myself defeats the whole purpose of offering that package.

Imagine if you bought a new car, and when you went to pick it up, you discovered that it didn't come with windshield wipers.

- David Stein
Old 11-12-04, 12:32 PM
  #4  
DVD Talk Legend
 
Mordred's Avatar
 
Join Date: Jan 2000
Location: Austin, TX
Posts: 12,215
Likes: 0
Received 0 Likes on 0 Posts
Not that I use C#, but I can understand your frustration. However, I looked and the class does include an Equals method (Inherited from the Object class). So it seems all you'd need to do is create a zeroed bitArray of the same size and then compare them that way. Kinda lame, but still pretty straightforward I would think.

As for shift and roll those are so straightforward that I would think there's probably a specific reason they weren't included. If you required that I'd just use the old method (that I use on a daily basis) of using a standard integer type. A least then shift, all the bitwise operaters, set all and easy comparisons are built in. I can kinda see how a bitArray class could be useful but personally I'd think it's main benefit is from a readability standpoint, something I'm normally not that worried about.
Old 11-12-04, 04:02 PM
  #5  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
Originally posted by Mordred
I looked and the class does include an Equals method (Inherited from the Object class). So it seems all you'd need to do is create a zeroed bitArray of the same size and then compare them that way. Kinda lame, but still pretty straightforward I would think.
It works correctly, but you lose all of the value inherent in a bit array with true bitwise functions. That is, instead of using a bitwise function (AND, OR, XOR, NOT, etc.) on all of the bits in the array, you have to iterate over every member and do something. So you may as well use a standard Boolean array.
Originally posted by Mordred
As for shift and roll those are so straightforward that I would think there's probably a specific reason they weren't included. If you required that I'd just use the old method (that I use on a daily basis) of using a standard integer type.
Again, you have to iterate over the entire array like:

for (int i = 1; i < array.length + 1; i++) { array[i-1] = array[i]; }

...instead of logically shifting everything left.
Originally posted by Mordred
I can kinda see how a bitArray class could be useful but personally I'd think it's main benefit is from a readability standpoint, something I'm normally not that worried about.
I guess... but that's silly. I mean, if you don't have bitwise operations, why use a specific list of bits instead of a generic list of objects?

- David Stein
Old 11-12-04, 04:42 PM
  #6  
DVD Talk Legend
 
Mordred's Avatar
 
Join Date: Jan 2000
Location: Austin, TX
Posts: 12,215
Likes: 0
Received 0 Likes on 0 Posts
Originally posted by sfsdfd
It works correctly, but you lose all of the value inherent in a bit array with true bitwise functions. That is, instead of using a bitwise function (AND, OR, XOR, NOT, etc.) on all of the bits in the array, you have to iterate over every member and do something. So you may as well use a standard Boolean array.

Again, you have to iterate over the entire array like:
for (int i = 1; i < array.length + 1; i++) { array[i-1] = array[i]; }
...instead of logically shifting everything left.
Which is precisely why I'm saying I wouldn't use bitwise arrays to begin with.

int bitArray;
bitArray = bitArray flags & kBeveled) will do the trick. Use |= for setting, etc. Only thing you'd actually have to write code for is a roll, and that's obviously not that complex.
I guess... but that's silly. I mean, if you don't have bitwise operations, why use a specific list of bits instead of a generic list of objects?
Which is why I understand your frustration... Microsoft sucks
Old 11-12-04, 04:47 PM
  #7  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
[QUOTE]Originally posted by Mordred
[B]Which is precisely why I'm saying I wouldn't use bitwise arrays to begin with.

int bitArray;
bitArray = bitArray
Old 11-12-04, 04:52 PM
  #8  
DVD Talk Legend
 
Mordred's Avatar
 
Join Date: Jan 2000
Location: Austin, TX
Posts: 12,215
Likes: 0
Received 0 Likes on 0 Posts
Originally posted by sfsdfd
...which is exactly my solution (only I have an array of 32-bit uints, since I'm dealing with a variable number of bits.) I always forget which operator does an XOR (it's ^.)
Well if you have a variable number of bits you should use a bitArray class

I suppose I wasn't fully thinking that you might need a lot of bits. Shift's and Rolls in that case are obviously a lot more complex.
Old 11-12-04, 09:45 PM
  #9  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
Originally posted by Mordred
Well if you have a variable number of bits you should use a bitArray class
Gee, thanks.

No, I stuck with a uint array. In truth, I don't need shifting or rolling (just pointed out 'cause, fuck, if you're going to create a BitArray class you need to implement those.) I just needed &, |, and ^. Work fine with uints.

- David Stein
Old 11-13-04, 01:22 AM
  #10  
DVD Talk Platinum Edition
 
Join Date: Oct 1999
Location: South Surrey, BC
Posts: 3,990
Likes: 0
Received 0 Likes on 0 Posts
Isn't the whole purpose of a bit array the ability to do a bunch of ops on it, and then check the value of the whole thing?
Looks to me to be more for manipulating truth tables than serious bit fiddling.

I've noticed myself that various features are missing from the dot-NET FCL. And, something that really irritates me is that the Decimal.Round function uses banker's rounding, rather than the plain rounding of SQL Server. Thus, I can't mix calculations between the two.
Old 11-13-04, 11:09 AM
  #11  
DVD Talk Legend
Thread Starter
 
Join Date: Oct 1999
Location: |-|@><0r [email protected]|)
Posts: 17,214
Likes: 0
Received 0 Likes on 0 Posts
Originally posted by DivxGuy
And, something that really irritates me is that the Decimal.Round function uses banker's rounding, rather than the plain rounding of SQL Server.
Can you explain what you mean by that? Do you just mean >=0.5 gets rounded to 1 while very strange problem. This code:

double x = 0.0;
for (int i = 0; i < 10; i++) x += 0.1;

produces something like the following values for x:
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8000001
0.9000001
1.0

I have no clue why it might be doing this. It's not a big deal for my code, but it's fucking weird.

- David Stein
Old 11-13-04, 11:50 PM
  #12  
DVD Talk Platinum Edition
 
Join Date: Oct 1999
Location: South Surrey, BC
Posts: 3,990
Likes: 0
Received 0 Likes on 0 Posts
Plain rounding adds 5 to the digit to the immediate right of the digit to round up to. Therefore, .445 rounded to 1 decimal place becomes 0.5.

Under banker's rounding (I think that's what it's called), it becomes 0.4.

As for the floating point issue you describe, it occurs because it is not possible to represent some fractional numbers in base 2. That's the raison d'Ítre for fixed-point types such as .NET's Decimal.

When doing financial math, one should use fixed-point types rather than floating-point ones.

Oh, and another gap in dot-NET I've found is that unlike SQL Server's ROUND function, there's no option to truncate rather than round.

RD

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Thread Tools
Search this Thread

Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service - Do Not Sell My Personal Information

Copyright © 2018 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.