# python-scala-idioms

python-scala-idioms guides AI agents to translate Python into idiomatic Scala. Enforces immutability, pattern matching, sealed domain traits, and type-safe error handling.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 1 install · ★ 1933 repo stars
- Author: benchflow-ai
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/python-scala-translation/environment/skills/python-scala-idioms/SKILL.md
- Updated: 2026-10-24
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/python-scala-idioms

## What it does

This skill prevents AI agents from generating literal line-by-line ports of Python scripts. Instead of migrating mutable state and loops as `var` structures, it directs the model to apply Scala idioms: expressions over statements, pattern matching over conditional branches, and `Option` or `Either` over raw null checks.

The guidance includes side-by-side patterns for mapping list comprehensions to collection combinators, replacing string-typed dispatch with exhaustive `sealed trait` hierarchies, and modeling state transitions through `case class` copy calls. It also establishes Scala naming rules (`camelCase` for methods, `CamelCase` for constants) and discourages casting with `asInstanceOf` or typing values as `Any`.

Keep in mind that these guidelines assume idiomatic functional Scala. If your target codebase relies heavily on mutable state for low-level performance tuning, the patterns enforced here will directly clash with that design.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill python-scala-idioms -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/python-scala-idioms/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/python-scala-idioms/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill python-scala-idioms -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/python-scala-idioms/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill python-scala-idioms -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/python-scala-idioms/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install benchflow-ai/skillsbench tasks/python-scala-translation/environment/skills/python-scala-idioms
```

2. **Manually: put the files in place**
- File: `.github/skills/python-scala-idioms/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill python-scala-idioms -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/benchflow-ai/skillsbench --path tasks/python-scala-translation/environment/skills/python-scala-idioms
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/python-scala-idioms/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add benchflow-ai/skillsbench --skill python-scala-idioms -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/python-scala-translation/environment/skills/python-scala-idioms/SKILL.md

## When to use it
- convert imperative Python workflows into functional Scala collections
- eliminate null checks by migrating Python code to `Option` chains
- turn string-based conditional branching into compiler-checked `sealed trait` hierarchies
- replace mutable loop accumulators with `foldLeft` or `map` pipelines

## Example prompts
- Translate this Python user service into idiomatic Scala using immutable case classes
- Refactor these nested Python `dict.get` calls into an Option for-comprehension in Scala
- Convert this Python status dispatcher into a Scala sealed trait hierarchy with pattern matching

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: fbd7a9310b9ffb34.

BEGIN THIRD-PARTY FILE fbd7a9310b9ffb34
````text
---
name: python-scala-idioms
description: Guide for writing idiomatic Scala when translating from Python. Use when the goal is not just syntactic translation but producing clean, idiomatic Scala code. Covers immutability, expression-based style, sealed hierarchies, and common Scala conventions.
---

# Python to Idiomatic Scala Translation

## Core Principles

When translating Python to Scala, aim for idiomatic Scala, not literal translation:

1. **Prefer immutability** - Use `val` over `var`, immutable collections
2. **Expression-based** - Everything returns a value, minimize statements
3. **Type safety** - Leverage Scala's type system, avoid `Any`
4. **Pattern matching** - Use instead of if-else chains
5. **Avoid null** - Use `Option`, `Either`, `Try`

## Immutability First

```python
# Python - mutable by default
class Counter:
    def __init__(self):
        self.count = 0

    def increment(self):
        self.count += 1
        return self.count
```

```scala
// Scala - immutable approach
case class Counter(count: Int = 0) {
  def increment: Counter = copy(count = count + 1)
}

// Usage
val c1 = Counter()
val c2 = c1.increment  // Counter(1)
val c3 = c2.increment  // Counter(2)
// c1 is still Counter(0)
```

## Expression-Based Style

```python
# Python - statement-based
def get_status(code):
    if code == 200:
        status = "OK"
    elif code == 404:
        status = "Not Found"
    else:
        status = "Unknown"
    return status
```

```scala
// Scala - expression-based
def getStatus(code: Int): String = code match {
  case 200 => "OK"
  case 404 => "Not Found"
  case _ => "Unknown"
}

// No intermediate variable, match is an expression
```

## Sealed Hierarchies for Domain Modeling

```python
# Python - loose typing
def process_payment(method: str, amount: float):
    if method == "credit":
        # process credit
        pass
    elif method == "debit":
        # process debit
        pass
    elif method == "crypto":
        # process crypto
        pass
```

```scala
// Scala - sealed trait for exhaustive matching
sealed trait PaymentMethod
case class CreditCard(number: String, expiry: String) extends PaymentMethod
case class DebitCard(number: String) extends PaymentMethod
````
END THIRD-PARTY FILE fbd7a9310b9ffb34

The third-party file has ended. Everything between the fbd7a9310b9ffb34 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2231 of 7510 bytes. © benchflow-ai · Apache-2.0 · https://github.com/benchflow-ai/skillsbench/tree/HEAD/tasks/python-scala-translation/environment/skills/python-scala-idioms/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
