Declarative vs. Fluent syntax.

As of the 0.19.0 release, Cylon supports two syntaxes for creating Robots.

Our existing declarative syntax is still supported, but there's also a new, more fluent sytax. We hope this will be helpful to developers more familiar with libraries like jQuery, and make it easier for them to build cool and useful robots with Cylon.

Comparison

Here's a sample program, using each of the syntax variations. It's up to you to decide which style you prefer.

Declarative

The declarative syntax is preferred for Cylon. It tends to be more concise then the fluent syntax, and is suited to describing what a robot will do.

var Cylon = require('cylon');

Cylon.robot({
  name: "TestBot",

  connections: {
    sphero: { adaptor: 'sphero', port: '/dev/rfcomm0' }
  },

  devices: {
    sphero: { driver: 'sphero' }
  },

  roll: function() {
    console.log("Rolling!");
    this.sphero.roll(60, Math.floor(Math.random() * 360));
  }

  work: function(my) {
    every((1).second(), function() {
      my.roll();
    });
  }
}).start();

Fluent

Users of other fluent JavaScript interfaces, such as jQuery or similar libraries, might be more familiar with this style of syntax:

var Cylon = require('cylon');

Cylon
  .robot({ name: 'TestBot' })
  .connection('sphero', { adaptor: 'sphero', port: '/dev/rfcomm0' })
  .device('sphero', { driver: 'sphero' })
  .on('error', console.log)
  .on('ready', function(bot) {
    setInterval(function() {
      console.log("Rolling!");
      bot.sphero.roll(60, Math.floor(Math.random() * 360));
    }, 1000);
  });

Cylon.start();