-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I wouldn't use math.floor(x) != x #3
Comments
I did not know I do very appreciate you. I'll update the every codebase which is using Thank you!! |
Another thing is that you are artificially limiting your own code. Duck typing in dynamic languages has a purpose and can help you to avoid long lines of code because you rarely need to type check the stuff. What is for example if someone code a complete new number type not based on the actual types but it has implemented the same or a very similar interface like an integer or a complex number. Why shouldn't Why should a vector class with arbitrary dimension not work with your function? Don't forget that all number types are vectors, just with specific dimensions and rule set. ;) If you never heard of this look out for Quaterions and Hyperr Complex Numbers. This is actually very important in python. Think a while about this problem, maybe you can come up with an elegant, smart and DRY (don't repeat yourself) solution. |
@KleinerNull You are right. I was do limiting my code by myself. So I decide that I should remove the type checking on functions which can accept various numeric types such as But, I should restrict the type on functions which can accept specific types, for exampe, the fibonacci function must only accept the integers. |
I forgot the advantages of dynamic types, Thank you to remind it to me. |
Why? For example
I've got the feeling you didn't understand my point. The idea was ad-hoc polymorphism. Look at how addition, subtraction or
The same is happening for all the other stuff like the basic operations and also abs. |
Ok I got it. def fibonacci(n: int) -> int:
# blah without the custom Exception raising. Because, with common sense, the fibonacci function can work only with integer. So, I just specify the input type hint to definition of function. I do not raise the custom error now with Is it still weird? (Yes, I know that |
(Sorry for my english, I'm not a native speaker. Please understand) |
Me too, me too. So don't worry :D
Type hints are fine, but don't think about them as static typing like in other languages. |
Sure, I know that :) Anyway, thanks for pointing out the important things, it is very helpful to me. It was an interesting conversation :D |
Go the save round and just use
isinstance(n, numbers.Number)
ornumbers.Complex
,numbers.Real
and and and. So you don't need to import the math module at all, which I think was your goal.The text was updated successfully, but these errors were encountered: