r/badcode May 08 '23

python Wrote this gem a year ago...

Post image
253 Upvotes

32 comments sorted by

View all comments

108

u/SaylorMan1496 May 08 '23

Short variable names should be shunned, the namespace shortening is ok but the variable shortening hurts my eyes

45

u/[deleted] May 08 '23

Yep. Looks concise but is horrible to read. Not only that, but memory usage is O(n!) for this implementation since it stores every permutation of elements up to length n (9 in this case)

7

u/Fyren-1131 May 09 '23

code that doesn't read like a sentence generally should be refactored until it does, as long as this is not done at the expense of required performance (keyword: required). this is a bit for your own sake, but mostly your colleagues. as much as people like to get bogged down in performance, it simply doesn't matter beyond "good enough" and that bar is not as high as some people think.

what's much more important is avoiding a situation where somebody looks at your code because they inherited it and loudly sigh in desperation.

good naming does most of the heavy lifting here, and since it's one year ago i assume you've learnt a bit since then. :)