Skip to content

Replace system lambda #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 5, 2024
Merged

Replace system lambda #601

merged 15 commits into from
Aug 5, 2024

Conversation

binkley
Copy link
Owner

@binkley binkley commented Jul 31, 2024

Howdy!
I'm looking to replace the system-lambda test library with small, local, bespoke code. This library specializes in nicer Java code for messing with System globals in the JVM such as STDOUT/STDERR, et al.
This addresses #483. Currently the build on this branch is green.

To consider before approving:
Should the project provide example replacement code rather than continuing to use a 3rd-party library?

Use a code style that:

  • Maximizes teaching, such as a lot of Javadoc: it isn't good enough to "just work", but should help others see the practices and patterns[1]
  • Is a drop-in replacement for system-lambda with improved naming: captureTerminal (this code) vs tapSystemOutNormalized (system-lambda library) (Expected discussion on naming for "captureTerminal" -- all TWers love noodling on naming 😀)
  • Hides internal details as much as possible (a lesson for readers) to lower the surface area of the API. The replacement class is TerminalContext and only the static method of captureTerminal should be visible. Do not look behind the curtain: we mess with JDK global statics)

@Bukharovsi GitHub auto-suggested you to review. :D We won't depend on your feedback to decide if to merge this PR--there is a lot on your plate right now--, but would love your thoughts!

I really like the https://github.com/stefanbirkner/system-lambda library, and use it in some side projects where I need to test complicated things about the terminal or environment. For the example code in this project, it feels like using a cannon to hit an orange.

Footnotes

  1. Essentially what this PR and a library like system-lambda does is to wrap a continuation (the call to test). Describing it this way is unhelpful for most programmers. We are wrapping calls (Application.main) that access monads for STDOUT and STDERR (such a scholarly description meaning "side effect"), and capturing the data sent to them so we can test these interactions.
    Yep, this is what testing "Hello, world" looks like! No way I want to talk about it this way to the general programmer audience.

binkley added 10 commits July 27, 2024 10:05
This is a code example in tests of replacing the "system-lambda"
library specific to our needs of checking program output to the
terminal/console.

The `ContextForTerminal` test class is reusable, but unclear we should
provide this even as copy/paste for folks browsing our test code.

Along the way:
- Find that the PMD rule on "CommentSize" is awful. We should suppress
  it by default. When you write large comments (for example, in Javadoc)
  your build should not break.
- Suppressions of PMD checks, or rewriting for Checkstyle. This is a
  smell that either code is wonky, or this is too low-level to make a
  good example.
- Reminder that the old Java APIs only dealt with UTF issues in a
  half-ass fashion. A reason to use libraries that dealt with this for
  you.
- Reminder that terminal/console out/err is not thread-safe, and no
  library can fix that.
This is a code example in tests of replacing the "system-lambda"
library specific to our needs of checking program output to the
terminal/console.

The `ContextForTerminal` test class is reusable, but unclear we should
provide this even as copy/paste for folks browsing our test code.

Along the way:
- Find that the PMD rule on "CommentSize" is awful. We should suppress
  it by default. When you write large comments (for example, in Javadoc)
  your build should not break.
- Suppressions of PMD checks, or rewriting for Checkstyle. This is a              smell that either code is wonky, or this is too low-level to make a
  good example.
- Reminder that the old Java APIs only dealt with UTF issues in a
  half-ass fashion. A reason to use libraries that dealt with this for
  you.
- Reminder that terminal/console out/err is not thread-safe, and no
  library can fix that.
@binkley binkley requested review from Bukharovsi and jwlibby July 31, 2024 13:37
binkley added 3 commits August 2, 2024 07:58
IntelliJ is happier with the line breaks in this commit.
Also, update the javadocs with better links and wording.
Making things public helps with Javadoc generation.
@binkley binkley merged commit e0d9e4c into master Aug 5, 2024
11 checks passed
@binkley binkley deleted the replace-system-lambda branch August 9, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant