3.4. ADR Dragon Create Name

  • EN: Create dragon named "Wawelski"

  • PL: Smok przy tworzeniu musi mieć nadane imię

3.4.1. Option 1

dragon = Dragon('Wawelski')

Good:

  • Code is readable

  • Easy to use

  • Easy to understand

Bad:

  • Less verbose than keyword arguments

Decision:

  • Candidate

3.4.2. Option 2

dragon = Dragon(name='Wawelski')

Good:

  • Code is readable

  • Easy to use

  • Easy to understand

  • More verbose than positional arguments

Bad:

  • Too verbose for such simple example

Decision:

  • Rejected, too verbose for such simple case

3.4.3. Option 3

dragon = Dragon()
dragon.name = 'Wawelski'

Good:

  • Code is readable

  • Easy to use

  • Can add validation if needed (property())

Bad:

  • Requires knowledge of an API

  • Violates encapsulation (OOP Principle)

Decision:

  • Rejected, violates encapsulation

3.4.4. Option 4

dragon = Dragon()
dragon.set_name('Wawelski')

Good:

  • Code is readable

  • Can use for validation if needed

Bad:

  • Not a Python convention (Setter method)

  • Requires knowledge of an API

  • Overkill for such simple case

Decision:

  • Rejected, overkill for such simple case

3.4.5. Option 5

dragon = (
    Dragon()
    .with_name('Wawelski')
)

Good:

  • Extensible

  • Can use for validation if needed

Bad:

  • Not a Python convention (Builder design pattern)

  • Requires knowledge of an API

  • Overkill for such simple case

Decision:

  • Rejected, overkill for such simple case

3.4.6. Decision

dragon = Dragon('Wawelski')

Rationale:

  • Readable

  • Easy to use

  • Easy to understand

  • Verbose enough

Implementation:

class Dragon:
    name: str

    def __init__(self, name: str, /) -> None: ...