Operator Trait Method Naming

Status: Approved Approved: 2026-01-31 Author: Claude Created: 2026-01-31 Depends On: operator-traits-proposal.md

Summary

Rename operator trait methods to use full words instead of abbreviations for consistency and readability.

Motivation

Currently, operator trait method names are inconsistent:

TraitCurrent MethodIssue
AddaddFine (already full word)
SubsubAbbreviation
MulmulAbbreviation
DivdivideFull word (due to div keyword)
FloorDivfloor_divAbbreviation
RemremAbbreviation
NegnegAbbreviation
NotnotFine (already full word)
BitNotbit_notFine
BitAndbit_andFine
BitOrbit_orFine
BitXorbit_xorFine
ShlshlAbbreviation
ShrshrAbbreviation

The Div trait uses divide because div is a keyword (floor division operator). This creates an inconsistency where some methods use abbreviations and one uses the full word.

Problems

  1. Inconsistency: divide stands out among add, sub, mul, rem
  2. Readability: Full words are more readable in method chains and impl blocks
  3. Discoverability: New users may not recognize rem as “remainder” or shl as “shift left”

Design

Method Renames

TraitCurrentProposed
Subsubsubtract
Mulmulmultiply
Divdividedivide (unchanged)
FloorDivfloor_divfloor_divide
Remremremainder
Negnegnegate
Shlshlshift_left
Shrshrshift_right

Unchanged Methods

These methods are already full words or conventional:

TraitMethodReason
AddaddAlready full word
NotnotAlready full word
BitNotbit_notConsistent with bitwise family
BitAndbit_andConsistent with bitwise family
BitOrbit_orConsistent with bitwise family
BitXorbit_xorConsistent with bitwise family

Updated Trait Definitions

trait Sub<Rhs = Self> {
    type Output = Self
    @subtract (self, rhs: Rhs) -> Self.Output
}

trait Mul<Rhs = Self> {
    type Output = Self
    @multiply (self, rhs: Rhs) -> Self.Output
}

trait Div<Rhs = Self> {
    type Output = Self
    @divide (self, rhs: Rhs) -> Self.Output
}

trait FloorDiv<Rhs = Self> {
    type Output = Self
    @floor_divide (self, rhs: Rhs) -> Self.Output
}

trait Rem<Rhs = Self> {
    type Output = Self
    @remainder (self, rhs: Rhs) -> Self.Output
}

trait Neg {
    type Output = Self
    @negate (self) -> Self.Output
}

trait Shl<Rhs = int> {
    type Output = Self
    @shift_left (self, rhs: Rhs) -> Self.Output
}

trait Shr<Rhs = int> {
    type Output = Self
    @shift_right (self, rhs: Rhs) -> Self.Output
}

Updated Desugaring Table

OperatorDesugars To
a + ba.add(rhs: b)
a - ba.subtract(rhs: b)
a * ba.multiply(rhs: b)
a / ba.divide(rhs: b)
a div ba.floor_divide(rhs: b)
a % ba.remainder(rhs: b)
-aa.negate()
!aa.not()
~aa.bit_not()
a & ba.bit_and(rhs: b)
a | ba.bit_or(rhs: b)
a ^ ba.bit_xor(rhs: b)
a << ba.shift_left(rhs: b)
a >> ba.shift_right(rhs: b)

Implementation

Files to Update

  1. library/std/prelude.ori — Rename methods in trait definitions
  2. compiler/ori_typeck/src/infer/expressions/operators.rs — Update binary_op_to_trait() and unary_op_to_trait()
  3. compiler/ori_eval/src/interpreter/mod.rs — Update binary_op_to_method()
  4. docs/ori_lang/v2026/spec/09-expressions.md — Update operator traits table
  5. docs/ori_lang/proposals/approved/operator-traits-proposal.md — Update method names
  6. docs/ori_lang/proposals/approved/duration-size-to-stdlib-proposal.md — Update method names
  7. tests/spec/traits/operators/user_defined.ori — Update test implementations

Migration

This is a breaking change for any code that:

  1. Implements operator traits with the old method names
  2. Calls operator methods directly (rare)

Since operator traits were just implemented and not yet released, there is no migration burden.

Alternatives Considered

Keep Abbreviations

Continue using sub, mul, rem, etc.

Rejected: Creates permanent inconsistency with divide.

Abbreviate divide to div

Change divide back to div and accept the keyword conflict by using a different parsing strategy.

Rejected: Introduces parser complexity and potential confusion. The keyword div for floor division is well-established.

Use Rust-style Names

Use Rust’s exact names: sub, mul, div, rem, neg, shl, shr.

Rejected: Ori already diverged from Rust by using divide. Full words are more readable and Ori values clarity over terseness.

References

  • operator-traits-proposal.md — Original operator traits design
  • Rust std::ops — Uses abbreviated names (sub, mul, div, rem)
  • Python — Uses full names (sub, mul, truediv, mod)
  • Swift — Uses full names (subtract, multiply, divide)