Datatypes for reasonable people.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
README.rst
datatypes.py
number.py

README.rst

Compromise: Datatypes for Reasonable People

PyCon 2016 Lightning Talk

Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.

—Stan Kelly-Bootle

In a world of disagreement, Compromise is everything for everyone. You no longer have to make the tough decisions in life.

>>> l = HalfIndexList('abcde')
>>> l[0.5]
'a'
>>> l[1.5]
'b'
>>> l[-0.5]
'e'
>>> l.reverse()
>>> l
['e', 'd', 'c', 'b', 'a']

Some may find having a set starting index a bit restrictive. They should use FlexibleList.

>>> l = FlexibleList('abcde')
FlexibleList(['a', 'b', 'c', 'd', 'e'], start=0)
>>> l.start = 5
>>> l[7]
'c'

SemiMutableSequences can't be changed.

>>> t = SemiMutableSequence(range(5))
>>> t
SemiMutableSequence([0, 1, 2, 3, 4])
>>> t[1] = 7
TypeError: SemiMutableSequence object does not support item assignment

Unless you, like, really want to.

>>> t = SemiMutableSequence(range(5))
>>> try:
...     t[1] = 7
... except TypeError:
...     pass
>>> t[1] = 7
>>> t
SemiMutableSequence([0, 7, 2, 3, 4])

Magic Numbers are bad. Who could possibly understand what this means?

>>> feet = yards * 3

These should be replaced by Number instances.

>>> from compromise import THREE
>>> feet = yards * THREE

See? Much better. You can make longer numbers with & and floats with point()

>>> ONE & ZERO
10
>>> THREE + point(ONE & FOUR)
3.14

They're constant by convention only. Don't change them!

>>> TWO = (ONE & ZERO) / FOUR
>>> TWO + TWO
5

Or change them if you want. I don't care.