We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Capture warnings with Code.with_diagnostics/2
Use Code.with_diagnostics/2 when warnings and errors need to become structured data instead of terminal text....
Update matching list items with Access.filter/1
Use Access.filter/1 to update only the list elements that match a predicate, without mapping and rebuilding the surrounding structure yourself....
Discard late replies with process aliases
Send hand-rolled request replies to a process alias, then deactivate the alias when the caller stops waiting....
Reject unknown struct keys with struct!/2
Use struct!/2 when runtime attributes must contain only fields that belong to the struct....
The Module Behind the Curtain
Use defdelegate when a function should simply forward its arguments to another module....
Build strings with iodata, not concatenation
Building a string by repeatedly <>-ing onto an accumulator can be quadratic — but not for the reason most people think. The BEAM has a runtime optimiz...
Ecto's :utc_datetime silently drops microseconds
:utc_datetime stores second precision. Hand it a DateTime.utc_now/0 value — which carries microseconds — and Ecto.Type.cast/2 truncates it with no war...
get_in/2 needs Access.key!/1 for structs
get_in/2, put_in/3, and update_in/3 walk a path of atom keys through maps and keyword lists just fine — but the same atom path raises on a struct.
``...
Decimal `==` is not value equality
Decimal.new("1.0") and Decimal.new("1.00") represent the same number, but Elixir's == says they are different:...
`dbg/2` shows every step of your pipeline
Debugging a pipeline usually means breaking it apart with IO.inspect/2 calls between every stage, labelling each one so you can tell them apart, then ...
Stop blocking your supervisor in `init/1`
Every millisecond spent in init/1 is a millisecond your entire supervision tree is frozen. start_link/1 does not return until init/1 does, and the sup...
Name dynamic processes with `:via` tuples
The moment you need one process per game, per room, or per upload, the naming problem shows up — and the tempting fix is String.to_atom("game_#{id}")....
`attr` turns component bugs into compile errors
A function component is just a function taking assigns, which means a typo'd or forgotten assign fails the way any missing map key fails: at render ti...
`Ecto.Enum` maps atoms to integer columns
Status columns tend to rot the same way everywhere: an integer in the database, a string in the params, an atom in the business logic, and String.to_a...
Sub-binaries keep the whole payload in memory
Slicing a binary in Elixir does not copy it. binary_part/3 on a 1 MB payload hands you 100 bytes that quietly reference all 1 MB — and the parent cann...
copied to clipboard