Skip to main content

Implementation of a Boolean toggle function according to the KISS ("Keep it sophisticated, specialist!") principle

Project description

cursed-toggle

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.

Preamble

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.

The complication

Initception

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.

[^1]: Note from the author: I am not sure whether I should be impressed or frightened, especially when __init__.py in Spyder looks like that from .__init_Ω__ [...].

TODO: rename __init_1__.py to 1)__init__.py and make it somehow work. Maybe with importlib?

SSOT / SPOT

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 and
  • cursed_toggle_v2.py and
  • cursed_toggle_just_a_temp_little_experiment.py and
  • cursed_toggle_high_school.py (WARNING: explicit sexual content) and
  • cursed_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!

Testing

All cursed_toggle....py must be tested. If a new cursed_toggle....py is created, don't forget the to test it.

  1. Copy a test file from tests/. But don't choose test.py, copy another file.
  2. Rename the copied file that one can associate it with its corresponding cursed_toggle....py file.
  3. 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.
  4. 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.

Midamble

Not even sure whether this is a word. Anyway, after each modification, there should be a $\LaTeX$-like representation of the "math" and after, the correspdoning python syntax (needed for testing this readme).

The toggle function

The start function looks too negative and too simple. Let's make it positve and more complex, because $i^2 = -1$

$$ f(b) = 1 + i^2 \cdot b $$

f(b) = 1 + 1j**2 * b

The single lonely 1 in the beginning is also a bit boring. And since $e^{i\pi} + 1 = 0$, we know what to do.

$$ f(b) = -e^{i\pi} + i^2 \cdot b $$

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) = -e^{i\pi} + i^{1234567 >> 13 >> 6} \cdot b $$

f(b) = -(math.e**(1j * math.pi)).real + 1j**(1234567 >> 13 >> 6) * b

$3! = 6$, so let's get rid of the 6.

$$ f(b) = -e^{i\pi} + i^{1234567 >> 13 >> 3!} \cdot 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) = -e^{i\pi} + i^{1234567 >> 13 >> \left(-e^{i\pi} - e^{i\pi} - e^{i\pi}\right)!} \cdot b $$

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

Time inindependence

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

$$ f_1(t) = -24 \cdot t^3 + 432 \cdot t^2 - 2568 \cdot t + 5053 $$

Surprisingly, $f_1(5) = f_1(6) = f_1(7) = 13$. So we just need something that results in 5, 6 or 7 and needs the time. What about int(time.time()) % 3 + 5? YEEEP, that's it- stupid simple.

So, 13 becomes (with $t$ as the current unix time as int, or more like $t$ can be any int)

$$ 13(t) = -24 \cdot (t \mod 3+5)^3 + 432 \cdot (t \mod 3+5)^2 - 2568 \cdot (t \mod 3+5) + 5053 $$

and the function of interest turns into

$$ f(b,t) = -e^{i\pi} + i^{1234567 >> -24 \cdot (t \mod 3+5)^3 + 432 \cdot (t \mod 3+5)^2 - 2568 \cdot (t \mod 3+5) + 5053 >> \left(-e^{i\pi} - e^{i\pi} - e^{i\pi}\right)!} \cdot b $$

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

Docstring dependence

The number 1234567 can be calculated as $3487 \cdot 354 + 169$. What a luck that the docstring of _cursed_toggle is 354 chars long. Easy substitution (with $d$ as length of the docstring of _cursed_toggle):

$$ f(b,t,d_{354}) = -e^{i\pi} + i^{3487 \cdot d + 169 >> -24 \cdot (t \mod 3+5)^3 + 432 \cdot (t \mod 3+5)^2 - 2568 \cdot (t \mod 3+5) + 5053 >> \left(-e^{i\pi} - e^{i\pi} - e^{i\pi}\right)!} \cdot b $$

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cursed_toggle-0.3.2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cursed_toggle-0.3.2-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file cursed_toggle-0.3.2.tar.gz.

File metadata

  • Download URL: cursed_toggle-0.3.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cursed_toggle-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d6ec5b745a5f149468b72cca04fab83cd3b8e0d80bace284064fe577ff7ce0d4
MD5 fc09b22dd0233e083099e60f2d1e1ed4
BLAKE2b-256 3c34e748edb5219391090f0f312a5ba6f7d049d74003f6db4ebbff92707dc836

See more details on using hashes here.

Provenance

The following attestation bundles were made for cursed_toggle-0.3.2.tar.gz:

Publisher: cd.yml on kvnglb/cursed-toggle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cursed_toggle-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: cursed_toggle-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cursed_toggle-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7742bf67cfc72af671e01df17b33b2ac11e8a06977bd8a536eaddb1adabcfcb
MD5 e8806b17a29edc23167bee5341b8c157
BLAKE2b-256 cf771b62d07eba3935bd926a3291fb6d4863fa634606f7e1e7f00c4e6ed00bf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cursed_toggle-0.3.2-py3-none-any.whl:

Publisher: cd.yml on kvnglb/cursed-toggle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page