This library is intended to implement a toggle function for Boolean values in a very bad or even the worst and most unmaintainable way, following the KISS ("Keep it sophisticated, specialist!") principle.
>>> from cursed_toggle import cursed_toggle as ct
>>> b = ct(False)
>>> print(b)
True
>>> c = ct(b)
>>> print(c)
False
$ python -m cursed_toggle true
False
There are also several layers of verbosity
$ python -m cursed_toggle true -v
source: cursed_toggle.cursed_toggle_v2
False
Or just run
python -m cursed_toggle --help
to get all supported switches.
pip install cursed-toggle
This projects is SemVer (Scoped for Exclusive Management Versioning) compliant and is applied the following way a.b.c
, with:
a
should be increased, when a new (backward compatible) feature is implemented (like making this module CLI capable)b
is the number of the several sources of truth (see section SSOT). This should be the number of files starting withcursed_toggle
in src/cursed_togglec
should be increased, when there are small changes on existing code (like bugfixes or improvements)
If a change breaks existing code (like upgrading to this new version results in also changing the code that imports this library), a
is calculated with -4.23.0
. Then a new backwards compatible feature is implemented, the version will be -5.23.0
. Make some improvements -5.23.1
, add another source of truth -5.24.0
and finally do something that breaks existing code again 6.24.0
. The idea should be clear now and needs no further explanation.
Only 1 __init__
file is too straight forward. Why not add another 3 instead? We can start by naming them properly
__init_1__.py
: The list of the init files starts with 1...__init_b__.py
: ...and continues with b...__init_Ω__.py
: ...and ends with an Omega (Ω) (Wow, this even makes sense, pathetic!)
Well... So... Ahm... Basically __init__.py
imports from __init_Ω__.py
1, which imports from __init_1__.py
, which imports from __init_b__.py
, which imports the cursed_toggle.
TODO: rename __init_1__.py
to 1)__init__.py
and make it somehow work. Maybe with importlib?
In common enterprise IT, several sources of truth (SSOT) or several points of truth (SPOT) is a typical architecture. Since this repo should be enterprise grade, there is no chance not to implement something like that. That is why
cursed_toggle_v1_deprecated.py
andcursed_toggle_v2.py
andcursed_toggle_just_a_temp_little_experiment.py
andcursed_toggle_high_school.py
(WARNING: explicit sexual content) andcursed_toggle_todo.py
exist. When using the cursed_toggle library, it is randomly choosen which cursed_toggle function will be used. Even if this looks a bit stupid, it is very important that all possible imports work. That's why there is proper testing. Further, only a fool thinks, that v1 is no longer beeing developed.
When accidentally - yes "accidentally" - a new cursed_toggle....py
is created, make sure to implement this new implementation. Just add the possibility for the import to __init_b__.py
. Just follow the scheme, it is self-explanatory. ALSO DONT FORGET THE README!
All cursed_toggle....py
must be tested. If a new cursed_toggle....py
is created, don't forget the to test it.
- Copy a test file from tests/. But don't choose
test.py
, copy another file. - Rename the copied file that one can associate it with its corresponding
cursed_toggle....py
file. - Change the line for the env variable
SECRET_ENV_FOR_TESTING_ONLY_DO_NOT_USE
so that it fits to the__init_b__.py
. This is self-explanatory. - Add the test to ci.yml. This is self-explanatory.
With this method, when the overall tests change, one have to copy and paste these changes to all test files. This complies with Copy-and-paste programming philosophy.
The variable b
can be True (1) or False (0). One of the most basic implementation to get a toggle is
f(b) = not b
But this is way too simple and efficient and something cooler looking might be
f(b) = b^1
A trivial linear function is also possible
f(b) = 1 - b
and this sounds like a good start.
Not even sure whether this is a word. Anyway, after each modification, there should be a
The start function looks too negative and too simple. Let's make it positve and more complex, because
f(b) = 1 + 1j**2 * b
The single lonely 1 in the beginning is also a bit boring. And since
f(b) = -(math.e**(1j * math.pi)).real + 1j**2 * b
Square 2. Two. 2 is 2 lame. Shifting 1234567 19 times to the right is also two. So, we will rightshift it 13 and 6 times.
f(b) = -(math.e**(1j * math.pi)).real + 1j**(1234567 >> 13 >> 6) * b
f(b) = -(math.e**(1j * math.pi)).real + 1j**(1234567 >> 13 >> math.factorial(3)) * b
During my research, I stumbled across the DRY-principle, that means "Do repeat yourself" or "duplication is excellent". Here we go with the Euler's idendity. For the 3. Three. Times.
f(b) = -(math.e**(1j * math.pi)).real + 1j**(1234567 >> 13 >> math.factorial(int((-math.e**(1j * math.pi) - math.e**(1j * math.pi) - math.e**(1j * math.pi)).real))) * b
No, this is not a typo. The function is already time independent, because it does not use any time. We could add something that is based on a time, so we make it time dependent, but this is bad... Like, why should this function just work on a defined time. So we should use the time but make it stable about it. And since the name time independent is already taken (for this case), we make it time inindependent. So it depends on the time but it doesn't matter.
Let's start with a randomly guessed function of third order
Surprisingly, int(time.time()) % 3 + 5
? YEEEP, that's it- stupid simple.
So, 13
becomes (with
and the function of interest turns into
f(b) = -(math.e**(1j * math.pi)).real + 1j**(1234567 >> -24*(t % 3+5)**3 + 432*(t % 3+5)**2 - 2568*(t % 3+5) + 5053 >> math.factorial(int((-math.e**(1j * math.pi) - math.e**(1j * math.pi) - math.e**(1j * math.pi)).real))) * b
The number 1234567
can be calculated as _cursed_toggle
is 354 chars long. Easy substitution (with _cursed_toggle
):
f(b) = -(math.e**(1j * math.pi)).real + 1j**(3487 * len(_cursed_toggle.__doc__.__str__()) + 169 >> -24*(t % 3+5)**3 + 432*(t % 3+5)**2 - 2568*(t % 3+5) + 5053 >> math.factorial(int((-math.e**(1j * math.pi) - math.e**(1j * math.pi) - math.e**(1j * math.pi)).real))) * b
The .__str__()
in cursed_toggle.__doc__.__str__()
is to satisfy mypy.
Footnotes
-
Note from the author: I am not sure whether I should be impressed or frightened, especially when
__init__.py
in Spyder looks like thatfrom .__init_Ω__ [...]
. ↩