Giter VIP home page Giter VIP logo

haxedci's People

Contributors

ciscoheat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tomhoenderdos

haxedci's Issues

cant compile haxedci-example and snakeDCI

I always get:

/usr/lib/haxe/lib/haxedci/git/haxedci/Dci.hx:335: characters 18-22 : haxe.macro.TypePath should be Array<haxe.macro.TypePath>
/usr/lib/haxe/lib/haxedci/git/haxedci/Dci.hx:335: characters 18-22 : { ?sub : Null<String>, ?params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String } should be Array<haxe.macro.TypePath>
/usr/lib/haxe/lib/haxedci/git/haxedci/Dci.hx:335: characters 18-22 : For function argument 'p'
/usr/lib/haxe/lib/haxedci/git/haxedci/Context.hx:3: characters 2-11 : Build failure

Is it error in library or Is it something wrong with my configuration? :)

Contract fields shadows local vars

@role var PLAYER {
  var x : Int;
  var y : Int;

  function moveTo(x, y) {
    SELF.x = x;
    SELF.y = y;
  }

This will not work because x and y in moveTo will incorrectly refer to SELF.x/y. The temp fix is to rename the local vars to something else than the contract fields.

The implementation of DCI without using macro-programming

The way, you provide an environment for DCI, is nice and self-explanatory. The only tough thing is IDE support -- it's often the problem, when using Haxe macros.

Here is the implementation of DCI using standard Haxe syntax (without macros):

package;

class Main {
    static public function main() {
        var acc1 = new AccountContext([]);

        acc1.deposit(10);
        acc1.deposit(15.5);
        acc1.withdraw(7);

        var acc2 = new AccountContext([]);

        var moneyTransfer = new MoneyTransferContext(acc1, acc2);
        moneyTransfer.transfer(8.5);

        trace(acc1.getBalance());
        trace(acc2.getBalance());

        var accountMock = {
            deposit: function(amount: Float) {
                trace("Mocking");
            }
        };

        var moneyTransfer2 = new MoneyTransferContext(acc1, accountMock);
        moneyTransfer2.transfer(5);
    }
}

//
// AccountingEntry.hx

class AccountingEntry {
    public function new() {}

    public var amount(default, default) : Float;
    public var message(default, default) : String;
}

//
// AccountContext.hx

class AccountContext {
    var bookKeeper: BookKeeper;

    public function new(entries) {
        this.bookKeeper = entries;
    }

    public function getBalance() : Float {
        return bookKeeper.getBalance();
    }

    public function deposit(amount : Float) {
        trace("Depositing");
        bookKeeper.addEntry("Depositing", amount);
    }

    public function withdraw(amount : Float) {
        bookKeeper.addEntry("Withdrawing", -amount);
    }
}

abstract BookKeeper(Array<AccountingEntry>) from Array<AccountingEntry> {

    public function getBalance() : Float {
        return Lambda.fold(this, function(a, b) { return a.amount + b; }, 0.0);
    }

    public function addEntry(message : String, amount : Float) {
        var entry = new AccountingEntry();
        entry.amount = amount;
        entry.message = message;

        this.push(entry);
    }
}

//
// MoneyTransferContext.hx

class MoneyTransferContext {
    var sourceAccount : SourceAccount;
    var destinationAccount : DestinationAccount;

    public function new(source : SourceAccountActor, destination : DestinationAccountActor) {
        this.sourceAccount = source;
        this.destinationAccount = destination;
    }

    public function transfer(amount : Float) {
        sourceAccount.transferTo(destinationAccount, amount);
    }
}

typedef SourceAccountActor = {
    function getBalance() : Float;
    function withdraw(amount: Float) : Void;
}

typedef DestinationAccountActor = {
    function deposit(amount: Float) : Void;
}

abstract SourceAccount(SourceAccountActor) from SourceAccountActor {
    public function transferTo(destinationAccount : DestinationAccount, amount : Float) {
        if (this.getBalance() < amount) {
            throw "Insufficient funds";
        }

        this.withdraw(amount);
        destinationAccount.deposit(amount);
    }
}

@:forward(deposit)
abstract DestinationAccount(DestinationAccountActor) from DestinationAccountActor
{ }

Main advantage: built-in Haxe support
Main disadvantages: lacks DCI-specific language (which is provided by your macros library)

Do you agree? How you compare these two approaches? I'm very eager to get your answers and thoughts.

Allow final contract fields without warning.

Currently a compiler warning is issued when accessing a (public) contract field outside its Role. An exception should be made for final and var(default, never), since they cannot be modified.

Autocompletion problem in Rolemethods

In display mode, there is some problem with displaying all roleMethods.

All methods in a role are transformed to a field on the class called ${role.name}__${field.name}, but autocompletion stops at the method where the display expression is.

A solution is to save the current structure to disk, and let autocompletion read and display that instead, but I'd like to be sure I'm not missing anything before doing that.

@back2dos do you have some clever idea how to solve this?

class MyContext implements dci.Context {
    // ... partial code...
    @role var source : {
        function decreaseBalance(a : Int) : Void;

        function addSource() : Void {
            source.| // withdraw is not displayed here, because it's below addSource.
        }

        function withdraw() {
            self.decreaseBalance(Std.int(amount / 2));
            destination.deposit();
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.