6 ms·
Why? I mean if you look at the majority of work that programmers do today - frontend/backend web development and apps, there is no need to have knowledge about
by Illniyar 9y ago
Why? I mean if you look at the majority of work that programmers do today - frontend/backend web development and apps, there is no need to have knowledge about bits.
In fact, if I see someone using binary operators in languages such as Java,JS,Ruby etc... I'll immediately consider it bad code, regardless of context - it's just not the right tool for the level of abstraction in these languages.
The fact is that in these products (frontend/backend web development and apps) the performance profile is dominated by bad algorithms, wrong data structures, slow libraries, missing db indexes etc... which knowledge about bits help absolutely zero with.
Large binaries are also not dominated by code you write but rather by using too broad libraries or simply from huge assets.
The only thing I'd consider knowledge of bits to be of any help to a run of the mill developer these days is the knowledge that floating point numbers don't multiply/divide well - but that kind of knowledge can be imparted without really diving into how bits work.
- bitexploder 9y agoThis just seems wrong to me. There are plenty areas of programming where knowing a little bit about internal data representation, either in memory or in your data store can help you make better choices. Not everyone needs to be a system programmer, but folks still need general computer awareness. We just aren't far enough from the CPU yet. Sufficiently advanced understanding of algorithms implies computer architecture awareness to me. I get what you are writing about here, that higher level concepts dominate programming many common apps today, but it seems like a weird place to allow yourself to have a knowledge gap.
- deanCommie 9y agoIt shouldn't feel wrong to you. In today's connected big-data world, the vast majority of your performance latency is from querying your data (if you structure your db incorrectly), followed closely by client to server communication. That's the p90 use case for development people are doing.
- lorenzk 9y agoWhat's a "p90 use case"?
- bitexploder 9y ago90th percentile use case
- roadnottaken 9y agoHa I thought it was related to P90X somehow https://en.wikipedia.org/wiki/P90X https://en.wikipedia.org/wiki/P90X
- bitexploder 9y agoSo many simple things are only easy if you know bits. Interpreting a packet capture, poking at memory, designing cache friendly data structures, ... It is like second nature to me. If it isn't required (obviously it isn't, it must at least be a strong competitive advantage). I am not that old. I don't have get off my lawn moments. I grew up (really learned at least) on a processor (P133) where bits started mattering less, but they still mattered.
- pennaMan 9y agoWhat are some good resources to learn about bits?
- jeffreygoesto 9y agoThere are some quite good pages, I don't remember the exact titles, but the first results are quite ok: https://www.google.de/search?q=bit%20hacks https://www.google.de/search?q=bit%20hacks
- bitexploder 9y agoYou can write mostly C code. Each processor will have different quirks. https://en.wikipedia.org/wiki/CPU_cache https://en.wikipedia.org/wiki/CPU_cache https://www.akkadia.org/drepper/cpumemory.pdf https://www.akkadia.org/drepper/cpumemory.pdf These are great places to start. Especially Ulrich Drepper's PDF on memory. edit: even simple things like looping can require knowledge of "bits" and "memory layout" and "CPU cache" to write the fastest code. Most people don't need to write the fastest code though.
- theon144 9y ago>the majority of work that programmers do today - frontend/backend web development and apps Therein lies your bias, and the rest of your comment just follows.
- Illniyar 9y agoI'm definitely bias towards frontend/backend web development and apps (I.E. mobile/desktop apps). But that's not to say the premise is bad - I don't think it's wrong to assume the majority of work is in that area, definitely for young developers. There aren't that many real-time and performance-demanding programming jobs compared to web development. I don't think even game-programming uses bit operations heavily these days- most of the low-level work is done by third party engines.
- throwaway2016a 9y agoJust the other day I showed one of our junior devs how they could turn their 10 lines of somewhat slow and obfuscated code into a 3 arguably more readable lines using a bitwise operations. And this was a front-end webapp. Then again, more readable is subjective and some devs might see "<<" and get thrown off.
- onion2k 9y agoA reasonable 'compromise' of 3 lines of code with 7 lines of comment to explain what it's doing would be my preference.
- throwaway2016a 9y agoOr... and just throwing this out there... developers can take responsibility to know what bitwise operators do the same as they know what "+" does. The three lines of code were: for ( ... ) { x = x << y } The developer was essential using an array of booleans to simulate a bitwise operator. It is very sad that devs these days need a comment to know what that does. Would we expect 7 lines of comments if it was: for ( ... ) { x = x + y; }
- onion2k 9y agodevelopers can take responsibility to know what bitwise operators do the same as they know what "+" does Yes but they won't. Pragmatically speaking adding a comment to explain a concept the next developer won't use very often means you won't need to answer their questions about it when they next need to modify that piece of code. That's a big win for you, and it means the other developer can carry on being productive.
- viraptor 9y ago> using binary operators [...] bad code, regardless of context > the performance profile is dominated by bad algorithms, wrong data structures Do you know how you often implement good algorithms and data structures? You wouldn't implement a bloom filter as a high level array of 1/0 integers, would you?
- Illniyar 9y agoI would definitely implement a bloom filter with an array of booleans, and will not use bit operations to modify the cells. Whether I use array access or a bitmask will mean nothing performance-wise, since the bloom filter itself is likely already speeds up a different algorithm by an order of magnitude.
- ajuc 9y ago> In fact, if I see someone using binary operators in languages such as Java,JS,Ruby etc... I'll immediately consider it bad code, regardless of context - it's just not the right tool for the level of abstraction in these languages. Clojure is written in java (and clojure). It uses bit operations to implement Software Transactional Memory and persistent collections. Is it a bad code? You seem to think a programmer should always code on the same level of abstraction. I'd argue in many applications often you find no suitable abstraction, and have to implement it yourself. Also linear feedback shift registers can be used without any knowledge about bits other than the fact that integers loop over when they reach maximum value (and every programmer should know that anyways). And these registers are useful for some very nice algorithms (like in-place pseudorandom permutations' generators - for example for shuffling songs in a media player, or for some ai algorithms).
- Illniyar 9y agoI don't know enough about Clojure, but I think you are saying that Clojure itself is using bit operations behind the hood - of course it's ok for a language implementation to use bit operations. But if any of your Java code for applications or libraries used bit operations, I'll call it bad code.
- open_bear 9y agoConway's Game of Life can be implemented naively in C/C++/Java/etc, using a boolean for every cell's state (on/off). This will require at least n*m bytes (probably more in Java). Using bits to store that data will require 8 times less, which will most likely greatly increase the performance because of the data locality and the amount of data that will fit into a CPU cache.
- Illniyar 9y agoConway's game of life is at best school homework, it does not correlate to any programming done in a real job.
- 9y ago
- kutkloon7 9y agoI remember a recent example. What I wrote was: int x = somefunction(); int x_dividedby16 = x >> 4; My coworker corrected the second line to something like: int x_dividedby16 = (int)Math.ceil(x / 16.0);
- biesnecker 9y agoDid your coworker correct it with "this is more readable" or "this is the correct way to do it"? The first is arguable (though I don't personally agree with the argument), the second just betrays a real lack of knowledge.
- sammoth 9y agoDon't the two bits of code have completely different behaviour? And the code with the bitshift is undefined on negative integers (in C). So the bottom code could indeed be the "correct way to do it".
- biesnecker 9y agoFair, with negative ints they're different. They have the same behavior on positive ints, though.
- krzat 9y agoWhy not `x / 16`?
- fundabulousrIII 9y agoFor most operational purposes there isn't a crying need for optimizations and handwritten assembly outside the kernel but a good programmer must at least recognize where something like this is called for and be able to implement (imo).