Dart code instrumentation possible? - dart

I know that Dart's VM is a "language VM" as opposed to a bytecode VM. Is there a way to do the equivalent of bytecode instrumentation on Dart code?

As far as I remember there was a similar question somewhere recently (Dart Google groups) in relation to profiling and the answer was no.
You can do code generation like Angular/DI does it to replace dynamic injection with static injection (Polymer transformer does something along this lines).
But that is only possible before the program is started.

Related

Why does flutter use dart?

I understand that there could be many reasons but when the developer community has already adopted ES6 and is working hard to make it better then why dart and not JS?
Is there anything special which makes dart such a good fit for Flutter?
That's an FAQ and already answered extensively
https://flutter.io/faq/#why-did-flutter-choose-to-use-dart
https://hackernoon.com/why-flutter-uses-dart-dd635a054ebf
I'm not sure why you wrote ES6 and "dart js".
Flutter has nothing to do with JavaScript.
While Dart can be compiled to JavaScript, Flutter doesn't use this feature.
For Flutter Dart is compiled to native binary code.
I did a little research after being asked the question by a couple of colleagues and thought it would help by summarising what I have read and thought about (it's a very important question for my colleagues)
Language requirements for Flutter
AOT and JIT compilation for fast reload and fast released code
A good garbage collector to clean up after creating and destroying many objects
Single threaded to avoid locks and therefore jank
An arm compiler to avoid having another engine running the code on the device (aka React Native)
Dart meets all these requirements. JS (I think) meets all the above pretty closely too, apart from the AOT and JIT compiler part.
Why didn't Flutter choose JS and build a JIT and AOT compiler? (initially they did choose JS but they switched) I could guess at the following...
Dart was built with to-binary compilation in mind from the beginning
Dart already had a to-binary JIT compiler, it added the AOT compiler later
Dart is more structured and simpler (it is type safe and has no eval)
JS could implement new language features that might jeopardise flutter dev
Dart can be optimized for Flutter without needing to worry about other uses of JS
Historically long wait times for new JS functionality (last 3 years has been better)
The Dart and Flutter teams can work together closely
Saying all of that I can imagine that a JS solution could happen but it might be costly and a more complicated solution. Dart is pretty good and Dart2 has really improved things with inherent type safety.
Dart has a declarative and programmable layout that is easy to read and visualize. Hence, Flutter doesn't require a separate declarative layout language like XML. It is easy for Flutter to provide advanced tooling since all the layout in one language and in a central place
Dart is much faster than JavaScript, as it can be compiled both AOT and JIT which helps building apps in several ways as using JIT compilation can speed up development and AOT compilation can be used during the release process for better optimization. This technique has been used in Flutter.
follow the link
https://medium.com/hackernoon/why-flutter-uses-dart-dd635a054ebf
https://insights.daffodilsw.com/blog/why-flutter-uses-dart

UCD equivalent for Groovy/Grails?

In Java projects I use UCD for cleaning dead/unnecessary code, and I love it.
Is there an equivalent in Groovy/Grails land?
Given the highly dynamic nature of Groovy it would be very difficult (if at all possible) to do something similar to this.
I haven't seen any tools that are capable of what you are looking for and I doubt any exist for the reasons above.
The codenarc project (Static Analysis for Groovy) has some rules to detect unused and unnecessary code.

How do I use LevelDB from Dart?

I'm looking into Dart for server-side development and one of the things I'd need to use if I went that direction was LevelDB. There is a port for the JVM that I could use from Java or Groovy but I haven't been able to find anything in Google that points me to a leveldb package for Dart.
I know it's possible to write a native port that uses the C++ API but I'm neither a C++ nor a Dart programmer so while that's theoretically possible, it's out of the question for me personally.
Since LevelDB and Dart are both Google initiatives, surely there's integration somewhere isn't there?
I have written a LevelDB binding for Dart at https://pub.dartlang.org/packages/leveldb. Please try it out and file bugs for any issues you see.
To use LevelDB, which is written in C, you'll need to use the Dart VM's native extensions API. At the time of this writing, there is no open source binding for LevelDB and Dart VM.
Thanks for the question!

Dart: Possible to exchange source code on the fly in a running system?

In this article it says: "The Dart VM reads and executes source code, which means there is no compile step between edit and run.". Does that mean that you can exchange source-code on the fly in a running Dart system like in Erlang? Maybe the compiler is removed from the runtime system and then this is no longer possible. So that's why I'm asking.
Dart is run "natively" only in Dartium, which is a flavour of Chrome with DartVM. When you develop an application you still need to compile it it to JavaScript. This way you get fast development lifecycle and in the end you can compile code to JS. Because it's compiled code there is lots more room for compiler to run optimisations on the code. So from my perspective, the compiler is still there and I don't think you would be able to replace code at runtime.
You can send around source code and run it, but it would need to be in a separate isolate. Isolates do have some relationship to Erlang concepts.
The Dart VM doesn't support hot swapping (Called live edit in V8). However, based on mailing list discussions, it sounds like this is something that the authors do want to support in the future.
However, as the others have mentioned, it is possible to dynamically load code into another isolate.

What tools are built using themselves? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am curious about what tools are used to build the next version of themselves.
For example, Delphi has long claimed that "Delphi is written in Delphi".
I assume Visual Studio is written using Visual Studio.
What are some other examples of tools that written in themselves?
Interestingly, the VB.NET & C# compilers themselves are written in unmanaged C++ (leading to the C++ team's T-Shirt: "My compiler compiled yours"). The C# team hopes to have a fully managed-C# hosted C# compiler for VS2010.
Bjarne Stroustrup mentioned in The Design and Evolution of C++ that the first C++ compiler was written in C++.
I've just noticed this is also a question in his FAQ:
The first C++ compiler (Cfront) was
written in C++. To build that, I first
used C to write a "C with
Classes"-to-C preprocessor. "C with
Classes" was a C dialect that became
the immediate ancestor to C++. That
preprocessor translated "C with
Classes" constructs (such as classes
and constructors) into C. It was a
traditional preprocessor that didn't
understand all of the language, left
most of the type checking for the C
compiler to do, and translated
individual constructs without complete
knowledge. I then wrote the first
version of Cfront in "C with Classes".
This is off-topic, but strictly speaking, it is an example of a tool which builds itself.
The reprap - an open-source 3d prototyping machine, which recently gave 'birth' to "its first complete working replicated copy".
I love this kind of stuff.
Generically speaking, C compilers are usually written in C... *nix kernels are compiled on *nix, etc.
Also, there's the pypy project which provides a Python interpreter written in Python.
When gcc (the Gnu C compiler http://gcc.gnu.org/) was not available widely, you had to compile it from source, compiling stage1 compiler, then compile stage2 with stage1, till you have your final compiler. I assume it must be the same today.
Here is another example: Mono's C# compiler is self hosting - i.e. it's written in C# and used to compile itself.
Dog fooding refers to the more general practice of a company using its own product internally, especially during its development.
Lots of folks like to look at how Lisp can be implemented in Lisp.
Squeak is a Smalltalk-80 implementation written in itself.
even its virtual machine is written entirely in Smalltalk making it easy to debug, analyze, and change.
Sun's Java compiler has long been written in Java. However, recent work is writing a JIT compiler in Java as well. This is the JVM component that converts Java byte code to native processor instructions.
We use to develop using RealBasic. The IDE is written in itself, or so I've been lead to believe.
ghc, the Haskell compiler, is mostly written in Haskell.
tcc is another self-hosting C compiler for x86 and ARM. Its claim to fame is being, well, tiny (100k or so for preprocessor, compiler, assembler, and linker).
I would assume that pretty much any tool that's part of the typical development process would be involved in its own development, to whatever extent possible. This includes:
certain programming languages, especially compiled ones
IDEs
text editors
version control systems
bug trackers
build systems
If you're on a team building one of these tools, and you're not developing it for a specific niche that doesn't apply to your team, I don't know why you wouldn't use it to build itself. Having developers be users of the product is one of the best ways to find possible improvements.
For the AmigaOS there was a third party Basic interpreter (don't remember the name) for which you could later buy a compiler. The compiler was delivered as source, so you had to use the interpreter to run the compiler to compile itself...
To cite Kent Beck:
...it may seem a bit like performing brain surgery on yourself.
Visual Studio and Team Foundation Server build themselves. It's called dogfooding, a term which if not originating in Microsoft, it certainly likes
Oracle Application Express is a web application development tool that is built in itself.
Eclipse IDE is generally built and developed using Eclipse IDE.
It is fairly typical to have a languages compiler written in its own language. This is called self-hosting or bootstrapping.
Maven2 is built using Maven2.
Ok, it's not built (i.e. written) using itself, as it is a tool to build (i.e. compile) project, but it is using its own code to compile...
I was amazed with JSLint
In short it has been described as Javascript "compiler" using javascript.
I am building an IDE-based code generator, and I am using it to build itself. If fact, as Stroustrup did, I am first building a valid generator model and using a pre-processor to build the final C++ code to compile. Once I have a good working version of the IDE, I'll start using it to build further versions of itself.
It's like giving a new dimension to the meaning of "recursive programming"!
AFAIK does the OpenJDK build itself first with the installed java and afterwards with itself.
Naturally the Jetbrains team uses its own IDE IntelliJ IDEA to develop this IDE.
I assume this is true for most IDE vendors.
As far as I know, when building EMACS from source, all of the ELISP code is bootstrapped. I found that quite noteworthy.
Not quite what you're asking for, but the entire development environment for Revolution http://www.runrev.com is built using Revolution itself, and the source (except for small parts that enforce the license) is completely exposed in source form. So if you don't like the way the dev environment is implemented, you can change it. Find a bug, fix it. You can also easily build additional development tools and integrate them.
Ada and Forth
I gave the Smalltalk-80 answer an uptick. Best, most elegant example I can think of. The question also reminds me of a slightly related problem that used to be popular: write a program that outputs itself. Not the same level of bootstrapping, but a fun little programming puzzle for your amusement. Maybe not possible in all languages?
The old Watcom C/C++ compiler was built using itself.
Kragen Sitaker's Ur-Scheme is a fine example of a small nontrivial compiler written in itself. That page links to several more good sources in that vein.

Resources