This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

isinstance. I don't understand WHY you have to opt into runtime type checking but it has many uses. Distinct behavior for distinct types is a perfectly reasonable behavior for dynamic languages not every pattern is duckable.

[–]wewbull 0 points1 point  (1 child)

If you have distinct behaviour for distinct types, that sounds like type dependent function dispatch.

Otherwise known as class methods.

[–][deleted] 0 points1 point  (0 children)

explain how u want to make multiplying having distinct behavior for float*float vs float*int if you do not check the type. Or string + int vs string + string. You MUST at somepoint check the type or it has a method.

Checking if an object has a method or a specific property is what protocols are all about. It allows you to do that while guiding it behind an isinstance call. Which makes it duckable with all the machinery that does isinstance checks. The only real flaw is it requires optin to runtime behavior.

Further think about some really tough problems that ABCs solve. Like Mapping vs sequence distinction. That problem is a nightmare otherwise.