Sdk: Dart.next: <Primitive>.fromEnvironment is a total misnomer

Created on 13 Oct 2016  路  7Comments  路  Source: dart-lang/sdk

In my mind, the following would be equivalent:

const String.fromEnvironment('FOO') == Platform.environment['FOO']

It's not though, because the former is a dart -d argument, and the latter is actually an exported environment variable. I realize this is a big breaking API, but maybe we have some planned anyway.

My recommendation is fromDefine.

area-library core-n type-enhancement

Most helpful comment

@lrhn @floitschG Any thought about this for 2.0?

Even just creating an alias and deprecating fromEnvironment would help a lot.

All 7 comments

This is unlikely to change at the current time. We'll consider if it's worth changing for 2.0.

There is always the possibility to add a new short form without breaking any existing uses of the API.

If you'll accept a PR, I'd be happy to add it as an alias for now, i.e.

const factory String.fromDefine = String.fromEnvironment;

And we could mark the other one as deprecated.

If you do this, please let the analyzer team know. We have special handling of the fromEnvironment constructors to support constant expression evaluation and might need to add special handling of the alias (it ought to work without additional support, but we'd need to verify that).

@lrhn Are you OK with the above? If so, I'll send a PR.

I appreciate the idea, but I don't think it's worth it to do this change now, the benefit is there, but it's not that big. There are lots of small things that we can change, but we should also not change too much - as usual, it's a trade-off.

@lrhn @floitschG Any thought about this for 2.0?

Even just creating an alias and deprecating fromEnvironment would help a lot.

Was this page helpful?
0 / 5 - 0 ratings