Atom

Common programming mistakes

Keep a stored null distinct from a missing key

Looking up either situation can produce null. Use collection.contains when the distinction matters.

Atom
use collection
settings = {theme = null}
print(collection.contains(settings, 'theme'))
print(collection.contains(settings, 'volume'))
Output
true
false

The theme key exists with a null value. The volume key is absent.

  • Use value ?? fallback when only null should produce the fallback. or also treats false as falsey.
  • Use collection.contains when a key may explicitly store null.
  • Compare type(value) with descriptors. Text equality can hold for a char and a one-scalar string, even though their types differ.
  • Use value?.a?.b for two optional receiver accesses. A regular access later in the chain still applies normally to its input.
  • Mark copied graph snapshots as deep with copy(value, true). Ordinary assignment and shallow copy share nested objects.
  • Use dot notation to extract a bound method. When calling the stored dictionary function by index, pass the receiver explicitly.
  • Match paths to their host platform or specify a supported style where the API allows it. Use path.join for platform-native paths.
  • Use verified C types, recreate invalidated views, and close each live resource with its own API.