Hacker News new | ask | show | jobs
Show HN: Phases, Scala macros for multiphase classes
1 points by jpivarski 4002 days ago
In adopting a functional style, I've found that I'm most tempted to break discipline when representing a single conceptual object that transitions between phases (usually before and after initialization).

An arbitrary state diagram can be represented with a collection of immutable objects, but usually with a lot of boilerplate code, especially if most fields stay the same and have to be copied from object to object. I've often wondered why programming languages don't have a facility for generating, e.g. "five classes that differ in these five ways, with the following transitions between them." Beamer, a LaTeX package for making presentations, has such a thing for making a sequence of slides that differ in only one new bullet point.

This is a hard question to ask a search engine because if such a thing existed, I wouldn't know what it's called. So I made it:

https://github.com/jpivarski/phases

is a Scala implementation of the idea using compile-time macros. I'm in the process of making it more easily deployable, but it can be tested by checking it out and changing/adding to its unit tests.

This is also my first HN post. Let me know what you think!