Code Monkey home page Code Monkey logo

python-automata-based-programming-paradigm's Introduction

Python Automata-Based Programming Paradigm

Short introduction to the project

Presenting my Python programming paradigm with which we can separate the application into several parts:

  • Behaviour
  • Execution
  • MainLoop

Many of the people reading this might think: "Hey, but MainLoop is the behaviour and execution as well" and you would be right. However, do allow me to elaborate on this. My reasoning is that everything should be simplified if it can be.

The goal here is actually to define some behaviour parts of your program in easy to read graphs and only write the execution parts in the code. This way you can concentrate on writing code for your main loop only.

Naturally, everything is better when there is an example with it to explain it even more so I recommend you check the examples in the repository first.

You can install the module via Pypi with

pip install automatabpp

A short explanation of the project

To really simplify what this is all about in one sentence: "Instead of programming the code yourself you draw graphs to define the behaviour."

These graphs are loaded when first executing your code and are automatically connected to their execution part.

Each graph is called a machine, and each execution is called a state. (Yes, there can be several machines working consecutively at the same time)

To get a better idea of what's going on here's a quick example. Using a yEd Graph Editor Create a .graphml graph like this one and store it in the graphs/ folder of your project as first.graphml .

Run the next code: (don't forget to clone the repository into your project folder)

import automatabpp as FSM

FSM.BEHAVIOUR.load_behaviour_from_graph("first.graphml", "My First Finite State Machine")

@FSM.EXECUTION.state
def ON_START(*args, **kwargs):
    print("FSM start")

@FSM.EXECUTION.state
def HELLO(*args, **kwargs):
    print("Hello!")

FSM.OPERATION.start()                   # prints "FSM start"
FSM.OPERATION.run("is_anyone_there")    # prints "Hello!"

To learn more please check the examples at the bottom of the page.


Why a paradigm and not a pattern?

While developing this project I ran into this quote on wikipedia. To quote:

"Automata-based programming is a programming paradigm in which the program or part of it is thought of as a model of a finite state machine (automatabpp) or any other (often more complicated) formal automaton."

There is also a definition on programming paradigm that I found fitting this project perfectly.

"A programming paradigm is a style, or โ€œway,โ€ of programming."

Indeed, there is more than enough style in developing this way once you learn how to do it.

How does this differ from ... ?

There are countless ways to develop your program and this one is just one take on it. However I do feel there are some advantages to using the Automata-Based programming over some other approach.

  • Explanation of the code can be easily visualized since most of the code is done by drawing graphs
  • If the machines are well defined the execution and the main loop can be really simple
  • It's fun (if you consider drawing FSMs to be fun)

I'll also leave these two quotes here:

"Programs must be written for people to read, and only incidentally for machines to execute." - Abelson & Sussman

"Typing is no substitute for thinking." - Richard W. Hamming

What other software do I need ?

I would recommend you download the yEd Graph Editor from their official homepage. This project can only import .graphml graphs at the moment. However I do plan on adding code to import more formats in the future.

yEd Graph Editor is used for viewing and drawing our state machine graphs. We consider nodes of the graph to be the states and the edges to be the transitions.

I also recommend using Python 3.4+ although I haven't even tried it yet on the older versions. This project uses logging and xml Python modules so install them if needed.

Directories

  • automatabpp - our module source code. This directory contains the python code for this project.
  • docs - I've really took my time to write all of this so I would appreciate you checking it out
  • graphs - yEd graphs are stored in this directory by default

Additional Links

Here are some other .md links for You to read about this project.

  • A list of available functions
  • Tutorial - make a "Hello, World!" type of application (sort of). Also some more insight on what happens in the code itself.
  • Example 1 - a simple e-mail validation machine
  • Example 2 - an example for developing with multiple machines
  • Example 3 - an example showcasing Base64 encode with this paradigm
  • Example 4 - developing your embedded application with complex behaviour
  • Other

python-automata-based-programming-paradigm's People

Contributors

grgomariani avatar grimar2008 avatar msarcev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-automata-based-programming-paradigm's Issues

Differences between the latest version and the pypi version

The version for pypi was compiled from the commit on June 2, 2019. After that, on June 23, 2019, changes were made to the names of methods, etc. (for example, in the documentation of the OPERATION class, the functions are called run, start, etc., and in the release version run_fsm, start_fsm, etc.) That is, examples and documentation from github turned out to be non-working. Please rebuild the release version and update it in pypi.

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.