3 ms·
I think what GP is trying to say here is that they haven't needed to think about OR-ing in such low-level terms: they could just do it without worrying about th
by thomastjeffery 5y ago
I think what GP is trying to say here is that they haven't needed to think about OR-ing in such low-level terms: they could just do it without worrying about the underlying theory and implementation.
- mewpmewp2 5y agoYeah, and I think I have never actually programmatically used this type of pattern. I have interfaced with things that do use this pattern as mentioned like file access system, which most of the changes I have done manually, understanding how single value represents various states. I'd argue if one were to do it programmatically, in most cases unless you are building the APIs for this yourself, in which case you should acquainted with the domain itself, and would learn about setting a bit during the process, you would use something like "file.setAccessMode("write", true)" etc, not only because it makes it easier to read, but because underlying implementation here shouldn't matter, since using an API like that means that setting this access mode could potentially work with any operation system etc, which might not be using the same representation of numeric value for read, write and execute. In all non low level cases you should be representing enums with strings, not with numbers like 1, 2, 4, 8, because the way I see it, it can only cause scalability, readability and maintainability issues. Just have a key value object, json or anything similar which would be structures like that const access { "write": true, "read": true, "execute": false }. And yes I have seen some legacy library code that uses 1, 2, 4, 8, but I've always thought naturally that it's unnecessarily complicated pattern, I have understood it, but I haven't known it as "setting the bit" and I don't think I have ever tweaked code like that neither created this type of code myself, so I actually may have never written a line of code to actually set a bit.