orchetect / TimecodeKit

The definitive SMPTE timecode library for Swift.
MIT License
91 stars 8 forks source link

Make all stored properties in `Timecode` struct mutable #34

Closed orchetect closed 3 years ago

orchetect commented 3 years ago

Proposal

Make all stored properties in Timecode struct mutable.

Current Conditions

Currently in 1.2.1, certain parameters are immutable and others are mutable.

struct Timecode {
    public let frameRate: FrameRate
    public let upperLimit: UpperLimit
    public let subFramesBase: SubFramesBase

    public var stringFormat: StringFormat
    public var days: Int
    public var hours: Int
    public var minutes: Int
    public var seconds: Int
    public var frames: Int
    public var subFrames: Int
}

Proposed Conditions

struct Timecode {
    public var frameRate: FrameRate
    public var upperLimit: UpperLimit
    public var subFramesBase: SubFramesBase

    public var stringFormat: StringFormat
    public var days: Int
    public var hours: Int
    public var minutes: Int
    public var seconds: Int
    public var frames: Int
    public var subFrames: Int
}

Context

In the earlier days of TimecodeKit, Timecode started as an exclusively immutable value type. This was to:

Then as its functionality grew, it became more evident that less restrictions on the values and mutability could provide more flexibility in practise while also not sacrificing the clarity of how the object works.

The paradigm has now shifted to:

To that end, there no longer appears to be a necessity or rationale to enforce that all or some stored properties be immutable. Since no implicit validation occurs on stored properties after the initial initialization of the Timecode struct (ie: component values are not clamped to valid values, and component values are not converted to a new frame rate when the .frameRate property changes, etc.), it is reasonable to assert that making all stored properties mutable would be intuitive and idiomatic.

orchetect commented 3 years ago

Added in 1.2.3