r/badcode • • Sep 13 '20

c Found in git's bisect algorithm

Post image
744 Upvotes

17 comments sorted by

View all comments

69

u/[deleted] Sep 14 '20

What makes it bad? Because they say the algorithm is stupid?

30

u/blehmann1 depraved Sep 14 '20

Well it has to be don't it? There's nothing but the comment and the method signature, and the method signature looks fine to me.

The static is the only thing worth noting because it looks like C++, and in C++ you probably shouldn't use raw pointers. But the keyword does actually have a meaning (although a little obscure) in C. Plus I think Linus Torvalds is pretty damn negative on any C++ code making its way into git.

64

u/aismallard Sep 14 '20

It's C, static just means the function is private to the object file. It's common and not a big deal.

The "bad code" aspect here is the comment admitting they use lazy implementation because it's only used for bisecting.

12

u/sunflsks Sep 14 '20

Git doesn’t have any C++ I think. It looks like it’s a whole function that was just cropped out

8

u/CanadianJesus Sep 14 '20

Raw pointers is a bit like raw dogging, if you know what you're fucking around with it's not that dangerous.