69
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
staticis 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,
staticjust 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.
86
25
u/caldazar24 Sep 14 '20
I doubt the actual function would belong here. First, what qualifies as “truly stupid” by the standards of the git codebase is probably far better than anything posted here. Second, from the comment I assume they think it’s stupid for performance reasons, but using a naive algorithm (that’s probably easier to follow along when reading than a more optimal one) in an area where you don’t care about performance is good code, especially if the decision is being made very deliberately!
20
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 14 '20
Image Transcription: Code
/*
* This is a truly stupid algorithm, but it's only
* used for bisection, and we just don't care enough.
*
* We care just barely enough to avoid recursing for
* non-merge entries.
*/
static int count_distance(struct commit_list *entry)I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
7
9
246
u/slothefish Sep 14 '20
Is this in fact good code, because they explicitly call out that it's not worth investing the time to make it good, and that decision of time investment is good?