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
Comments
Removed Type-Defect label. |
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'. Added WontFix label. |
We should reopen this. The problem is doing as followed: if (platform === TargetPlaform.android) {
return RaisedButton(...)
}
else {
return CupertinoButton(...)
} will not work with tree shaking. |
You can use |
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 |
I quickly skimmed though the doc but couldn't see anything about frustration. |
In the comments there's a
This is also an argument regularly used against flutter coming from RN Developers. I am preparing a medium article on the 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. |
I'm not against it and it's not my call anyway. |
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).The text was updated successfully, but these errors were encountered: