Saturday, October 27, 2012

M1 Dart Editor First Use

‹prev | My Chain | next›

A number of folks have suggested that I try the Dart Editor for the kind of refactoring that I have been doing. Indeed, it seems that are a number of automations in the editor for instant fixes for what has taken me a couple of days so far.

In all honesty, I prefer finding the bugs the hard way as I find it easier to internalize the changes and problems. Checking a box and pressing a button does not usually aid in a deep undestanding. But now that I believe that I have my Dart Comics sample app, and the underlying Hipster MVC on which it is built, upgraded for the M1 release of Dart, well it could not hurt to see if I missed anything.

After downloading and installing the editor, I fire it up. There does not seem be to an "import project" option, so I chose "Open Folder" instead, choosing the location of my current dart-comics local repository:


That seems to work as the project appears and the tooling gets right to work analyzing the project:


There sure are a lot of red circle-Xs in there. In fact, there are 168 problems and 262 warnings:


I eliminate a bunch of the errors by marking the test directory to not be analyzed and marking the public/packages directory as a package directory in the editor's preferences.

Only I still have hundreds of problems and warnings. Looking closer, some of the problems are things that I just fixed for M1:


Curly braces are the correct syntax for optional, named parameters in M1. I am able to run it in Dartium just fine. But the editor does not recognize it. It's almost as if the editor was old.

The "About Dart" options would seem to indicate that my Dart Editor is, in fact, old:


Build 9822? Just under the link that I used to download the editor, it says that the current version is 13841:


Elsewhere on the Dart Editor page is a link to the bleeding edge editor. I try that.

Only when I start, I get an unholy stacktrace, the very beginning of which is:
➜  ~  ~/local/dart/DartEditor 
!SESSION 2012-10-27 17:53:46.001 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_24
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -os linux -ws gtk -arch x86_64 -consoleLog -data @user.home/.dartEditor

!ENTRY org.eclipse.ui.workbench 4 0 2012-10-27 17:53:48.563
!MESSAGE Unable to create view ID com.google.dart.tools.ui.FileExplorer: Failed to find /home/chris/local/dart-sdk/lib/_internal/libraries.dart.  Is dart-sdk path correct?
!STACK 0
com.google.dart.compiler.InternalCompilerException: Failed to find /home/chris/local/dart-sdk/lib/_internal/libraries.dart.  Is dart-sdk path correct?
 at com.google.dart.compiler.SystemLibrariesReader.getLibrariesFile(SystemLibrariesReader.java:256)
 at com.google.dart.compiler.SystemLibrariesReader.(SystemLibrariesReader.java:191)
 at com.google.dart.compiler.FileBasedSystemLibraryProvider.createReader(FileBasedSystemLibraryProvider.java:39)
...
Since I am an Emacs guy, I normally use the dart-sdk when doing local development work. It seems that the Dart Editor recognizes that I have the dart-sdk installed and it tries to use it. But, my dart-sdk appears to be missing a file that the Dart Editor is trying to find. The result is a big, huge crash.

Fortunately, the solution is simple enough:
➜  ~  mv local/dart-sdk local/dart-sdk.bak
With that, I have a Dart Editor that sports an M1 splash screen.

I again add open my Dart Comics folder. I again mark a few older files as not requiring analysis. I again add the pub folder from Dart Comics as the primary location for pub packages:


That would not be a good idea if I were working on multiple projects, but it will suffice as a temporary setting as I get started.

With all of that, Dart Editor's automatic analysis now identifies 4 problems and 7 warnings:


Much better.

All but one of those errors are in files that are not directly used. I will get around to fixing them eventually, but today, I am only concerned with the warning from Collections.Comics.dart:
Concrete class Comics has unimplemented member(s) 
# From Collection:
  bool isEmpty 
  Collection<dynamic> map((dynamic) -> dynamic)
  Collection<dynamic> filter((dynamic) -> bool) 
  bool contains(dynamic) 
  dynamic reduce(dynamic, (dynamic, dynamic) -> dynamic) 
  bool every((dynamic) -> bool) 
  bool some((dynamic) -> bool)
# From Iterable: 
  Iterator<dynamic> iterator()
It is fairly easy to eliminate this warning—I need to delegate a bunch of the Collection methods in the HipsterCollection class to the underlying list of models:
class HipsterCollection implements Collection {
  // ...
  iterator() => models.iterator();

  bool isEmpty => models.isEmpty;
  map(fn) => models.map(fn);
  filter(fn) => models.filter(fn);
  contains(element) => models.contains(element);
  reduce(intialValue, fn) => models.reduce(initialValue, fn);
  every(fn) => models.every(fn);
  some(fn) => models.some(fn);
  // ..
}
There is not too much typing involved, thanks to the hash-rocket function syntax. Still, I do appreciate Ruby's Enumerable which only requires a each method to be defined.

Aside from the problems with the very-old-editor and the wrong dart-sdk, it was pretty easy to get my old project imported into Dart Editor. It did not find too many problems, which buys a bit of peace of mind. Tomorrow, I will keep working through some of the non-happy path problems and warnings that exist.


Day #552

No comments:

Post a Comment