caleb531 / automata

A Python library for simulating finite automata, pushdown automata, and Turing machines
https://caleb531.github.io/automata/
MIT License
349 stars 64 forks source link

Add global configuration and allow disabling automaton validation #97

Closed caleb531 closed 2 years ago

caleb531 commented 2 years ago

Adds a new automata.base.config module with the following members:

  1. A Config class that is only used for instantiating the global_config instance mentioned below
  2. A single Config instance called global_config, which is referenced in the automata.base.automaton module.

README documentation still needs to be added.

@eliotwrobson @Tagl I welcome your feedback on the code I've written so far.

coveralls commented 2 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling bc736e33e801c4d253d52b2fb346cae1ce8599ca on config into 1e8258343e95e23c20de98e7b150a79e7f05b900 on develop.

caleb531 commented 2 years ago

@eliotwrobson What do you find hacky about it? 😅

eliotwrobson commented 2 years ago

@caleb531 Just using a class variable as a global flag to control behavior. The class is effectively a singleton, and class creation behavior no longer depends only on input parameters. But like I said, for something this simple I don't think it's really a big deal.

Something like this might actually be a standard pattern in other Python packages too, just something I haven't run into before.

Tagl commented 2 years ago

Something like this might actually be a standard pattern in other Python packages too, just something I haven't run into before.

It's not any different than some python standard library configuration options, such as sys.setrecursionlimit.

caleb531 commented 2 years ago

@eliotwrobson

class creation behavior no longer depends only on input parameters.

Just wanted to address this: while it is true that something outside of the input parameters can change the behavior, it is only an issue if you create an invalid automaton (which, validation or none, will produce unpredictable behavior anyway). If you always create a valid automaton, then the behavior technically does not change based on the value of this new setting.

eliotwrobson commented 2 years ago

@caleb531 that makes sense, like I said before I don't have any objections to the way that you're doing this, just something that I haven't seen a lot (mostly due to my own inexperience 😅 , and having spent too much time around functional programming purists). I think it looks good!

caleb531 commented 2 years ago

I've added the appropriate documentation to the README in this PR, so this configuration functionality should now be ready to merge.