Remix.run Logo
scoofy 3 days ago

I’m not sure what you mean. You’re not necessarily going to know the type of a variable just by reading a random section of code… especially in Python.

I absolutely going to add the type to the variable name if it’s a complex function. It’s just clearer.

zahlman 3 days ago | parent [-]

The point is to not care about the type. If you see `weight, radius, price = ...`, then it generally isn't going to matter whether `...` is a tuple or a list (or more exotic possibilities). What matters is that you can iterate over it, and iterating over it gives exactly three results, and the first result represents a weight, etc.

If your weights need to be, say, a floating-point number of kilograms, then you establish that convention, and only mark intentional deviations from the convention (e.g. because you're doing an explicit conversion to format output). (Or you use a library like Pint to give more formality to it.)

scoofy 3 days ago | parent [-]

Lists are mutable, tuples are not… that’s a massive difference if I’m editing code deep in a function I wrote two years ago.

zahlman 3 days ago | parent [-]

The point is that you clearly aren't mutating it in the current context. Therefore, knowing that you could mutate it doesn't help you understand what the current code is doing, nor guide you away from mistakes (as you would have no reason to try to mutate it).

scoofy 3 days ago | parent [-]

I operate a site where I have lists of things that have operations done on them all the time, occasionally I’ll load those series into memory as a tuple to save memory.

If I’m adding a feature to the site in 5 years, it’s going to be important to know if I’ve done that or not.