Poll: How many programmers don't know about bit-wise operations?
41–50 of 82 posts
Re: Poll: How many programmers don't know about bit-wise operations?
#42If you're not working with device drivers, embedded systems, or legacy code/filetypes you probably shouldn't be using bitwise operations. It can be confusing to other programmers, make your code a mess, and you're repeating optimisations probably found in libraries. This is just a generalisation of course, I use them on occasion. Mostly with string encoding oddities. For me using excessive bit operations is a red fla…
Re: Poll: How many programmers don't know about bit-wise operations?
#43I have always wondered why I was taught binary as if they were arrays, but programming languages never allowed me to use bits like arrays. It's always masking and shifting uint16_t or int32_t, instead of what I really want, "result = bits[3] xor bits2[3]".
Re: Poll: How many programmers don't know about bit-wise operations?
#44I use them a lot when I'm designing hardware, but I never use them when I'm doing "regular programming", there's no reason to do it if I can use more readable, higher level constructs.
Re: Poll: How many programmers don't know about bit-wise operations?
#45Earlier quoted context omitted.
The answer is hardware design. Most machines are at best "Byte Addressable" which means you have an address for a specific byte. In some cases, even if the system is "Byte Addressable" it's still actually faster to use blocks of bytes (2Byte/16bt, 4Byte/32bit, 8Byte/64bit). The reason why this is true is because the hardware design was optimized to handle blocks. Though I'm sure "Bit Addressable" hardware exists, I'v…
yes, but we don't care. A language is agnostic of the underlying system. Even the C standard is built on top of a machine that doesn't really exist. Anyhow, the point is, limitations of the underlying system aren't excuses for why this syntax isn't implemented. If I can write bitmasks, then so can a compiler, right?
Now while this may not be as "convenient" as array-style indexing, it definitely is orders of magnitude better than using bit masks and what not. You could also argue forcing to name each clump of bits (as a bit field struct forces you to) is a good thing, because most of the time the use case calls for something like this, and simply numerically indexing into bits might not be the most readable approach.
Re: Poll: How many programmers don't know about bit-wise operations?
#46For example, the WordPress JSON API I've been working on [0] uses them for HTTP methods. This lets me have an EDITABLE, which is actually just POST | PUT | PATCH. With the bit fields, a user can also indicate whether an endpoint expects JSON data and whether it should be hidden from indexes.
It's certainly possible to do all of this without bitmasks, but I personally think `EDITABLE | ACCEPT_JSON | HIDDEN_ENDPOINT` looks nicer than `array('methods' => array('POST', 'PUT', 'PATCH'), 'accept_json' => true, 'hidden' => true)`
[0]: https://gist.github.com/rmccue/5022591d312952d1245a#file-wp-...
Re: Poll: How many programmers don't know about bit-wise operations?
#47Clickable: https://news.ycombinator.com/item?id=5506458
At the moment, the linked submission is sitting at 2 points. The default is 1 point, and I'm the +1 up-voter. People writing code should know these things, but the move away from learning real low level languages means many people never learn these things. NOTE: The "low level" languages are assembly, microcode, and machine code, but never C. In spite of claims to the contrary, C is a high level language. When employ…
Why? I think every programmer who didn't grow up using a machine with a few kilobytes of RAM misses out on lots of fun, and it is true that some people need to know this (e.g. to write efficient hashing code, video compressors, networking code, etc), but I also think there is a place for programmers who only work at way higher levels, glueing together libraries others wrote with a decent UI.
"if they can swap two variable without a third"
I can, but I also know it may be harder to optimize for the compiler, and introduces a data dependency that many current processors have problems handling, and I know I never felt the need to remember which those processors were. More info at http://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_....
Re: Poll: How many programmers don't know about bit-wise operations?
#48There is no correct option for me. My actual answer is "I know about them and could do complex things with them when they're the right tool, but for the kind of programs I write they're never needed."
Instead I voted for the first thing.
Re: Poll: How many programmers don't know about bit-wise operations?
#49Earlier quoted context omitted.
Because 90% of all programmers don't do much than writing plain CRUD applications.
I see claims like this regularly, but never any data to support it. Do you have anything to back it up?
Unless you are doing games, HPC, codecs, drivers or compilers, you seldom use this type of stuff.
Re: Poll: How many programmers don't know about bit-wise operations?
#50Earlier quoted context omitted.
The answer is hardware design. Most machines are at best "Byte Addressable" which means you have an address for a specific byte. In some cases, even if the system is "Byte Addressable" it's still actually faster to use blocks of bytes (2Byte/16bt, 4Byte/32bit, 8Byte/64bit). The reason why this is true is because the hardware design was optimized to handle blocks. Though I'm sure "Bit Addressable" hardware exists, I'v…
yes, but we don't care. A language is agnostic of the underlying system. Even the C standard is built on top of a machine that doesn't really exist. Anyhow, the point is, limitations of the underlying system aren't excuses for why this syntax isn't implemented. If I can write bitmasks, then so can a compiler, right?
If the question is "why isn't bit indexing supported" then "because processors didn't (and don't) support it" is the historically correct answer, whether you like it or not.