+ 1

Why single dispatch is not working

Refer code below: Why it is not working? https://sololearn.com/compiler-playground/chb215v6YsD9/?ref=app

2nd Jan 2025, 5:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
6 Respuestas
+ 4
https://sololearn.com/compiler-playground/ct7tO9qK6w51/?ref=app
2nd Jan 2025, 8:54 PM
Vitaly Sokol
Vitaly Sokol - avatar
+ 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
3rd Jan 2025, 2:11 AM
Bob_Li
Bob_Li - avatar
+ 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
2nd Jan 2025, 9:15 PM
MO ELomari
MO ELomari - avatar
+ 2
3rd Jan 2025, 3:41 AM
Bob_Li
Bob_Li - avatar
+ 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
3rd Jan 2025, 4:19 AM
Bob_Li
Bob_Li - avatar
+ 1
Thanks Everyone for these great solutions!
3rd Jan 2025, 10:08 AM
Ketan Lalcheta
Ketan Lalcheta - avatar