-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add abs to Math #411
Comments
It's a member on 'num'. Added Area-Compiler, Invalid labels. |
This comment was originally written by [email protected] Having some methods on num and others on Math is quite confusing. Math has sqrt, num has abs. I can imagine a rule where if it's an operation on a number then it should be in num, if it's on multiple nums it should be in Math, but that's violated by sqrt. So I'll ask that this be considered a request for consistency between num and Math and that floor, ceil, truncate, round, and abs should be moved to Math. |
Removed Area-Compiler label. |
This comment was originally written by [email protected] I can imagine a rule where if it's an operation on a number then it should be in num, if it's on multiple nums it should be in Math, but that's violated by sqrt. +1 for that idea. So instead of moving floor, ceil, truncate, round, and abs to Math. sqrt should move into num. |
This comment was originally written by [email protected] I'm starting with dart and was searching for the Math.abs Considering almost everywhere abs belongs to Math this lib will be the first place users will search, and they will be confused when they don't find it. Although I understand moving this kind of logic to num so that Math as other utilities. Doing: While: Also as the instruction is coming first it is like saying "We are going to floor the result of: foo + bar" |
This comment was originally written by [email protected] I would like to echo comment #6. Looking in Math is the first place to look on some of these. In fact, as a newbie, I wouldn't have even thought of looking in num until finding this post. Call it a remnant of being a C++ developer, but I don't think of a double as having operations for abs, sqrt, floor, ceil, etc. That's just not intuitive for me. So Math is the first place to look. As a potential side fix, maybe replicate some of that functionality in Math simply by redirecting functions for sqrt, abs, etc. to be the return of num.xxx(). Similar to adding this in Math: static num abs(num value) {return value.abs();} It shouldn't be that much work, and would save lots of newbie Dart developers lots of time hunting for the right function call. |
While I can understand the pain (as a C++/Java/JavaScript programmer), we don't intend to hide the object nature of integers and doubles. Unlike the languages above, a double is a full object in Dart, and it has methods, and it makes a certain kind of sense to have "abs" as a method on all numbers. We also don't want too much duplication. It's bad for readability - if one programmer used "d.abs()" and another uses "abs(d)", reading suffers - is it the same, or is it different, and why is it different??? - PANIC! Removed Type-Defect label. |
This comment was originally written by @stevenroose +1 on this issue. Now that Dart passed 1.0, I assume this won't be changed? |
This issue was originally filed by [email protected]
Math should have the abs method that returns the absolute value of the num passed in.
The text was updated successfully, but these errors were encountered: