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

language: conditional metadata, compile-time constants, #ifdef, etc #7238

Closed
kevmoo opened this issue Dec 10, 2012 · 8 comments
Closed

language: conditional metadata, compile-time constants, #ifdef, etc #7238

kevmoo opened this issue Dec 10, 2012 · 8 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). 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

@kevmoo
Copy link
Member

kevmoo commented Dec 10, 2012

I'm sure this has been requested, but I couldn't find any related bug.

assert is great, but I want more.

I'd love to add diagnostic logging and other features to my Retained/Canvas library, but I'd also like to eliminate runtime costs in the general case.

I could certainly have a static, top-level 'enableDebug' field and a bunch of runtime checks all over my code to see if it's set.

The closure compiler/tools support goog.DEBUG and the ability to strip out members by enclosing them in if(goog.DEBUG) { ... }

I prefer the approach in C#/.NET

define/#ifdef

Great for stripping out sections of code or having a 'paranoid' and 'fast' section of code depending on the context.

[Conditional('DEBUG')] metadata on void methods is also very helpful and would allow easy definitions of alternate assert-like statements.

I've created and used a number of requireArgument... methods in my libraries. It'd be nice to turn all of these off in production (or after setting a compiler flag).

@sethladd
Copy link
Contributor

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

@gbracha
Copy link
Contributor

gbracha commented Aug 25, 2014

Conditional expressions are constant if there subexpressions are constant. This addresses the metadata scenario.

Conditional asserts are a bit different, since an assert is never constant. I'd argue that a good implementation will reduce thing like DEBUG? assert(predicate : null; to nothing if DEBUG is false.

The same holds for whole blocks of code within if statements. All of which is similar to some of the alternatives you mention. It seems to come down to "i'm used to C# and I want it that way'.
So I'm closing this bug.


Added WontFix label.

@kevmoo kevmoo added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 25, 2014
@kevmoo kevmoo added 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 and removed resolution-wont_fix labels Mar 1, 2016
@rrousselGit
Copy link

We should reopen this.
With Flutter we have both IOS/Android as target.

The problem is doing as followed:

if (platform === TargetPlaform.android) {
  return RaisedButton(...)
}
else {
  return CupertinoButton(...)
}

will not work with tree shaking.

@zoechi
Copy link
Contributor

zoechi commented Oct 15, 2018

You can use -t to run different lib/main_xxx.dart files like shown in https://stackoverflow.com/a/47438620/217408.
This should work well with tree-shaking.

@rrousselGit
Copy link

Yeah that's what I do.

But it causes frustration for many others. https://medium.com/flutter-io/do-flutter-apps-dream-of-platform-aware-widgets-7d7ed7b4624d

@zoechi
Copy link
Contributor

zoechi commented Oct 15, 2018

I quickly skimmed though the doc but couldn't see anything about frustration.
Would you mind copying a citation?

@rrousselGit
Copy link

rrousselGit commented Oct 15, 2018

In the comments there's a

Yup, agree with you guys, I feel flutter can only succeed if we don’t have to write platform specific widgets since it then requires you to study both material design guidelines and iOS ones thoroughly.

This is also an argument regularly used against flutter coming from RN Developers.

I am preparing a medium article on the -t part.

But I still think this issue would make things easier


Overlall, the simple fact that this article got 1k6 claps when it actually breaks tree shaking reveals that the community is looking for a solution.

@zoechi
Copy link
Contributor

zoechi commented Oct 15, 2018

I'm not against it and it's not my call anyway.
I just tried to get at the core of what this is required for or what it would make more convenient.
Your last comment should make that clear.
I don't know if Dart team members monitor comments on closed issues.
Perhaps it's better to create a new issue with the new motivation and perhaps a link to this issue.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). 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

5 participants