Code Monkey home page Code Monkey logo

sproutcore-statecharts-usecase's Introduction

Usecase for Statecharts in SproutCore

This project includes the same SproutCore 2 application in two versions:

  1. Without a statechart but with mediating and coordinating controllers
  2. With a statechart that replaces the coordinating responsibilities form the controllers

The application is complex enough to get in trouble with a bunch of coordination controllers but simple enough to understand in a few minutes.

For a high level view you can see the statechart diagram in 'pomodoro-timer-statechart.png'

Soft results of this Experiment

The goal was to show the difference in maintainability of the two resulting codebases.

Of course it doesn't make too much sense to speak of hard maintainability for such a simple application but this can quickly become a problem if the application grows and complexity rises.

Here are some thoughts and soft results:

  • Without the statechart you have to introduce variables that indicate the current state of the coordinating controllers. All actions must be handled in context of these states to provide reliable application logic. This results in many if blocks and checks which make the code harder to read and understand.

  • Concurrent states and transitions (startPomodoro / finishedPause) are much harder to implement without statechart since you have to introduce dependencies between the coordinating controllers.

  • Nested states and actions that can happen on the parent state (cancelPomodoro on Timer.Pomodoro state) result in if/else if blocks for each child state.

Hard facts and numbers

Of course these differences can not only be described with 'blabla' but also with concrete measures. jsmeter was used to measure the two complete javascript code bases and here are the results:

Without Statechart

  • Lines of Code: 593
  • Statements: 426
  • complexity (lower = better): 2.0344827586206895
  • Maintainability Index (higher = better): 125.21396551724136

With Statechart

  • Lines of Code: 647
  • Statements: 422
  • complexity (lower = better): 1.3541666666666667
  • Maintainability Index (higher = better): 136.90510416666666

The results show that statecharts add more lines of code but lower complexity and improve the overall maintainability of the code base.

sproutcore-statecharts-usecase's People

Contributors

mlcohen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.