--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
Agreed, I think with annotations like @devonly we might be able to remove some of the code from the compiled output?It sounds like there are two goals here:1) omit dev-time only code from the shipped product2) generated different versions of the app, based on experiments or otherWe've heard #2 before. Conditionally loading libraries might help here. Not sure how others are thinking of attacking this problem. @Justin?
For #1, the example here might be "remove all logging statements". Do we need something more than annotations here?
On Fri, Mar 8, 2013 at 9:40 AM, Seth Ladd <seth...@google.com> wrote:
Agreed, I think with annotations like @devonly we might be able to remove some of the code from the compiled output?It sounds like there are two goals here:1) omit dev-time only code from the shipped product2) generated different versions of the app, based on experiments or otherWe've heard #2 before. Conditionally loading libraries might help here. Not sure how others are thinking of attacking this problem. @Justin?re #2: I think conditional loading is a good way to approach this, but for large apps with experiments systems, it will probably be important to structure the app in fine-grained and encapsulated enough libraries to be able to swap them out with out wanting conditional compilation within the library. Hopefully many experiments will be possible without even conditional libraries. Minification/obfuscation might be enough to allow experiments based on flags.For #1, the example here might be "remove all logging statements". Do we need something more than annotations here?Annotations currently aren't allowed in all the places needed for this. I don't think they're allowed on statements, for example, which would be required for annotated blocks like:@devonly {onlyInDev();}However we have built experimental systems that allow transformations based on function calls like:devonly(() {onlyInDev();});The nice thing about this is that without the compilation step you can still control whether the code is executed. devonly() would implemented like this:bool dev = true;void devonly(f) {if (dev) f();}And removing the call is an optional optimization. This is an important property I'd like to see maintained with any compilation step, that the compilation is optional and the program still runs correctly without it. It may require a non-production environment, like Dartium, but it'll still run in development without forcing a compiler run, preserving the fast edit-refresh cycle.
See inline below...
On Fri, Mar 8, 2013 at 10:40 AM, Justin Fagnani <justin...@google.com> wrote:
On Fri, Mar 8, 2013 at 9:40 AM, Seth Ladd <seth...@google.com> wrote:
Agreed, I think with annotations like @devonly we might be able to remove some of the code from the compiled output?It sounds like there are two goals here:1) omit dev-time only code from the shipped product2) generated different versions of the app, based on experiments or otherWe've heard #2 before. Conditionally loading libraries might help here. Not sure how others are thinking of attacking this problem. @Justin?re #2: I think conditional loading is a good way to approach this, but for large apps with experiments systems, it will probably be important to structure the app in fine-grained and encapsulated enough libraries to be able to swap them out with out wanting conditional compilation within the library. Hopefully many experiments will be possible without even conditional libraries. Minification/obfuscation might be enough to allow experiments based on flags.For #1, the example here might be "remove all logging statements". Do we need something more than annotations here?Annotations currently aren't allowed in all the places needed for this. I don't think they're allowed on statements, for example, which would be required for annotated blocks like:@devonly {onlyInDev();}However we have built experimental systems that allow transformations based on function calls like:devonly(() {onlyInDev();});The nice thing about this is that without the compilation step you can still control whether the code is executed. devonly() would implemented like this:bool dev = true;void devonly(f) {if (dev) f();}And removing the call is an optional optimization. This is an important property I'd like to see maintained with any compilation step, that the compilation is optional and the program still runs correctly without it. It may require a non-production environment, like Dartium, but it'll still run in development without forcing a compiler run, preserving the fast edit-refresh cycle.Does dart2js (which also powered dart2dart) have the extensibility to let me, the end user, add a plugin and give guidance to remove devonly() from the production output? Asked another way, how far are we from this type of solution?
Why this is not done in the traditional way?With a traditional source code preprocessing.
// Predefined macro#if WEB_CLIENT// Code for client side#else// Code for server side#end#if WEB_CLIENT#error Illegal use of this library in the web client#end
// Macro passed to cmd line args, e.g -dDEVELOPMENT#if DEVELOPMENTconst String mode = 'DEVELOPMENT';#elseconst String mode = 'PRODUCTION';#end
@Ladislav Thon
>> You can run cpp (the C preprocessor) on any file, even a Dart source code. So you can do this
>> today, without any issues.
Again you're kidding?
Andrew,
we all know what pre-processing directives are and what they are used for. No need to quote full passages of encyclopedias at a large!
And I also think that Lasse has cleary described the differences between a language that is truely compiled at build time on
2.5 Pre-processing directives
Visual Studio .NET 2003The pre-processing directives provide the ability to conditionally skip sections of source files, to report error and warning conditions, and to delineate distinct regions of source code. The term "pre-processing directives" is used only for consistency with the C and C++ programming languages. In C#, there is no separate pre-processing step; pre-processing directives are processed as part of the lexical analysis phase.