Skip to content
Skills Library
Programming · Building & coding

code-style-principles

/code-style-principles

ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, wh

Licence
MIT
Last repository change
12.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 12.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, wh

Triggers from the description

coding standards
Original author description

ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, wh

How it works

  1. 1. Control-Structure Spacing
  2. 2. Early-Return Pattern
  3. 3. If-Continue Pattern in Loops
  4. 4. Flatten Nested Null Checks
  5. 5. Explicit Checks Over Implicit Truthy/Falsy
  6. 6. Parameter Ordering
  7. 7. Comments — Justify or Delete
  8. 8. Function Length
  9. Quick Reference
Original SKILL.md headings · 108 lines, 728 words
SKILL.md preview
---
name: code-style-principles
description: "ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, which apply on top of this skill rather than instead of it. DO NOT use for: language-specific syntax already covered by php-code-conventions / ts-code-conventions (see php:php-code-conventions + typescript:ts-code-conventions for PHP/TS specifics)."
---

# Code Style — Cross-Language Principles

> The **rules** below are language-agnostic. Syntax-specific examples (nullsafe `?->`, optional chaining `?.`, no-`empty()`, nowdoc, template literals) live in:
> - `php-code-conventions`
> - `ts-code-conventions`

These conventions go **beyond** standard linters (PSR-12/PER, eslint/prettier). They encode the project's house style.

## 1. Control-Structure Spacing

Always add a blank line **before AND after** control structures (`if`, `for`, `foreach`/`for...of`, `while`, `switch`) when they are not at the start or end of the enclosing block.

**Exception:** no blank line at start or end of a method/function/block.

**Why:** visual separation between sequential statements and branching/looping logic.

## 2. Early-Return Pattern

Always use early return to handle edge cases and invalid conditions **first**. Main logic stays at base indentation.

- Reduces nesting.
- Clarifies intent (edge cases handled upfront).
- Add a blank line **before** the `return` when preceded by other statements.

## 3. If-Continue Pattern in Loops

`continue` in a loop is the equivalent of early-return in a function.

- Use `continue` **only** when the exit condition is simple and the main processing is more complex.
- When both branches have comparable complexity, prefer a classic `if/else` for readability.
- Add a blank line **before** `continue` / `return` / `break` / `throw` when preceded by other statements.

## 4. Flatten Nested Null Checks

Replace nested null-guards with the language's null-propagation operator (PHP: `?->`, TS: `?.`, Kotlin: `?.`, Swift: `?.`).

For absent values with a default, use the null-coalescing operator (PHP: `??`, TS: `??`, …).

**Criterion:** if you nest more than one `if (x !== null)`, use null-propagation.

## 5. Explicit Checks Over Implicit Truthy/Falsy

Use **explicit** comparisons instead of relying on language coercion.

- Arrays / collections: compare to empty (`=== []`, `.length > 0`) — not truthy.
- Strings: compare to `''` (or use length).
- Null/undefined: compare to `null` / `undefined` explicitly.

**Exception:** booleans can be checked directly (`if (isValid)`).

**Why:** implicit truthy/falsy hides type bugs and gives unstable results across languages (and even across the same language: PHP `empty()`, JS coercion).

## 6. Parameter Ordering

Constructors / function signatures: **mandatory parameters before optional / nullable**.

Within each group, the language's natural ordering applies (e.g. promoted properties in PHP, default values in TS).

## 7. Comments — Justify or Delete

Write a comment **only** when the code cannot speak for itself. A comment earns its place if it surfaces something the code does **not**:

- **Hidden complexity** — a non-obvious algorithm, a workaround, a `!important` / specificity hack, an ordering constraint.
- **Business / domain rule** — the *why* behind a magic value or branch (e.g. "French IBAN length = 27").
- **A decision that would otherwise look wrong** — why a line is disabled, why a framework default is overridden.

Delete any comment that **restates the code** without adding value:

```php
// AVOID — reproduces the code
// Uppercase the IBAN and strip whitespace
return strtoupper(preg_replace('/\s+/', '', $iban));

// AVOID — restates the name
/** Extra HTML attributes applied to the wrapper. */
public array $wrapperAttributes = [];
```

```php
// CORRECT — surfaces a non-obvious rule
// !important: beat Bootstrap's :valid border (empty boxes are HTML5-valid)
border-color: $danger !important;
```

**Type annotations are not prose comments**: keep `@var` / `@return` / `@param` when they add type information a tool or reader needs — they are not subject to this rule.

**Heuristic**: if deleting the comment loses no information a competent reader couldn't get from the code in seconds, delete it.

## 8. Function Length

Extract a private or local helper as soon as a function's body no longer fits in one glance.

Measure: no function body exceeds 25 executable lines, blank lines and comments excluded.

## Quick Reference

| Rule | Principle |
|------|-----------|
| Control-structure spacing | Blank line before AND after `if`/`for`/`while`/`switch` (except start/end of block) |
| Early return | Edge cases first, main logic at base indentation |
| Continue vs if/else | `continue` only when exit is simple and main is complex |
| Flatten null checks | Use null-propagation operator instead of nested `if` |
| Explicit checks | No implicit truthy/falsy — compare to empty / null explicitly |
| Parameter ordering | Mandatory before optional |
| Comments | Only for hidden complexity / business rule; delete anything that restates the code |
| Function length | Extract a helper past 25 executable lines |

Versions

The database has no other skills named code-style-principles.

Database snapshot: 13.11.2026 · package version 6f55946a774e (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95ts-code-conventions
    ACTIVATE whenever writing or modifying TypeScript code in src/. ACTIVATE for code review, formatting, or 'coding standards'. Provides TS-specific code style examples for the cross-language rules defined in craft:code-style-principles, plus TS-specific patterns (optional…
  • 100php-code-conventions
    ACTIVATE whenever writing or modifying PHP code in src/, creating controllers, services, repositories, specifications, or any production PHP class. ACTIVATE for code review, formatting questions, or 'coding standards'. Provides PHP-specific code style examples for the…
  • 100php-coding-standards
    Invoke BEFORE writing or modifying any PHP code. Provides coding standards and naming conventions for Nette repos: TABs, single quotes, strict_types, PER Coding Style modifications, use statement ordering. Use this whenever creating, modifying, or refactoring any PHP code - even…
  • 100python-code-style
    Python code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.
  • 95csharp-style
    Applies C# coding conventions when writing, reviewing, or refactoring code. Covers .cs files, XML documentation, naming, formatting, error handling, using directives, file ordering, and Unity-specific patterns. Use when writing new C# code, modifying existing code, reviewing…
  • 100review-local
    Review a local php-src diff (your current branch vs origin/master, or a base ref you provide) against PHP coding standards and produce REVIEW.md. Use when the user says "review my changes", "review this branch", "/review-local", "review the diff before I push", "check my fix",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.