Skip to content

Adopt more idiomatic Go style; fix panic in sedra.FindParshaNum - #35

Merged
mjradwin merged 3 commits into
mainfrom
idiomatic-go-cleanup
Jul 12, 2026
Merged

Adopt more idiomatic Go style; fix panic in sedra.FindParshaNum#35
mjradwin merged 3 commits into
mainfrom
idiomatic-go-cleanup

Conversation

@mjradwin

@mjradwin mjradwin commented Jul 12, 2026

Copy link
Copy Markdown
Member

Three commits: a dependency bump, a no-op style pass, and one real bug fix that the style pass turned up.

Stays on Go 1.18 — every change is compatible with the current go.mod.

chore: update dependencies

gematriya v1.0.1 → v1.1.0, greg v1.0.2 → v1.1.0. Independent of the rest of the branch; go mod tidy is a no-op on the result.

Adopt more idiomatic Go style (no functional change)

All exported signatures and types are unchanged; verified by diffing go doc -all for every package against main. The only API-surface differences are doc comment text and receiver names, neither of which callers can observe.

  • sedra: renamed the snake_case parsha tables (sat_short, mon_long_leap_Israel, …) to camelCase, and _d/_u to doubled/undoubled with a comment explaining the negative-index encoding of doubled readings. getSedraArray was a nested if/else-if tree in which every branch returned; it's now split into commonSedraArray and leapSedraArray, each a switch on weekday with an inner switch on year type, with the repeated if il { ... } else { ... } collapsed into a schedule() helper. Parsha.Render uses strings.Builder instead of bytes.Buffer.
  • hebcal: dropped redundant else-after-return in getStartAndEnd; replaced the four-way HDate comparison with an XOR on hasStart/hasEnd; renamed the min local that shadowed the builtin; used the AND-NOT operator (&^=) to clear mask bits.
  • event: HolidayEvent.Render's if/else-if chain is now a tagless switch.
  • omer: := over var x = ..., grouped consts, Sefira's locale chain as a switch, and doc comments on the exported OmerEvent/NewOmerEvent.
  • candles: formatTime takes time.Time by value rather than by pointer.

Doc comments on exported identifiers now begin with the identifier name, per Go convention, so go doc renders them correctly.

sedra: return an error from FindParshaNum instead of panicking

FindParshaNum already declared an (hdate.HDate, error) result, but panicked when the parsha wasn't found. That branch is reachable: a parsha read as part of a doubled reading can't be found on its own, so in a year that reads Matot-Masei together (e.g. 5784 in the Diaspora), FindParshaNum(42) and FindParshaNum(43) both crashed the caller.

It now returns an error, as the signature always promised. Added TestFindParshaNumErrors to cover it.

Note

This is a behavior change, not a pure fix — worth a changelog line. Every in-tree caller already discarded the error with _, so they now get a zero HDate instead of a panic. But anyone downstream relying on the panic (catching it with recover, or treating "didn't panic" as proof the parsha exists) will now silently get a zero value if they ignore the error.

Testing

gofmt, go vet, and the full test suite pass at each of the three commits individually.

🤖 Generated with Claude Code

mjradwin and others added 3 commits July 12, 2026 11:05
No functional change; all exported signatures and types are unchanged
(verified by diffing `go doc -all` against the previous commit).

sedra: rename the snake_case parsha tables (sat_short, mon_long_leap_Israel,
...) to camelCase, and rename _d/_u to doubled/undoubled with a comment
explaining the negative-index encoding of doubled readings. Split
getSedraArray into commonSedraArray and leapSedraArray, each a switch on
weekday with an inner switch on year type, and collapse the repeated
`if il { ... } else { ... }` into a schedule() helper. Use strings.Builder
rather than bytes.Buffer in Parsha.Render.

hebcal: drop the redundant else-after-return in getStartAndEnd and replace
the four-way HDate comparison with an XOR on hasStart/hasEnd. Rename the
`min` local, which shadows the builtin. Use the AND-NOT operator (&^=) to
clear mask bits instead of `&= ^`.

event: rewrite HolidayEvent.Render's if/else-if chain as a tagless switch.

omer: use := over `var x = ...`, group the loose consts, rewrite Sefira's
locale chain as a switch, and document the exported OmerEvent and
NewOmerEvent.

candles: pass time.Time by value to formatTime rather than by pointer.

Doc comments on exported identifiers now begin with the identifier name,
per Go convention, so that `go doc` renders them correctly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FindParshaNum already declared an (hdate.HDate, error) result, but panicked
when the requested parsha was not found in the year's schedule. That branch
is reachable: a parsha that is read as part of a doubled reading cannot be
found on its own, so in a year that reads Matot-Masei together (e.g. 5784 in
the Diaspora), FindParshaNum(42) and FindParshaNum(43) both crashed the
caller.

Return an error in that case, as the signature always promised. Existing
callers already discard the error, so they now see a zero HDate rather than
a panic. Also switch the invalid-number path to fmt.Errorf for consistency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gematriya v1.0.1 -> v1.1.0
greg v1.0.2 -> v1.1.0

Co-Authored-By: Michael J. Radwin <mradwin@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@mjradwin
mjradwin merged commit ed86fdb into main Jul 12, 2026
6 checks passed
@mjradwin
mjradwin deleted the idiomatic-go-cleanup branch July 12, 2026 18:09
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.

1 participant