Coding 2020-02-01

By Max Woerner Chase

I think I've been a little burned out on coding recently. I guess it's partly that I'm frustrated because I don't want to use Poetry until my pull request against it gets merged and released, and it seems to me to be still in a kind of bikeshedding phase.

If I want to do more, I should probably switch languages for a bit.

To get something done, I reviewed my reference material for the old solo RP. I basically just established that Risus uses d6s, and the rest uses mostly d10s and d100s, with a single d20 added as a result of the exensive mixing of sources for the fate check. Most sections had at least a little bit that could be entered into a tabular data file.

I was considering a bit the best practices for the library I'm putting together. Because there's always at least some level of reliance on strings for the registrations, at least the way I write this stuff, the class names and aliases should probably be namespaced, which will probably look a little clunky. I may want to look into changing how I do the dependency injection, since it's (almost) totally decoupled from the class definitions.

For some context, here's what some of these classes look like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
@typing_extensions.final
@attr.dataclass(slots=True, frozen=True)
class Roll(object):
    """Handle rolling a dice for some reason."""

    _random: Random
    _roll_log: RollLog

    def __call__(self, top: int, purpose: str) -> int:
        """Log the purpose of the roll, and the outcome.

        Args:
            top: The maximum value of the die to roll.
            purpose: The reason the die is being rolled.

        Returns:
            The outcome of rolling the die.
        """
        self._roll_log("Rolling {purpose}.".format(purpose=purpose))
        roll = self._random.randint(1, top)
        self._roll_log("Rolled {roll}.".format(roll=roll))
        return roll

This is written to be mostly compliant with wemake-python-styleguide, which I think is a combination of interesting ideas, overreach, and I'm pretty sure it still crashes on Structured Data.

Anyway, I was just looking over the source code to punq, and I'm not convinced I understand its usage of type hints. I'm going to have to experiment with it and see if I find some kind of shortcoming or edge case. (Probably related to giving two classes the same name.) But I'm too tired right now.

Good night.