From 720a2bebcf6a1e76f15351569fc64b4ab88eb16c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 15 Jul 2022 22:39:02 -0700 Subject: [PATCH] Officially prefer int for IDs. For a while I was attracted to string IDs because of the notion that "if you're not going to perform arithmetic, it shouldn't be an int". But ints make way better use of the allotted bits and I'm loving getrandbits for urandom ID generation. --- voussoirkit/worms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 5a4b337..e2d17f4 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -132,11 +132,12 @@ class Database(metaclass=abc.ABCMeta): self._worms_transaction_lock = threading.Lock() self._worms_transaction_owner = None self.transaction = TransactionContextManager(database=self) - # If your IDs are integers, you could change this to int. This way, when - # taking user input as strings, they will automatically be converted to - # int when querying and caching, and you don't have to do the conversion - # on the application side. - self.id_type = str + # Since user input usually comes in the form of strings -- from command + # line, http requests -- and the IDs are usually ints in the database, + # we'll do the data conversion before making queries or responses, + # so you don't have to do it in your application. + # But if your application uses string IDs, set self.id_type = str + self.id_type = int self.last_commit_id = None @abc.abstractmethod