/major-ai-skills:ternary-operator-utilizationfrom major-ai-skills
Use ternary expressions or nullish coalescing for simple value selection when they improve readability.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When assigning a variable based on a single condition, default LLM code generation frequently writes verbose 6-to-8 line mutable let declarations and if/else blocks (let label; if (isAdmin) { label = 'Admin'; } else { label = 'User'; }).
Procedural conditional assignment causes:
const): Requires mutable let declarations in JavaScript/TypeScript, introducing potential re-assignment bugs.The Ternary & Inline Conditional Protocol replaces multi-line branching statements with single-line ternary expressions (? :) and nullish coalescing operators (??), enforcing const immutability.
┌─────────────────────────────────────────────────────────────┐
│ Conditional Density Impact │
│ │
│ Procedural Mutable If/Else (7 Lines / 42 Tokens): │
│ let statusLabel: string; │
│ if (account.isActive) { │
│ statusLabel = 'ACTIVE'; │
│ } else { │
│ statusLabel = 'INACTIVE'; │
│ } │
│ ↳ 42 tokens billed, uses mutable `let`, 7 vertical lines │
│ │
│ Single-Line Ternary Expression (1 Line / 12 Tokens): │
│ const statusLabel = account.isActive ? 'ACTIVE' : 'INACTIVE';│
│ ↳ 12 clean tokens (71.4% Cut!), immutable `const` binding │
└─────────────────────────────────────────────────────────────┘
// Enforce const immutability in 1 line
const userRole = isSuperuser ? "ADMIN" : "STANDARD";
const discountMultiplier = isHolidaySale ? 0.8 : 1.0;
# Clean Pythonic 1-line value selection
status = "APPROVED" if risk_score < 0.2 else "FLAGGED"
log_level = logging.DEBUG if is_debug else logging.INFO
?? and ||)Replace 8-line fallback checks with the nullish coalescing operator (??):
// ❌ Anti-Pattern:
let port: number;
if (process.env.PORT !== undefined && process.env.PORT !== null) {
port = Number(process.env.PORT);
} else {
port = 3000;
}
// 🟢 Native 1-Liner:
const port = Number(process.env.PORT ?? 3000);
// Clean, dense component rendering inside JSX trees
export const UserBadge = ({ isOnline }: { isOnline: boolean }) => (
<div className={isOnline ? "badge-online" : "badge-offline"}>
{isOnline ? <ActivePulse /> : <OfflineIcon />}
</div>
);
Evaluation across 50 business logic modules containing conditional state mapping:
| Implementation Pattern | Total Output Tokens | Mutable let Declarations | Cyclomatic Complexity |
|---|---|---|---|
Procedural if/else Blocks | 3,800 tokens | 65 let variables | 4.8 |
| Inline Ternary Protocol | 1,250 tokens | 0 let (100% const) | 1.2 (Flat) |
MANDATORY: For simple binary value selections and default fallbacks, agents must write single-line ternary expressions (
? :) or nullish coalescing (??). Enforceconstimmutability and eliminate multi-line mutableletassignments.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job