Skip to content
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

Closed
DartBot opened this issue Nov 10, 2011 · 8 comments
Closed

Add abs to Math #411

DartBot opened this issue Nov 10, 2011 · 8 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 10, 2011

This issue was originally filed by [email protected]


Math should have the abs method that returns the absolute value of the num passed in.

@floitschG
Copy link
Contributor

It's a member on 'num'.
Closing as invalid. If your issue is actually that it shouldn't be there, but on Math, please reopen.


Added Area-Compiler, Invalid labels.

@DartBot
Copy link
Author

DartBot commented Nov 10, 2011

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.

@floitschG
Copy link
Contributor

Removed Area-Compiler label.
Added Area-Library, Triaged labels.

@DartBot
Copy link
Author

DartBot commented May 8, 2012

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.

@DartBot
Copy link
Author

DartBot commented Aug 28, 2012

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:
(foo+bar).abs() feels wrong
(foo-9999).abs()

While:
Math.abs(foo+bar)
Math.floor(foo+bar) feels correct.

Also as the instruction is coming first it is like saying "We are going to floor the result of: foo + bar"

@DartBot
Copy link
Author

DartBot commented Feb 27, 2013

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.

@lrhn
Copy link
Member

lrhn commented May 29, 2013

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!
Reading code is much harder than writing it in the long run, so we'll keep to one way of doing this.
So, all in all, we think the disadvantages of having the same function twice outweighs the advantages.


Removed Type-Defect label.
Added Type-Enhancement, WontFix labels.

@DartBot
Copy link
Author

DartBot commented Jan 5, 2014

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 closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants