-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing #[]
in BitArray
#3968
Comments
They definitely look like bugs :). |
From wikipedia:
That is, the use case of a bit array is to count things, to know if a given object is inside a set. For that, you consider each position in the bit array to be a different object of interest. For example the compiler uses this to determine if all types are covered by method overloads. With this in mind, you normally don't want to get a piece of a bit array. You don't use it like an array. In Java there's no such functionality. Neither in C#. It's not that this was overlooked, it's just that the use case of a BitArray is not that of an Array. That said, we could implement @jzakiya It would be interesting to know what's your use case here and why you need this slicing functionality. |
I also changed the title: there's no bug or inconsistency here, we are just missing an (with what I said above, maybe even |
I think you need to see and appreciate this issue from the perspective of a user. First, you can not restrict the use of any resource that is provided to just what you think it will/should be used for. If you create it people will try to use if for things you might have never considered. A BitArray is presented as an array, which is a collection, which according to it's own documentation inherits a host of methods from other modules, including Enumerables. If so, it should work with them. I do a lot of numerical heavy applications. I use arrays to represents data that is boolean in nature, i.e, 1|0, true|false. I can significantly reduce memory usage by using BitArrays, over arrays of Ints, where I'm more concerned with memory reduction versus speed. From a user's perspective, or at least MY USER PERSPECTIVE, it is a bug, and certainly inconsistent, to not be able to manipulate a BitArray like an Array, especially when the documentation states they inherit methods from the same modules. Either create accurate documentation to explain how the resource actually behaves or make the resource behavior match its documentation. |
That's interesting, maybe we could rename BitArray to Bitmap to avoid these kinds of false expectations. The name could be misleading if the user doesn't know the context discussed here and in https://en.wikipedia.org/wiki/Bit_array. So why don't we just:
|
If we can implement the full array interface, is there any reason why not? |
Bitmap can be confusing too (images). I think I'd choose BitSet instead, and/or document how specific it is (i.e. not to be considered an Array). |
#codetriage At the top of
So this either is a documentation issue, where we change Enumerable to Indexable, or ensure that BitArray should indeed include all Enumerable methods. |
@miketheman |
FWIW I personally think that |
I originally posed this on the crystal google groups forum and it was suggested I raise this as an issue.
https://groups.google.com/forum/#!topic/crystal-lang/Iiqgrgvca8M
In trying to use bit arrays (0.20.5) I've noticed a number of bugs and inconsistencies
in expected behavior compared to regular arrays which use the same methods.
Then there are indexing issues using bit arrays.
According to BitArray API, https://crystal-lang.org/api/0.20.5/BitArray.html
these are inherited from the appropriate modules that work with Arrays.
Are these problems with BitArrays just a consequence of the current age of the language, and planned
to be fixed, or are these the intended different behavior compared to other Arrays?
The text was updated successfully, but these errors were encountered: