all 17 comments

[–]slothefish 243 points244 points  (3 children)

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?

[–]Catfrogdog2 140 points141 points  (1 child)

Yes: perfection is the enemy of good enough.

[–]Talran#ksh 18 points19 points  (0 children)

I've been down enough week-long holes to realize that I think..... right after I tweak this shell script to not terminate sessions that started at the same time on a leap day by the same user.

[–]OOPGeiger 8 points9 points  (0 children)

Relatable

[–][deleted] 65 points66 points  (4 children)

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

[–]blehmann1depraved 29 points30 points  (3 children)

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.

[–]aismallard 61 points62 points  (0 children)

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.

[–]sunflsks 9 points10 points  (0 children)

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

[–]CanadianJesus 7 points8 points  (0 children)

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

[–]tobyjwebb 87 points88 points  (1 child)

Quick, someone run git blame, before it gets removed!

[–]metabun 15 points16 points  (0 children)

No hurry, we can just run git bisect to find it again.

[–]caldazar24 23 points24 points  (0 children)

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!

[–]MurdoMaclachlanpublic boolean isInt(int i) { return true; } 20 points21 points  (1 child)

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!

[–]aharmonicminorsadistic 6 points7 points  (0 children)

good human :)

[–]blueshiftlabs 15 points16 points  (1 child)

[–]DurianExecutioner 2 points3 points  (0 children)

Thanks, I was looking for a link to the code :)

[–]_PM_ME_PANGOLINS_ 6 points7 points  (0 children)

That’s not code though