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

Math.parse{Int,Double} could be constructors #2868

Closed
DartBot opened this issue May 2, 2012 · 5 comments
Closed

Math.parse{Int,Double} could be constructors #2868

DartBot opened this issue May 2, 2012 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 2, 2012

This issue was originally filed by @seaneagan


It would be more consistent/logical to have Math.parseInt and Math.parseDouble as constructors:

interface int {
  int.parse(String s); // could use "fromString" but it's a bit long
  //...
}

interface num {
  num.parse(String s);
  //...
}

interface double {
  double.parse(String s);
  //...
}

@DartBot
Copy link
Author

DartBot commented May 2, 2012

This comment was originally written by @seaneagan


It might make more sense as static methods in order to be able to handle invalid Strings and nulls intelligently (similar to issue #2870):

interface int {
  // returns ifInvalid if s is null or is incorrectly formatted
  static int parse(String s, [int ifInvalid]);
  //...
}

interface num {
  // returns ifInvalid if s is null or is incorrectly formatted
  static num parse(String s, [int ifInvalid]);
  //...
}

interface double {
  // returns ifInvalid if s is null or is incorrectly formatted
  static double parse(String s, [int ifInvalid]);
  //...
}

@sethladd
Copy link
Contributor

sethladd commented May 3, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented May 8, 2012

Removed Area-Language label.
Added Area-Library label.

@DartBot
Copy link
Author

DartBot commented May 9, 2012

This comment was originally written by @seaneagan


If going the static method route, I think it would be more orthogonal to just always return null on invalid input rather than providing an "ifInvalid" parameter.

In any case, the solution should be consistent with issue #2870.

@floitschG
Copy link
Contributor

We are pretty happy with the current solution:
int int.parse(String source, {int radix, int onError(String source)})
double double.parse(String source, { double onError(String source)})

Still missing num.parse and I will open another bug for that: issue #8237.


Added Fixed label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jan 31, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
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. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants