luckyframework / luckyframework/website

Document nil string storage anti-pattern

Open
#413 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

guides:missing
Dominant language
Crystal
Stars
39
Forks
62
PR merge metrics
No merged PRs in 30d

Description

This kind of question has come up quite frequently:
https://gitter.im/luckyframework/Lobby?at=5f4fc74f36e6f709fd1ca322

It boils down to storing "empty" to represent a nil/falsy value as being inadvisable, both from a database perspective (querying in the default PSQL CLI doesn't differentiate between the display of an empty string and a NULL value) and from a Crystal perspective (you can't do nifty things like what Paul noted in the Gitter chat above).

In case something happens to Gitter, here's the essence of what we want to call out (from Paul):

> Some data are required, like note but note can be "".
This doesn't mean it's empty, because it's a string, not a nil
▸ note: is required
note is on permit_columns

> I'd recommend keeping it and instead treating an empty string as nil. Otherwise you may do stuff like: span @user.name and it'll print an empty string. It's also easier to check for nil than an empty string because you can use try. @user.name.try { |name| span name } for example

We should add a callout in the documentation on the website around this being an anti-pattern from the Lucky perspective, the benefits of avoiding it, and how to work around it (`my_column.errors.reset_errors` in `before_save`) if desired.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the relevant documentation section on the Lucky website and review how database values and nil handling are currently explained. Add a callout covering the empty-string anti-pattern, its database and Crystal drawbacks, and the documented my_column.errors.reset_errors workaround; done means the guidance is clear and published in the appropriate section.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.