|
1 |
| -# Python Automata Based Programming Paradigm |
| 1 | +# Python Automata-Based Programming Paradigm |
| 2 | + |
| 3 | +### Short introduction to the project |
| 4 | + |
| 5 | +Presenting my Python programming paradigm with which we can separate the application into several parts: |
| 6 | + |
| 7 | +- Behaviour |
| 8 | +- Execution |
| 9 | +- MainLoop |
| 10 | + |
| 11 | +Many of the people reading this might think: _"Hey, but MainLoop **is** the behaviour and execution as well"_ and you would be right. |
| 12 | +However, do allow me to elaborate on this. My reasoning is that everything should be simplified if it can be. |
| 13 | + |
| 14 | +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. |
| 15 | +This way you can concentrate on writing code for your main loop only. |
| 16 | + |
| 17 | +Naturally, everything is better when there is an example with it to explain it even more so I recommend you check [the examples](#additional-links) in the repository first. |
| 18 | + |
| 19 | +### A short explanation of the project |
| 20 | + |
| 21 | +To really simplify what this is all about in one sentence: ___"Instead of programming the code yourself you draw graphs to define the behaviour."___ |
| 22 | + |
| 23 | +These graphs are loaded when first executing your code and are _automatically_ connected to their execution part. |
| 24 | + |
| 25 | +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) |
| 26 | + |
| 27 | +To get a better idea of what's going on here's a quick example. Using a [__yEd Graph Editor__][4] Create a .graphml graph like this one and store it in the _graphs/_ folder of your project as _first.graphml_ . |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Run the next code: (don't forget to clone the repository into your project folder) |
| 32 | + |
| 33 | +```python |
| 34 | +import automatabpp as FSM |
| 35 | + |
| 36 | +FSM.BEHAVIOUR.load_behaviour_from_graph("first.graphml", "My First Finite State Machine") |
| 37 | + |
| 38 | +@FSM.EXECUTION.state |
| 39 | +def ON_START(*args, **kwargs): |
| 40 | + print("FSM start") |
| 41 | + |
| 42 | +@FSM.EXECUTION.state |
| 43 | +def HELLO(*args, **kwargs): |
| 44 | + print("Hello!") |
| 45 | + |
| 46 | +FSM.OPERATION.start_fsm() # prints "FSM start" |
| 47 | +FSM.OPERATION.run_fsm("is_anyone_there") # prints "Hello!" |
| 48 | +``` |
| 49 | + |
| 50 | +To learn more please check [the examples at the bottom of the page](#additional-links). |
| 51 | + |
| 52 | +*** |
| 53 | + |
| 54 | +### Why a paradigm and not a pattern? |
| 55 | + |
| 56 | +While developing this project I ran into this quote on [wikipedia][1]. To quote: |
| 57 | + |
| 58 | +> "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." |
| 59 | +
|
| 60 | +There is also a [definition on programming paradigm][2] that I found fitting this project perfectly. |
| 61 | + |
| 62 | +> "A programming paradigm is a style, or “way,” of programming." |
| 63 | +
|
| 64 | +Indeed, there is more than enough style in developing this way once you learn how to do it. |
| 65 | + |
| 66 | +### How does this differ from ... ? |
| 67 | + |
| 68 | +There are countless ways to develop your program and this one is just one take on it. |
| 69 | +However I do feel there are some advanteges to using the Automata-Based programming over some other approach. |
| 70 | +* Explanation of the code can be easily visualized since most of the code is done by drawing graphs |
| 71 | +* If the machines are well defined the execution and the main loop can be really simple |
| 72 | +* __It's fun__ _(if you consider drawing FSMs to be fun)_ |
| 73 | + |
| 74 | +I'll also leave these [two quotes here][3]: |
| 75 | +> "Programs must be written for people to read, and only incidentally for machines to execute." - Abelson & Sussman |
| 76 | +
|
| 77 | +> "Typing is no substitute for thinking." - Richard W. Hamming |
| 78 | +
|
| 79 | +### What other software do I need ? |
| 80 | +I would recommend you download the [yEd Graph Editor from their official homepage][4]. This project can only import ___.graphml___ graphs at the moment. |
| 81 | +However I do plan on adding code to import more formats in the future. |
| 82 | + |
| 83 | +__yEd Graph Editor__ is used for viewing and drawing our state machine graphs. |
| 84 | +We consider nodes of the graph to be the states and the edges to be the transitions. |
| 85 | + |
| 86 | +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. |
| 87 | + |
| 88 | +### Directories |
| 89 | + |
| 90 | +* **./automatabpp** - our module source code. This directory contains the python code for this project. |
| 91 | +* **./comparisons** - a small module which offers some lambda comparison functions you can use with this project. |
| 92 | +* **./graphs** - yEd graphs are stored in this directory by default |
| 93 | +* **./README** - I've really took my time to write all of this so I would appreciate you checking it out |
| 94 | + |
| 95 | +### Additional Links |
| 96 | + |
| 97 | +Here are some other .md links for You to read about this project. |
| 98 | +* [A list of available functions](README/FSM.md) |
| 99 | +* [Tutorial](README/tutorial.md) - make a _"Hello, World!"_ type of application (sort of). Also some more insight on what happens in the code itself. |
| 100 | +* [Example 1](README/examples/example1.md) - a simple e-mail validation machine |
| 101 | +* [Example 2](README/examples/example2.md) - an example for developing with multiple machines |
| 102 | +* [Example 3](README/examples/example3.md) - an example showcasing Base64 encode with this paradigm |
| 103 | +* [Example 4](README/examples/example4.md) - developing your embedded application with _complex_ behaviour |
| 104 | +* [Other](README/other.md) |
| 105 | + |
| 106 | + |
| 107 | +[1]: https://en.wikipedia.org/wiki/Automata-based_programming "Automata-based programming" |
| 108 | +[2]: https://cs.lmu.edu/~ray/notes/paradigms/ "Programming Paradigms" |
| 109 | +[3]: https://en.wikiquote.org/wiki/Programming_languages "Wikiquote - Programming languages" |
| 110 | +[4]: https://www.yworks.com/products/yed "yWorks Homepage" |
0 commit comments