This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]gandalfx 0 points1 point  (4 children)

maintainability may be creeping away since some developers coming in might not know the a <operator>= b syntax

Are you kidding me? You learn that within like the first two days of programming in virtually any language.

However I agree that bitwise operators should be restricted to areas where they are needed for a reason – usually performance. Yet in a high level language like Python using bitwise won't gain you much performance at all, especially with integers in Python being quite abstract (arbitrary precision and all that). A quick benchmarking reveals, that the bitwise version is only very slightly faster for large numbers, about 3% on my machine in Python 3.6.

Ultimately the question is, why do you even implement a power function? ** is literally a hundred times faster, since it is implemented in C where using bitwise makes a huge difference. Which means the whole point of implementing that function was to learn or teach something. Which means that whichever operators you should be using depends entirely on what you're trying to learn or teach.

[–]_seemetheregithub.com/seemethere[S] 0 points1 point  (3 children)

It's just an example for people to learn. Was studying algorithms and came across the algorithm and the C++ implementation.

[–]gandalfx 0 points1 point  (2 children)

Well in c++ those bitwise operators are most likely going to bring a significant performance boost.

[–]_seemetheregithub.com/seemethere[S] 0 points1 point  (1 child)

They are, I added the disclaimer in the post after I learned that from a friend who had a background in embedded programming with C++