Tests as docs? π€
Tests can serve as documentation. But the default `mix test` command doesn't print them out in a way that has clear information. Thankfully, there are two flags that can make it really nice.
Tests can serve as documentation. But the default `mix test` command doesn't print them out in a way that has clear information. Thankfully, there are two flags that can make it really nice.
People frequently struggle with Phoenix Contexts. They ask, 'Why were they introduced?' A brief history of why they were introduced might be helpful.
What should we name our own βlinkβ component in a Phoenix codebase? We cannot call it <.link> because that comes with Phoenix out of the box. This is what I do.
Elixir's new `Date.shift/2` is really cool, but you have to keep in that it's not doing arithmetic operations. Check it out.
If you want to improve your test suite speed, the first thing we want to do is find out what's the slowest module we have, right? Elixir 1.17's got your back.
Intermittent tests are a pain, but Elixir 1.17 has a really cool new flag in `mix test` to help us.
Elixir 1.17 shipped with a new feature that lets us put breakpoints right into our tests! All we have to do is run them with --breakpoints. Too good to be true? Check it out!
Have you ever wondered how Phoenix and Ecto have functions whose arguments the Elixir formatter doesn't automatically wrap with parentheses? Let me show you how to get that in your own project!
How can we inject a list into another list in a quoted expression? Turns out, our friend `quote/1` doesn't do the trick. But this other helper does!
When dealing with macros, it's sometimes hard to know what a quoted expression evaluates to. So let me show you this helper
If you've ever looked at a using macro (or any other macro for that matter), you've probably seen quote and unquote. What do those do? Let me show you.
If you ever want to find one of your dependencies' modules and functions programmatically. This tip is for you.
Elixir 1.17 ships with a brand new `to_timeout/1` helper that helps us create timeout durations in a more natural language!
Many functions in Elixir take milliseconds as an argument. Don't leave magical millisecond numbers everywhere. Use these `:timer` helpers instead.
It's mind blowing how powerful (and simple) tracing is in Elixir. Here's a quick intro into tracing in Elixir with Recon.
I think there is a right way (and a wrong way) to update Elixir structs -- at least that's if you want to know when you accidentally type the wrong thing! Let me show you the differences.
Sometimes it's a pain to write long lists... Have you ever forgotten to remove that last trailing comma? Yeah, me too. π€¦ Thankfully, there's a sigil that lets us type less (and have more power!)
Elixir 1.17 and Erlang 27 just added new process labels!
Erlang 27 just came out, and one of the highlights is the new built-in `:json` module!
Need to split a string that has two delimiters? This is a cool trick.
Elixir code tends to be pipe-friendly. But sometimes that fails. You have a pesky break in your pipeline! Here are 2 helpers that can help you keep your pipeline flowing!
People new to Elixir ask, which should I use? and/or OR &&/||? They're not the same. Here are some useful differences and some pitfalls.
Elixir's `with` clauses are awesome for organizing happy paths. But sometimes the `else` clauses get really messy and difficult to understand. Let's refactor that.
When we use function-head pattern matching as control flow and as an extraction mechanism, we make it difficult to know what's important in our code and what's merely convenience! Let's refactor it.
Enum.find/2 returns `nil` when a value can't be found. That's not always desirable. Sometimes, it's nicer to provide a better default. Thankfully, that's what Enum.find/3 gives us!
At some point, you might introduce a new `mix` alias to run a subset of your tests. But that runs in `dev` by default. How can we change the default to `test`?
When running tests we sometimes want to know which functions are being executed. But it's a pain to write custom dbg statements. How can we print the name of the function without having to know it?
Module's functions are for dealing with modules at compile time. What about runtime? We have `Module.__info__/1` just for that!
Prior to Elixir 1.16 we couldn't run multiple test files with their line numbers. With Elixir 1.16, we can!
Elixir 1.16.rc just came out, and there are four noteworthy improvements to docs
If we want to add packages to our Elixir scripts, Mix.install is the tool to use!
Elixir might add types through gradual typing. But that comes with some challenges. Check out Elixir's new way of handling some of those gradual typing challenges with strong arrows.
The Elixir types paper talks about operator precedence. Let's take a look at how that changes how we read type signatures.
JosΓ© Valim talked about types in ElixirConf 2023. I read the paper to understand why we need intersection types for some type signatures. Let me break down why!
Ever want to create an infinite sequence? Check out how we can do that with `Stream.unfold/2`. We even generate the famous fibonacci sequence.
One nice way of turning a map or keyword list into an existing struct is to use `struct/2` or `struct!/2`. Check it out!
Ever wanted to run a function in Elixir `N` times? I got the thing just for you!
Elixir 1.15 introduced new `DateTime` and `Date` functions to compare dates. Let's cover what's new, what we already had, and what to avoid at all costs!
I always knew that Elixir had some optional syntax, but I didn't realize how prevalent it was!
Elixir 1.15 is deprecating `Logger.warn/2` in favor of `Logger.warning/2`.
I've seen people quit out of IEx and restart it to load new changes to their code. Here are some cool helpers for you.
To access previous values in IEx (and save some typing) use the `v/1` helper.
I'm always fascinated by how Elixir's Stream module handles operations lazily by storing them in a struct.
Want to check if two lists have overlapping elements in Elixir?
Tail call (or last call) optimization is the trick to having long-lived processes. Never ceases to amaze!
I love how easy it is to do code spelunking π€Ώ in Elixir projects!
Updating nested data in Elixir can be tough, since all data is immutable. But there's a `put_in/2` macro that works really nicely with structs!
People asked me in previous videos, what about dbg/2 with iex? Spoiler alert β also awesome! β‘οΈ
TIL about the `:printable_limit` option for `dbg/2` and `IO.inspect/2`.
Elixir 1.14 introduced `dbg`, a debugging helper that is much more powerful than `IO.inspect` but equally easy to use!
Elixir 1.14 introduced a new option when deriving the Inspect protocol for a struct.
I love `mix help` to get the docs for mix tasks right from the command line.