Hacker News new | ask | show | jobs
by photios 371 days ago
Disappointed that my favorite pythonic pattern of "here's a dict with unknown contents, do the right thing with it" is not listed.
5 comments

Hey now, at least the dictionary has keys that _could_ hint at the contents (or be completely misleading). What about the tuple with just positions?

    image.size
    ndarray.shape
Are the image sizes (width, height) or (height, width)?

Trick question of course, it's (height, width, channels) for numpy. numpy is fairly well known though and sort of gets away with it, but when your never-seen-before internal company starts doing this, well...

Serious question, but what is the best practice for keeping n-dimensional arrays organized/labeled? Pandas? Xarray? Converting everything to netcdf before using it?
It's not just Python. You see this a lot in Javascript and Groovy too.

Really I think what makes languages with manual memory management and limited built in types like C nice is it forces people to really think about the types and interfaces they're writing instead of just hacking unmaintainable code at 20 lines an hour.

Seen (and fixed): A function returns some “struct” (as a dict), with a couple of fields, mostly stringly typed, and one field for accumulating error messages called “errors”. The dict was created as a defaultdict(list) (probably) to make it easier to append messages.
haha, i should add this.
What do you mean, "unknown contents"?

Just trace back the dict to it's origin, through all the places it can be modified, and you know what is (or could be) inside...

/s