Skip to content
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

Replace text-format dependency with something more type safe #275

Open
isomorpheme opened this issue Sep 13, 2024 · 0 comments
Open

Replace text-format dependency with something more type safe #275

isomorpheme opened this issue Sep 13, 2024 · 0 comments

Comments

@isomorpheme
Copy link

isomorpheme commented Sep 13, 2024

In a bunch of places, we currently use format from Data.Text.Format to produce strings (e.g. for posting comments, but also log messages). This function is partial: if the format string doesn't have a matching amount of parameters, it fails with an error. Moreover, there's at least one non-obvious way this can happen: in a call like format "x = {}" (show x), the formatting parameters aren't understood as the single string show x, but all of its individual characters because of the infamous type String = [Char] design error. (The fix here is writing [show x] or Only (show x) instead.)

There's some possible alternatives:

  • Use good old-fashioned concatenation of Texts. More foolproof, but cumbersome to read and write, and in principle less efficient.
  • Use a more type-safe formatting library like formatting.
  • In case of logging: use a structured logging library instead of putting contextual data into strings.
  • In case of comments: introduce a sum type of possible comments, and format them centrally (using one of the aforementioned approaches). This has the added benefit of making tests more concise - no need to copy-paste & update similar strings everywhere.
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

No branches or pull requests

1 participant