this post was submitted on 30 Nov 2024
41 points (82.5% liked)

Programmer Humor

19821 readers
14 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] AVincentInSpace@pawb.social 9 points 3 weeks ago (1 children)

For the last time, Python is not weakly typed. It is dynamically typed. The statement 5 + "hello" results in a type error. Bash is weakly typed, and that same addition results in 5hello

[–] NaevaTheRat@vegantheoryclub.org 1 points 3 weeks ago (1 children)

Why do people think Python is ducktyped? The syntax is quite explicit, just because x = 5. is shorthand for x = float(5) doesn't mean it's doing weird mutations. The closest would be maybe that something like:

x = 5
y = 2.
z = x * y

works (I think) but that's not exactly a wacky behaviour. It's not like it ever does the wrong behaviour of casting a float to an int which can erase meaningful data and cause unpredictable behaviour.

I mean you can (and often should!) give functions/methods type signatures ffs.

[–] AVincentInSpace@pawb.social 7 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Because to a certain extent Python is duck typed. Python has no concept of interfaces, unless you count the abc module combined with manual isinstance() checks, which I've never seen anyone do in production. In order to be passed to some function that expects a "file-like object", it just has to have methods named read(), seek(), and possibly isatty(). The Python philosophy, at least as I see it, is "as long as it has methods named walk() and quack(), it's close enough to a duck for me to treat it as one".

Duck typing is distinct from weak type systems, though.

[–] FooBarrington@lemmy.world 2 points 3 weeks ago

Python has Interfaces in the form of protocols, but those are explicitly duck-typed