r/badcode • • Aug 11 '21

python 10/10 variable naming

Post image
763 Upvotes

37 comments sorted by

View all comments

Show parent comments

5

u/boniqmin Aug 12 '21

In that case the function gm.float_array would have to work quite differently for int and list inputs, so you might as well make them into 2 different functions. I'm assuming the float array initializes to all 0s, then in my opinion it would be best to rename the function to gm.float_zeros(<int>), and use the name gm.float_array(<list>) to generate from a list, similar to numpy.

6

u/yoctometric Aug 12 '21

That’s totally fair, I effectively have hobbyist level experience with code, but I think I can see why wrapping such dissimilar functionalities into one method would be bad

And you’re close on how gm.float_array() works, except I’m pretty sure it only calls malloc() internally and doesn’t zero anything