Values, Names, and Conversions
-
Values, Types, and Supported Operations
A type describes which operations a value supports and how those operations behave when applied.
-
Integer Division and Fractional Quotients
Choose a division operation from the intended quotient semantics and check its behavior at negative inputs.
-
Quotient and Remainder Together
A quotient counts complete groups and a remainder counts the leftover part under a particular division rule.
-
Parsing Text and Formatting Values
Parsing recovers a value from a representation. Formatting creates text for a particular reader or external interface.
-
Lexicographic and Numeric Order
Text order compares sequence elements from the start. Numeric order compares magnitudes after the values have been parsed.
-
Unset, Empty, and Zero Values
A missing input, an explicit zero, and an empty collection can carry different meanings even when a Boolean check treats them alike.
-
Boolean Values and Truth Testing
A conditional converts its test to a truth value. Be precise about which values the condition treats as meaningful.
-
Object Identity and Value Equality
Identity asks whether two references denote the same object. Equality asks whether the objects compare equal under their type's rule.
-
Mutable and Immutable Values
A mutation changes an existing object. Rebinding associates a name with another object and can leave older references intact.
-
Shallow Copies of Containers
A shallow copy duplicates the outer container and preserves the references held in its positions or entries.
-
Sign and Absolute Value in Integer Calculations
Absolute value measures distance from zero. Keeping the original sign can be essential for position, direction, or accounting.
-
Fixed-Width and Arbitrary-Precision Integers
Integer operations have different representable ranges across runtimes, formats, and hardware interfaces.
-
Representing Decimal Amounts
Store currency amounts in a representation whose scale and rounding rules match the operations the application promises.
-
Binary Floating-Point Rounding
A floating-point value stores a finite binary approximation to many familiar decimal fractions.
-
Comparing Floating-Point Values with Tolerances
A tolerance expresses how much difference a calculation or measurement can permit at the scale of the problem.
-
Truncation, Floor, Ceiling, and Rounding
Different ways of turning a fractional value into an integer behave differently at negative numbers and halfway cases.
-
Implicit and Explicit Type Conversion
An implicit conversion happens while evaluating an operation. Explicit conversion can make the intended representation and failure mode easier to see.
-
Strings, Bytes, and Text Encoding
A string holds text according to the language's character model. Encoding produces bytes that files and networks can carry.
-
Sentinel Values for Missing Data
A sentinel marks an exceptional condition in a value channel such as the absence of an optional argument.
-
Unpacking Values and Simultaneous Assignment
Unpacking binds multiple targets from one iterable. Computing the right side first lets a pair of bindings be swapped without a temporary name.
-
Operators on Different Types
Operator overloading gives one spelling several meanings determined by the participating types and their agreed operations.
-
Hashable Values and Collection Keys
Hash tables use a hash to locate candidate keys and equality to decide which key is present.
-
Parsing and Domain Validation
A parser can accept the spelling of a value while the surrounding application still rejects its meaning.
-
Converting Input Records to Typed Values
Translate incoming fields into domain values at one clear boundary so downstream code can use a consistent representation.
-
Tuples and Mutable Contents
A tuple's element positions stay fixed. The objects in those positions can still change when they support mutation.
-
Representing Values with Units
Keep the scale attached to a value so conversions happen once, at a documented interface.
-
Canonicalizing Text Labels
A canonicalization rule maps equivalent labels to one representation so records can be compared and grouped consistently.
-
Propagating a Missing Value Through a Calculation
A calculation should make clear whether incomplete inputs cause an unknown result, a partial result, or a documented substitution.
-
Ratios, Percentages, and Fractional Rates
Represent a percentage with an explicit scale so a calculation and its display cannot accidentally multiply or divide by one hundred twice.
-
Deciding What Makes Records Equal
Record identity and attribute equality are domain choices. Two records can represent one entity while containing different versions of its fields.