fkling / JSNetworkX

Build, process and analyze graphs in JavaScript (port of NetworkX)
https://felix-kling.de/jsnetworkx/
Other
761 stars 184 forks source link

Info: Development progress #25

Closed fkling closed 9 years ago

fkling commented 10 years ago

I'm going to use this new issue as a way to document my progress of refactoring the code. I'm also happy to receive comments and suggestions.

(this is an experiment, I'm not sure if I'm disciplined enough to keep this up, but I will try my best :) )

fkling commented 10 years ago

(July 1, 2014)

I didn't make much progress on the code base itself last week, but spent some time to improve the tools used to build and test the code. So here it goes:

Deep equality testing

It turns out that there are many deep equality implementations but they all produce slightly different results. Especially, none of them provided the functionality I was looking for. Most libraries consider these two arrays as deep equal:

var a = {x:42};
var b = {x:42};
var array1 = [a, a];
var array2 = [a, b];
deepEqual(array, array2); // true

However, as you can see, array1 contains two reference to the same object, while array2 contains references to different objects. If both arrays where mutated in the same way, e.g. arrayX[0].x = 21;, you would get two different results (even though they are supposed to be equal)/

So built deep-equal-ident which is a very thin wrapper around lodash's _.isEqual function. It comes with a chai.js extension so that it can be easily used in unit tests.

Additional I made chai-members-deep which just adds some convince methods for deep equality testing in sets.

ES6 class transforms and generators

The upcoming changes in ES6 let you write so much cleaner code. Take the class syntax for example. Instead of

function Foo() {
  this.title = 42;
}

Function.prototype.doSomehing = function() {
    // something
};

you can write

class Foo {
  constructor() {
     this.title = 42;
  }

  doSomething() {
    // something
  }
}

Generators are particular useful in JSNetworkX, since many of the original Python functions are actually generators.

The good thing is that we can use the new syntax today because people have built transpilers to convert the new syntax to ES5 compatible syntax, Facebook's jstransform and regenerator projects.

Unfortunately jstransform is not feature complete. It didn't allow to use getters and setters in class definitions and "converted" generators to normal functions. I made two pull requests to support this, so that we can use this in JSNetworkX. (I also built an AST explorer in the meantime.)

apitts commented 9 years ago

@fkling just wondering if you were able to make any further progress on the above? I'm thinking about having a go at porting Page Rank and HITS to JSNetworkX fairly soon. Thanks!

fkling commented 9 years ago

@apitts: Yes, I made some progress, however I haven't touched any algorithms yet. I will publish what I have so far on a new branch in one or two days. It's really work in progress, but can give you an idea in which direction it goes.

apitts commented 9 years ago

Thanks very much @fkling! Looking forward to checking it out!

fkling commented 9 years ago

Created a new branch that will contain the latest progress: https://github.com/fkling/JSNetworkX/tree/es6_WIP

apitts commented 9 years ago

Just checked it out - looking good! Certainly a lot easier to follow without the Google Closure Compiler.

fkling commented 9 years ago

v0.3.0 is now released https://github.com/fkling/JSNetworkX/commit/eff7fb17dca9e68646316460665aee6f10627845