frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

How to Write the Worst Possible Python Code (Humor)

https://effective-programmer.com/how-to-write-the-worst-possible-python-code-8c6e49816e90?sk=d06d4241ce97a51a969fbce67070f8ba
18•naveed125•15h ago

Comments

photios•11h ago
Disappointed that my favorite pythonic pattern of "here's a dict with unknown contents, do the right thing with it" is not listed.
sunrunner•11h ago
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...

vidyava•1h ago
Serious question, but what is the best practice for keeping n-dimensional arrays organized/labeled? Pandas? Xarray? Converting everything to netcdf before using it?
msgodel•9h ago
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.

alfons_foobar•6h ago
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

naveed125•2h ago
haha, i should add this.
RadiozRadioz•11h ago
> abandoned packages with no recent commits

So, stable packages?

seanhunter•11h ago
I once was in the position of becoming pr approver[1] for a team of outsourced python programmers who were under some pretty extreme deadline pressure. Anyway one day a PR comes in and I can’t help but notice it was doing a string eval.

Weird. You almost never need to do string eval in python, and whenever there is something where you think you need eval there is a better and safer way to achieve the same result.

Also, I was bending my brain but I couldn’t really figure out what this eval was for until I wrote out some scratch code myself to figure it out.

Turns out this 5 lines or so was constructing a string to do dict lookup and then evalling that. So say you have a dict d = {‘foo’: ‘bar’} and you have a variable i=foo and want to look up d[i], instead of just doing that it was doing something like

   eval(‘d[‘+i+’]’)
Just no.

So I rejected the change and they came back with “but we’ve always done it that way”. I grep the codebase and yes. There were about 200+ uses of eval, all of which were constructing a string to look something up in a dictionary and then evaling the result. Some person who clearly didn’t program in python had found this twisted way to look things up in a dictionary and then this team had dutifully copied and pasted it throughout the codebase.

[1] ie I wasn’t there from the start of the project

kryptocannon•10h ago
> So I rejected the change and they came back with “but we’ve always done it that way”. I grep the codebase and yes. There were about 200+ uses of eval

That's code review's worst! Happened to me many times.

graemep•10h ago
I came across something quite similar. Using eval to convert a string to a dict. The string potentially included user input.
seanhunter•9h ago
I wonder whether my dudes cut and pasted from the same cursed stack overflow snippet as your dudes had.

The strings here included user input too. Worse still, the situation was the company was offering a b2b service and the string didn’t just come from user input by an employee of the company they came from arbitrary customers of the customers of the company.

franktankbank•9h ago
Yes! India? There is a very big follow the leader culture.
baobun•9h ago
Rhymes with apocryphal monkey-ladder story.
JimDabell•9h ago
I saw plenty of similar things from outsourced teams.

For instance: An e-commerce API that used JSON. Not only did the spec. tell them to use integers with pence for prices, but it explicitly called out that it MUST NOT use floating points with pounds. Sure enough, they implemented it as floating point pounds. So we asked them to fix this.

The underlying datatype in the database was pounds in a decimal type. You would think that they would multiply this by 100 and call it a day. What they actually did was: a) render it as a string, b) strip the period character, and c) parse the resulting string as an integer. They didn’t test this properly before deploying, which resulted in us charging the correct price for things that cost £xxx.x5 but undercharging by a factor of ten for things that cost £xxx.x0 and undercharging by a factor of a hundred for things that cost £xxx.00.

sim7c00•10h ago
oh but theres so much more worse xD... but i guess that goes in general for code. fun read tho and with reverse psychology u can maybe learn something as a novice snake wrangler xD
in12parsecs•10h ago
I am teaching python to a group of beginner programmers. This will be shared!
baobun•9h ago
Caveat #13
Zeppelin1492•10h ago
Alternative for rule 1 - give descriptive names to your variables, but then just reuse them throughout the function for all kinds values and purposes. The longer the function the better.

Example

    somethingService = ... 
    somethingService = somethingService.Do()
Really fun to debug.
xg15•10h ago
> Rule #13: AI-Assisted Coding is for the Weak

Me reading this article: yup, yup, yup, yup, wait a minute!

This part feels a bit snuck in, in a "leading and pacing" kind of way: All the other points are long-established no brainers, but this one is still controversially discussed and I'd say - in the general form it's presented here - wrong.

The author is still right that it's wrong to categorically dismiss AI tools when coding. But you'd have to apply a lot more caution to this point than to the others.

I hope sneaking this in wasn't the real motivation of the article.

baobun•10h ago
Classic listicle trick: All the obvious ones and one random controversial hot take to get the engagement going.
hsbauauvhabzb•9h ago
Jokes on you, the article is ai written
naveed125•2h ago
busted
ck45•9h ago
Double pro tip for naming identifiers: Overwrite built ins; dir, list, len, file, those are all beautiful identifiers and debugging the resulting bugs is twice the fun

Flavour 0.3.1 Java SPA Framework: Routing, Component, and Archetype Enhancements

https://sourceforge.net/p/flavour/groups/announce/thread/0fadec617e/
1•TeaVMFan•1m ago•1 comments

Texas OK's $50M for Ibogaine Research

