+ 1
Why single dispatch is not working
Refer code below: Why it is not working? https://sololearn.com/compiler-playground/chb215v6YsD9/?ref=app
6 odpowiedzi
+ 4
https://sololearn.com/compiler-playground/ct7tO9qK6w51/?ref=app
+ 3
More on the topic on singledispatch, workaround for OOP and alternative libararies to use:
https://stackoverflow.com/questions/24601722/how-can-i-use-functools-singledispatch-with-instance-methods
Basically, for OOP, use singledispatchmethod
instead of singledispatch
https://sololearn.com/compiler-playground/clQkeTocrFe7/?ref=app
+ 2
you need to specify what types they will handle ( the second and third registered functions ):
https://sololearn.com/compiler-playground/c46fmfprYlHV/?ref=app
or
https://sololearn.com/compiler-playground/ciHHzSk0uKLM/?ref=app
+ 2
There's also a multipledispatch library:
https://sololearn.com/compiler-playground/cUKggWX2aiqx/?ref=app
+ 2
Function overloading like this is actually inefficient and harder to use.
1. You are actually doing more work just to be able to use the same function name.
2. It's unclear what the function's return will be.
Why not just use different functions with more specifically descriptive names instead of insisting to use the same function name?
It's an anti-pattern. Remember that " just because you can doesn't mean you should "...
https://sololearn.com/compiler-playground/c6DM5TWwmOiF/?ref=app
+ 1
Thanks Everyone for these great solutions!