News for hackers. Stuff that matters.
Re:Low Level Bit Hacks You Absolutely Must Know by majewsky on Friday May 11, 2018 @09:00AM (#17046954)
At least in C++, wouldn't you just write these "hacks" only once, in inline methods of a BitField class? It's much more likely to mistype

  state = state & ~BIT7;
than to mistype

  state = state.without(BIT7);
Re:Low Level Bit Hacks You Absolutely Must Know by scraft on Friday May 11, 2018 @11:07AM (#17047799)
As daemin says, no, I am used to working with people that find basic bit field manipulation easy to work with[1], so there isn't any confusion.

Plus there are performance concerns. I remember one graduate introducing a c++ bit field class and tried to replace some core functionality with it and killed performance. Developers prefer to debug non optimized builds, and non optimized builds can end up running slow when you replace simple one liners with classes and inline methods that don't get optimized in debug builds.

[1]I hope this doesn't sound aggressive as it really isn't intended to. It is just everyone is so used to seeing bitwise operations it is as straight forwards as reading "set the third bit" or "toggle the last bit" when we see the C code.

Re:Low Level Bit Hacks You Absolutely Must Know by dahfizz on Friday May 11, 2018 @11:12AM (#17047853)
Would you create a wrapper class and member function to make addition less likely to mistype?

num = num.plus(x);

might be less likely to mistype than

num = num + x;

but nobody would ever do that. Once you've done bitwise operators a few times they become just as comfortable and natural as addition or subtraction.

Re:Low Level Bit Hacks You Absolutely Must Know by daemin on Friday May 11, 2018 @10:35AM (#17047571)
Nope, people actually just write the bit setting code. It's simpler and also I haven't found a good generic bit flags class that works as you intend.
Re:Low Level Bit Hacks You Absolutely Must Know by slededit on Friday May 11, 2018 @03:30PM (#17050202)
What about C++ bitfields? Not a library but a language extension. A lot of code I used has migrated to that.
Re:Low Level Bit Hacks You Absolutely Must Know by daemin on Monday May 14, 2018 @06:59AM (#17064374)
Normal C++ bitfields? Sometimes you get that inside classes in the form of "bool x : 1; bool y : 1;" etc. But that's much harder to use as far as function parameters go, so old school bitmasks are used for that.
Re:Low Level Bit Hacks You Absolutely Must Know by coldacid on Friday May 11, 2018 @12:26PM (#17048627)
I'd only do that if I could force every compiler to _always_ inline those methods. The cost of a method call for a simple bit operation is magnitudes greater than just doing the operation itself (tens to hundreds of ops versus 1-5).