https://www.nytimes.com/2025/06/14/health/texas-psychedelics-ibogaine-veterans.html
1•gametorch•1m ago•0 comments

James Jingleton

1•naulix•3m ago•0 comments

How can we get enough data to train a robot GPT?

https://itcanthink.substack.com/p/how-can-we-get-enough-data-to-train
1•JumpCrisscross•3m ago•0 comments

Increased Traffic from Web-Scraping AI Bots Is Hard to Monetize

https://m.slashdot.org/story/443217
2•gametorch•6m ago•0 comments

Freedom in the 50 states

https://www.freedominthe50states.org/
1•nabla9•7m ago•0 comments

Google is shutting down Android Instant Apps over 'low' usage

https://www.theverge.com/news/686573/google-android-instant-apps-shutdown
1•fidotron•7m ago•0 comments

Help: A decentralized public aid platform: no tokens, no VCs, full traceability

https://docs.google.com/document/d/1JxKSapReZbrVO47Bo0Fo5SVN0II1DGl8UVS7-6RsYuo/edit?usp=drivesdk
1•zodexid•8m ago•1 comments

Google paid £88.2M for North Weald Airfield land

https://www.bbc.co.uk/news/uk-england-essex-68302092
1•zeristor•9m ago•0 comments

What are the effects on humans if we decrease CO2 in a room down to 0 PPM?

https://www.quora.com/What-are-the-effects-on-humans-if-we-decrease-CO2-in-a-room-down-to-0-PPM
1•zeristor•12m ago•0 comments

Anyone Can Cook

https://world.hey.com/jorge/anyone-can-cook-c6346f84
1•mellosouls•16m ago•0 comments

Big Tech Is Dealing Flat Design a Death Blow

https://www.bloomberg.com/news/articles/2025-06-13/apple-airbnb-ditch-flat-app-icons-for-new-3d-ui-design
3•thm•17m ago•1 comments

Trust and Procedural Fetishism

https://ben-mini.com/2025/trust-and-procedural-fetishism
2•bewal416•25m ago•0 comments

Show HN: TorServ – Zero-config static web server over Tor hidden services

1•wonder-boy•26m ago•0 comments

Rapidly Growing Treasury Supply Crowding Out Other Types of Credit Growth

https://www.apolloacademy.com/rapidly-growing-treasury-supply-crowding-out-other-types-of-credit-growth/
2•everybodyknows•32m ago•0 comments

Cool years are now warmer than the past's warm years

https://globalclimaterisks.org/temperature/cool-years-are-now-warmer-than-the-pasts-warm-years-tracking-enso-and-polar-influence/
4•geox•33m ago•1 comments

Words of War

https://en.wikipedia.org/wiki/Words_of_War
1•consumer451•34m ago•0 comments

AMD's AI Future Is Rack Scale 'Helios'

https://morethanmoore.substack.com/p/amds-ai-future-is-rack-scale-helios
2•rbanffy•35m ago•0 comments

Tiny Awards

https://tinyawards.net/
1•laacz•36m ago•0 comments

Anam

https://anam.ai/
1•handfuloflight•37m ago•0 comments

Tclpysh: Multi-language shell supporting both Tcl and Python

https://wiki.tcl-lang.org/page/tclpysh
1•blacksqr•41m ago•0 comments

Strange radio pulses detected coming from ice in Antarctica

https://phys.org/news/2025-06-strange-radio-pulses-ice-antarctica.html
3•6581•42m ago•0 comments

What is systems programming, really? (2018)

https://willcrichton.net/notes/systems-programming/
2•fanf2•44m ago•0 comments

Computing Is Efficient

https://andymasley.substack.com/p/computing-is-efficient
3•jger15•51m ago•0 comments

Exploring the Best Input Representation for Electrocardiogram-Language Models

https://arxiv.org/abs/2505.18847
1•PaulHoule•55m ago•0 comments

Patent reveals Huawei's quad-chiplet rival for Nvidia's Rubin AI GPUs

https://www.tomshardware.com/pc-components/gpus/huaweis-quad-chiplet-rival-for-nvidias-rubin-ai-gpus-could-use-packaging-tech-that-rivals-tsmc-ascend-910d-rumors-have-seemingly-solid-foundation
1•rbanffy•55m ago•0 comments

The Tech Industry Doesn't Understand Consent

https://soatok.blog/2024/02/27/the-tech-industry-doesnt-understand-consent/
8•ColinWright•55m ago•1 comments

PCIe 6.0 SSDs for PCs won't arrive until 2030 – PCIe 5.0 SSDs are here to stay

https://www.tomshardware.com/pc-components/ssds/pcie-6-0-ssds-for-pcs-wont-arrive-until-2030-costs-and-complexity-mean-pcie-5-0-ssds-are-here-to-stay-for-some-time
4•rbanffy•57m ago•0 comments

Why AI and SQL Go Together Like Peanut Butter and Jelly

https://thenewstack.io/why-ai-and-sql-go-together-like-peanut-butter-and-jelly/
5•dxs•59m ago•0 comments

Architecture That Works with Challenging Terrain, Not Against It

https://www.core77.com/posts/137287/Architecture-That-Works-With-Challenging-Terrain-Not-Against-It
2•smartmic•1h ago•0 comments