frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Static Protocols in Python: Behaviour over Inheritance

https://patrickm.de/static-protocols-in-python/
2•sneakyPad•1h ago

Comments

go26•1h ago
To use it:

  from typing import Protocol
s/new //
sneakyPad•16m ago
Good catch! Thanks a lot, I updated the snippets.
MORPHOICES•1h ago
I remember reading this thing about programming where people talk about behavior instead of inheritance. It stuck with me because Ive dealt with some code that got messy fast. ~

Like, when do you actually pick behavior over inheritance in stuff youre writing? I mean, the question is out there, asking for real experiences.

For me, inheritance seemed okay at first, you know, building these trees that looked neat. But then they turn rigid, and youre stuck. It burns you a few times.

Shifting to behavior feels better. Its not about what the object is exactly, but what it can do. That changes things.

Protocols help make that clear, or interfaces in different languages. The idea is, if it acts like it can do the thing, then it works. Kind of like the duck thing, if it quacks like a duck.

I have this rough idea in my head. Use inheritance when you want to share the actual code implementation. But for protocols, its more about what everyone expects, the shared behaviors.

Still, Im not totally sure where to draw the line between them. It gets a bit fuzzy.

How do others figure it out? What are the signs that inheritance is going to cause problems down the road, like aging badly?

sneakyPad•12m ago
Those are some very good thoughts and questions. As I tried to touch on in the article, the own mental model has to shift slightly away from the typical inheritance tree. I have built products in which I use inheritance over behaviour, and it was fine. However, I also experienced that it does make the code tightly coupled, and this leads also to what you describe, as it got messy fast. All of a sudden, I added edge cases here and there. Certainly, the abstraction could have been improved, but the point remains. It would have aged even worse with multiple devs on the product and different libraries. Large inheritance trees tend to become brittle. That was my point with the machine learning models. With behaviour and static protocols, it has been so much easier to integrate different approaches.

Having said that, I read (I think also from Luciana Ramalho) that inheritance can make sense when developing a library/package itself. Nevertheless, I would try to use static protocols as long as it seems possible. Inheritance for code reuse is an implementation detail. It can often be replaced by composition and delegation.

I hope this gives you a bit more context to the article and idea of using behaviour over inheritance.

CATL Makes Big Announcement on Sodium Batteries for 2026

https://cleantechnica.com/2025/12/29/catl-makes-big-announcement-on-sodium-batteries-for-2026/
1•ksec•1m ago•0 comments

Peek-a-boo and the First Lesson in Awareness [essay]

https://omegaaxiommeta.substack.com/p/why-we-play-peek-a-boo-contrast-pattern
1•nilegreen•6m ago•1 comments

Enough of the 'Hey you ' faux-friend nonsense. You're a business, not my mate

https://www.theguardian.com/commentisfree/2026/jan/01/the-hill-i-will-die-on-business-friend-indi...
2•beardyw•9m ago•0 comments

Built AI chatbot platform to be 100% EU-hosted after customers refused OpenAI

https://www.chatvia.ai
1•mayahi•14m ago•0 comments

Bulgaria joins euro area from 1 January

https://ec.europa.eu/commission/presscorner/detail/de/ip_25_3123
2•yreg•15m ago•0 comments

China builds a record-breaking hypergravity machine to compress space & time

https://www.google.com/url?q=https://www.scmp.com/news/china/science/article/3338193/china-builds...
1•mnming•17m ago•0 comments

Windows 11 Outperforming Linux on an Intel Arrow Lake H Laptop

https://www.phoronix.com/review/windows-beats-linux-arl-h
13•tuananh•19m ago•2 comments

Deltax: A non-decision AI governance framework with explicit stop conditions

https://zenodo.org/records/18100154
1•DELTA-X•19m ago•1 comments

Bluetooth Headphone Jacking: A Key to Your Phone [video]

https://media.ccc.de/v/39c3-bluetooth-headphone-jacking-a-key-to-your-phone
1•AndrewDucker•22m ago•0 comments

V programming language version 0.5 released

https://github.com/vlang/v/releases/tag/0.5
2•hggh•23m ago•0 comments

Show HN: 1seed – Derive all your crypto keys from a single seed

https://github.com/oeo/1seed
1•genesishash•24m ago•0 comments

Show HN: BakwasLogin – A user-hostile login with physics-based password entry

https://www.bakwaslogin.app/
2•bhavesh_kukreja•31m ago•0 comments

IQuest-Coder: Open model w/ 81.4% on SWEBench

https://iquestlab.github.io/
5•denysvitali•31m ago•0 comments

Role of psychological strengths in positive life outcomes in adults with ADHD

https://www.cambridge.org/core/journals/psychological-medicine/article/role-of-psychological-stre...
1•bookofjoe•32m ago•0 comments

Bulk image conversion client-side using Web Workers

1•lemongravity•32m ago•0 comments

Navigating Moats in the AI Transition

https://shaokang.substack.com/p/navigating-moats-in-the-ai-transition
1•Wraecca•34m ago•0 comments

Facebook is testing a link-posting limit for professional accounts and pages

https://techcrunch.com/2025/12/17/facebook-is-testing-a-link-posting-limit-for-professional-accou...
3•austinallegro•36m ago•0 comments

I rebooted my social life

https://takes.jamesomalley.co.uk/p/this-might-be-oversharing
3•edent•38m ago•0 comments

Can a Commodore 1541 disk drive be used as a general purpose computer? [video]

https://www.youtube.com/watch?v=6loDwvG4CP8
2•amichail•38m ago•0 comments

China's CXMT eyes $4.2B Shanghai listing to fund DRAM expansion

https://www.reuters.com/world/asia-pacific/chinas-cxmt-eyes-42-billion-shanghai-listing-fund-dram...
1•ksec•45m ago•1 comments

Rust–: Rust without the borrow checker

https://github.com/buyukakyuz/rustmm
13•ravenical•46m ago•11 comments

The Tech We've Lost in 2025

https://www.cnet.com/tech/the-tech-weve-lost-in-2025/
1•taubek•46m ago•1 comments

Show HN: Mailcow/Rspamd kept missing obvious spam so I built my own email filter

https://email-filter.ai/
1•rodoni•48m ago•0 comments

Free AI Stamp Generator and Online Stamp Maker

https://stampgenerator.net/
1•qweasdzxc111111•48m ago•0 comments

Wicked Engine: 3D engine with modern graphics

https://github.com/turanszkij/WickedEngine
1•ksec•49m ago•0 comments

Show HN: Awesome Symbian

1•catstor•49m ago•1 comments

Crown: The Flexible Game Engine

https://www.crownengine.org/
1•ksec•50m ago•0 comments

Gnashing of Teeth

https://www.250bpm.com/p/gnashing-of-teeth
1•tosh•1h ago•0 comments

How did the world change in 2025?

https://frontier2025.netlify.app/
1•que3216•1h ago•0 comments

Show HN: Distill – Remove redundant RAG context in 12ms, no LLM calls

1•sidk24•1h ago•0 comments