Skip to content

Docs: Recommend switch expressions in AGENTS.md code style - #17357

Merged
stevenzwu merged 2 commits into
apache:mainfrom
stevenzwu:agents-md-switch-expressions
Jul 26, 2026
Merged

Docs: Recommend switch expressions in AGENTS.md code style#17357
stevenzwu merged 2 commits into
apache:mainfrom
stevenzwu:agents-md-switch-expressions

Conversation

@stevenzwu

Copy link
Copy Markdown
Contributor

This is surfaced by @gaborkaszab in his review comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread AGENTS.md Outdated
- Comments and Javadocs should describe the current behavior or contract, not how it changed over time.
- `} else {` on same line. Minimize variable scope. `try-with-resources` for all `AutoCloseable`.
- Prefer method references over lambdas. Wrap lines at the highest semantic level.
- Prefer switch expressions (`case X -> ...`) over statement switches; an exhaustive enum switch needs no `default`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current line only tells the agent half of it ("enum switch needs no default") and could lead an agent to strip the default from a String switch.

Something like this might be complete:

Prefer switch expressions (case X -> ...) over statement switches. An exhaustive enum switch needs no default. For 
String/non-exhaustive switches, the required default should throw an informative error (e.g. Unsupported X), not a generic one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the risk of over-generalizing. I want to keep the bullet terse to match the surrounding style, and I'd rather leave the informative-error-message advice out of this one since it's really about exception messages, not switches. Pushed a tighter version:

Prefer switch expressions (case X -> ...) over statement switches. Exhaustive enum switches need no default; others must have one.

WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@anuragmantri anuragmantri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevenzwu
stevenzwu merged commit a54ce8c into apache:main Jul 26, 2026
25 checks passed
@stevenzwu
stevenzwu deleted the agents-md-switch-expressions branch July 26, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants