this post was submitted on 13 Jul 2023
3 points (80.0% liked)

Python

6281 readers
83 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

No. Duck types (including virtual subclasses) considered harmful; use real inheritance if your language doesn't provide anything strictly better.

It is incomparably convenient to be able to retroactively add "default implementations" to interface functions (consider for example how broken readinto is in Python). Some statically-typed languages let you do that without inheritance, but no dynamically-typed language can.

This reads more as a rant against inheritance (without any explanation whatsoever) than a legitimate argument.

[–] [email protected] 1 points 1 year ago

Personally I prefer functional architectures + callbacks (better) / closures (tolerable),they tend to scale a bit better.

If a a dog needs to eat, then invoke the eat function with dog data and the dog eat function.

Explicit (this data is dog so I feed it with the dog eat function) vs implicit (I have no idea, I ask my data to eat as it pleases).

Explicit design tends to have fewer bugs my conjecture. Protocols are a halfway point, at least you know β€œhey this thing eats … uh … something.”

However, if doing that, just take it all the way - systems are better explicitly linking a verb to a noun vs assuming the noun knows how to verb.

It is also easier to test and debug.

[–] [email protected] 0 points 1 year ago (1 children)

I need to move away from using inheritance in my Python. I've been using Rust exclusively for the past year and it's definitely going to affect how I write code in other languages.

[–] [email protected] 1 points 1 year ago (1 children)

"If only I could make this a trait..."