Command Palette

Search for a command to run...

Назад к скиллам
скилл № 11705

hoc-properties

Conventions for class properties — where they are set, whether they may change, and what may hold them. Use when declaring, assigning or reviewing a property…

БесплатноБез исполняемых скриптов
openreachtechот openreachtech★ 17 звёзд на GitHub

Установить hoc-properties в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Classes: Members / Properties

This summarizes conventions related to class property definitions.

Set properties on this within the constructor

  • That a property is set only as this.xxx = xxx inside the constructor, and why class fields are not used, belong to /hoc-classes-principles.
  • It is read here for what it means to tests: a property set that way stays accessible from outside, so a test can read it directly.

Classes are immutable / property reassignment is prohibited

  • Basically, all classes are implemented as immutable. Once a property is set in the constructor, it must not be reassigned thereafter.
  • this.xxx = ... within the constructor (the initial set) is permitted. ESLint also does not prohibit this.
  • What is prohibited is property reassignment outside the constructor, including anything under the property's object path — this.state.count += 1 as much as this.state = .... ESLint enforces the direct form; what lies under the path is held by this rule alone.
  • Being immutable means that even a property with public access scope is "protected by coding rules." Hence there is no need to make it native private for encapsulation purposes (for why, see /hoc-prohibit-native-features).
// NG: reassigning a property after creation
scalar.normalizedValue = anotherValue

// NG: reassigning under a property's object path
this.state.count += 1

// OK: if a different state is needed, generate a new instance via a factory method
const next = Scalar.create({
  normalizedValue: anotherValue,
})

Every element of a collection is treated as an equal

Code that makes an instance mutable is prohibited, uniformly — the reassignment prohibition is one means to that, and a collection is no exception. An Array or a Set holds elements that are all treated as equals: none is singled out by its position or by a condition, so the collection never holds a [3] and a [0] that differ in kind.

A collection is used in one of two ways, and the way decides whether it may change while the instance is in use. In the first, the class has an entry-point method that handles every element at once: what that method returns changes when the collection does, so the collection is state — it is built, and the change goes to a new instance through the factory method instead. In the second, the class has no such method and only adds at one end and takes from the other, as a queue does: no result depends on what the collection holds as a whole, so the collection is not state.

This holds wherever the collection sits — a property, or anything under its object path — and a Set is held to it exactly as an Array is.

  • A builder edits its collection until it builds. In the Builder Pattern, the editing period runs until #buildXxxx() is called on the values the collection property holds. Until then, elements are added to it; from that call on, its elements are handled together like any other collection's.

    // OK: the builder's collection is edited until #buildQuery() uses it
    addCondition ({
      condition,
    }) {
      this.conditions.push(condition)
    }
    
    buildQuery () {
      return this.conditions
        .map(it => it.toClause())
        .join(' AND ')
    }
    
  • A queue is the second way a collection is used. A queue has no entry-point method that handles all of its elements. It adds elements at the tail and takes them from the head, so every element is handled alike and only its turn differs; the head is whichever element has waited longest, never one with a role of its own. No result of the class depends on what the collection holds as a whole, so adding and taking at its ends is not state that changes. Reading or replacing an element in between, by position or by condition, stays prohibited.

    // OK: a queue adds at the tail and takes from the head
    enqueue ({
      topic,
    }) {
      this.topics.push(topic)
    
      return this
    }
    
    dequeue () {
      return this.topics.shift()
        ?? null
    }
    
  • Its elements are used through a higher-order function, as /hoc-higher-order-functions settles. Taking an individual element out by its position — [n] on an Array, values().next() or [...set][0] on a Set — singles one element out of the others.

  • An element is never replaced in place. Taking a position — indexOf(), findIndex() — and replacing what sits there with splice(index, 1, newEntity) is array[index] = newEntity under another name. The changed collection is another array, built with map().

  • Its count is asked of the class that holds it. .length / .size is read only inside that class, in a member that answers the count — get entityCount () — and whether it is empty is answered the same way, by isEmpty (). A caller handed the collection asks the holder rather than reading its length itself.

  • A collection is held for its elements. An array whose only use is i

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл hoc-properties?

Conventions for class properties — where they are set, whether they may change, and what may hold them. Use when declaring, assigning or reviewing a property of a class, including when a note writes a member as `#alpha`. `Map` and native private belong to the native-feature prohibition convention; accessors, to the accessors convention; whether a class needs properties at all, to the class design principles convention.

Как установить скилл hoc-properties?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hoc-properties запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить hoc-properties с