Navigation Menu

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

Provide a Method to Dynamicaly Load Classes #3819

Closed
DartBot opened this issue Jun 21, 2012 · 11 comments
Closed

Provide a Method to Dynamicaly Load Classes #3819

DartBot opened this issue Jun 21, 2012 · 11 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Milestone

Comments

@DartBot
Copy link

DartBot commented Jun 21, 2012

This issue was originally filed by kevincox....@gmail.com


This was originality posed as a question on stack overflow http://stackoverflow.com/questions/11128476/how-can-i-lasily-dynamicaly-load-classes-in-dart/11128713

A quick summary is that it would be useful to provide a method for dynamically loading classes so that you did not have the up-front loading cost and to prevent the cost if you don't use those sections at all.

@sethladd
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.
Changed the title to: "Provide a Method to Dynamicaly Load Classes".

@DartBot
Copy link
Author

DartBot commented Jun 26, 2012

This comment was originally written by dhasenan@gmail.com


Additionally for cases where you don't know the classes you need when you're writing the code -- for instance, a plugin system for an application, or third-party database drivers for a generic database layer (like JDBC, not that I'm suggesting that as a model for your application), or a test framework driver, or a reflection-based static analysis tool...

There's a question of what you want to get back when you ask to include something at runtime. Probably some reflection object, so you can find what interests you.

@DartBot
Copy link
Author

DartBot commented Jun 26, 2012

This comment was originally written by kevincox...@gmail.com


That would be even better.

@gbracha
Copy link
Contributor

gbracha commented Jun 26, 2012

We are looking at these issues.


Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Sep 1, 2012

This comment was originally written by thesain...@gmail.com


I also want to add an important use case. Since next-gen web apps are expected to deliver desktop-like experience, probably the most important aspect are plugins. Imagine a Web-3D engine, which is definitely one of the many amazing things Dart is best suited for on paper. Almost any engine out there, and for good reasons, doesn't require you to recompile the entire beast just to add behaviour to your assets. Instead they let you hotplug scripts into the game, which could be done through a code editor in a web-page. Of course one could build a script system statically on top of Dart but let's be realistic... JavaScript is slow as it is, no need for an interpreted scripting environment on top of that. So it it really important that users can write their own scripts in Dart, and then my app maybe uses Frog to compile it to JavaScript, and now some shiny new mechanism, to instanciate the user's class.

From a language perspective Dart should be more than capable, in constrast to JavaScript, to provide a stable plugin-mechanism, since runtime code changes are not permittet.

@gbracha
Copy link
Contributor

gbracha commented Nov 6, 2012

We are well aware of this issue and intend to provide a workable answer. I'm marking this M3 tentatively.


Set owner to @gbracha.
Added this to the M3 milestone.

@gbracha
Copy link
Contributor

gbracha commented Nov 6, 2012

Issue #4307 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Nov 7, 2012

This comment was originally written by daniel.sch...@gmail.com


Use isolates, mirrors and primitive remote method call serialization as workaround to dynamically load dart scripts into the vm. See a proof-of-concept at (plugin system): https://github.com/danschubert/dart-plugin-isolate

@DartBot
Copy link
Author

DartBot commented Jan 2, 2013

This comment was originally written by @seaneagan


My use case is dynamically loading code which is dependent upon the user's locale.

In particular the CLDR plural rules (http://unicode.org/reports/tr35/#Language_Plural_Rules) are naturally represented as Dart code. Otherwise one would need to include a plural rules parser on the client (bloating the code), and the AST returned from the parser would need to be traversed each time a plural category operation is invoked (too slow). In http://pub.dartlang.org/packages/intlx I generate Dart code for each locale, but as of now the generated code has to be loaded statically at compile time, so in order to support multiple locales in their application, one has to generate a different entry point for their app for each locale, and then load the correct entry point at runtime based on the detected user locale such as via the HTTP Accept-Language header. That works in many cases, but in other cases it would be more convenient to have a single entry point, and load the locale-specific code dynamically after the user's locale is detected.

Isolates don't work because I want to call the dynamic code synchronously.

@anders-sandholm
Copy link
Contributor

Removed this from the M3 milestone.
Added this to the M4 milestone.

@gbracha
Copy link
Contributor

gbracha commented Mar 19, 2013

The comments above cover various use cases. The initial one is deferred loading, to avoid massive downloads when some code is needed only later, or perhaps only needed in some situations. We now have a mechanism for this.

There was also a request for more general form of dynamic loading, where the code being loaded is not known statically. This will require the ability advanced capabilities like mirror builders. This should be a separate issue.

This bug was originally for deferred loading, and that has been addressed.


Added Done label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Mar 19, 2013
@DartBot DartBot added this to the M4 milestone Mar 19, 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-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants