News for hackers. Stuff that matters.
Re:How to Write the Worst Possible Python Code (Humor) by photios on Saturday June 14, 2025 @05:39AM (#44275322)
Disappointed that my favorite pythonic pattern of "here's a dict with unknown contents, do the right thing with it" is not listed.
Re:How to Write the Worst Possible Python Code (Humor) by msgodel on Saturday June 14, 2025 @07:29AM (#44275709)
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.

Re:How to Write the Worst Possible Python Code (Humor) by sunrunner on Saturday June 14, 2025 @06:12AM (#44275433)
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...

Re:How to Write the Worst Possible Python Code (Humor) by vidyava on Saturday June 14, 2025 @04:22PM (#44278569)
Serious question, but what is the best practice for keeping n-dimensional arrays organized/labeled? Pandas? Xarray? Converting everything to netcdf before using it?
Re:How to Write the Worst Possible Python Code (Humor) by alfons_foobar on Saturday June 14, 2025 @10:59AM (#44276802)
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

Re:How to Write the Worst Possible Python Code (Humor) by naveed125 on Saturday June 14, 2025 @02:55PM (#44278057)
haha, i should add this.
Re:How to Write the Worst Possible Python Code (Humor) by ck45 on Sunday June 15, 2025 @04:28AM (#44281240)
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.