GithubHelp home page GithubHelp logo

xyuan / lager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arximboldi/lager

0.0 1.0 0.0 984 KB

C++ library for value-oriented design using the unidirectional data-flow architecture (Redux for C++)

Home Page: https://sinusoid.es/lager/

License: MIT License

C++ 58.50% CMake 2.58% Nix 0.74% Elm 1.10% CSS 0.47% HTML 0.70% Makefile 0.02% Python 0.11% JavaScript 34.97% Emacs Lisp 0.02% QML 0.72% Starlark 0.07%

lager's Introduction

Travis Badge

CodeCov Badge

Sinusoidal Engineering badge

Logotype

lager is a C++ library to assist value-oriented design by implementing the unidirectional data-flow architecture. It is heavily inspired by Elm and Redux, and enables composable designs by promoting the use of simple value types and testable application logic via pure functions. And you get time-travel for free!

  • Documentation (Contents)
  • Code (GitHub)
  • CppCon 2018 Talk: The most valuable values (YouTube, Slides)
  • C++ on Sea 2019 Talk: Postmodern immutable data-structures (YouTube, Slides)

    This project is part of a long-term vision helping interactive and concurrent C++ programs become easier to write. Help this project's long term sustainability by becoming a patron or buying a sponsorship package: [email protected]

Examples

For a guided introductory tour with code samples, please read the architecture overview section. Other examples:

  • Counter, a minimalistic example with multiple UIs (link).
  • Autopong, a basic game using SDL2 (link).
  • Ewig, a terminal text editor with undo, asynchronous loading, and more (link).

Why?

Most interactive software of the last few decades has been written using an object-oriented interpretation of the Model View Controller design. This architecture provides nice separation of concerns, allowing the core application logic to be separate from the UI, and a good sense of modularity. However, its reliance on stateful object graphs makes the software hard to test or parallelize. It's reliance on fine-grained callbacks makes composition hard, resulting in subtle problems that are hard to debug.

Value-based unidirectional data-flow tackles a few of these problems:

  • Thanks to immutability and value-types, it is very easy to add concurrency as threads can operate on their local copies of the data without mutexes or other flaky synchronization mechanisms. Instead, worker threads communicate their results back by dispatching actions to the main thread.
  • The application logic is made of pure functions that can be easily tested and are fully reproducible. They interact with the world via special side-effects procedures loosely coupled to the services they need via dependency injection.
  • This also means that data and call-graphs are always trees or DAGs (instead of cyclical graphs), with explicit composition that is to trace and debug. You can also always snapshot the state, making undo and time-travel easy peasy!

Dependencies

This library is written in C++17 and a compliant compiler and standard library necessary. It is continuously tested with GCC 7, but it might work with other compilers and versions.

It also depends on Boost Hana. Some optional extensions and modules may have other dependencies documented in their respective sections.

Usage

This is a header only library but to be configured correctly you need to run CMake first:

mkdir -p build && cd build
cmake .. -D lager_BUILD_DEBUGGER=OFF -D lager_BUILD_TESTS=OFF -D lager_BUILD_EXAMPLES=OFF -D lager_BUILD_DOCS=OFF

Now you can just copy the lager subfolder somewhere in your include path.

Some components, like the time-travelling debugger, also require the installation of extra files.

You can use CMake to install the library in your system once you have manually cloned the repository:

mkdir -p build && cd build
cmake .. && sudo make install

Development

In order to develop the library, you will need to compile and run the examples, tests and benchmarks. These require some additional tools. The easiest way to install them is by using the Nix package manager. At the root of the repository just type:

nix-shell

This will download all required dependencies and create an isolated environment in which you can use these dependencies, without polluting your system.

Then you can proceed to generate a development project using CMake:

mkdir build && cd build
cmake ..

From then on, one may build and run all tests by doing:

make check

License

Boost logo

This software is licensed under the MIT license.

The full text of the license is can be accessed via this link and is also included in the LICENSE file of this software package.

lager's People

Contributors

arximboldi avatar ltjax avatar cjbussey avatar xzorit avatar craigscott-crascit avatar nyanpasu64 avatar kamibo avatar waybeforenow 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.