When starting a new project, do you have any go-to libraries you pull in out of habit/preference?
CompareChain!
Mishka Chelekom, igniter, Ash
freedom_formatter, ecto_dev_logger, mix_test_interactive
If you aren’t Ash’ing then Flop along with Flop.Phoenix along with Let Me covers all of pagination/filtering/sorting/authz in a pretty nice way. Ash was, in part, born out of not having these basic necessities but if you aren’t going to use Ash (which is of course totally fine) then these help a lot (and play nicely together). I really don’t like to ping but these libs are all by @woylie who has another very helpful one in ecto_nested_changeset. Really, I wish Phoenix had out-of-the-box solutions for all of these thing, even just as generators (a la phx_gen_auth) as it’s all stuff every project needs.
There’s also Sobelow.
To be a little catty and flip the question, I intentionally shun any type of “helper” libraries (I’ll pick on Moar as an example) and argue loudly against them in a team situation. At best they are unnecessary.
Here’s my list off the top of my head.
For application code
Formatting / tools etc
BlitzCredoChecks
Credo
CredoContrib
CredoNaming
Dialyxir
Sobelow
Testing
For virtually every application:
- credo
- dialyxir (probably not needed any more once the type system is finished?)
- excoveralls
- ex_machina
- logger_json
- mix_audit
- sobelow
The rest depends on the need of the application.
I’m a co-author of Moar and I agree with your statement … check out the very first line in its readme:
A dependency-free utility library containing 100+ useful functions. Add the library to your project, or just copy and paste the bits that you want.
The library was extracted from a bunch of code that I copied and pasted between projects (I’ve built 20+ Phoenix projects by now) and putting it in a public library is the easiest way to reuse it.
Moar and similar libraries probably have at least a few functions that are useful for others, so I’d recommend perusing the docs to see if anything jumps out at you, and then consider copying that code (and modifying it as needed), or adding the library to your project (Moar is dependency-free, and I assume most other utility libraries are). Moar’s docs have a short list of other utility libraries; if you are the author of such a library, feel free to add it to Moar’s docs.
Besides Moar (see above), I add these libraries to all my projects (I’m an author of some of them):
I like to avoid dependencies whenever I can, there is only one I’d add without much thinking:
On more serious projects:
Sorry to pick on Moar it’s just the one I’ve been most exposed to. I do appreciate the README advice but I realize I’m thinking more of a team setting where the whole thing is being used and it’s hard to argue against using certain pieces of it when it’s already there, and there are a few things in Moar I’m very against (but that’s not your fault, we’re all entitled to write code how we want!) Generally, though, I’ve found myself happily ditching small helpers that just wrap an English term around very simple code and it makes reading code far more enjoyable for me. slot_given?
is an example of something I’ve run into which is just a wrapper around foo != []
. Another example is present?
(available in Moar
but a common one people make these regardless)—that one is more problematic as it conveys “I don’t care what type this is” when that is never true.
Thanks for the responses all, it’s useful to see what people find useful, there were a few in there that were new to me, and I’m sure this thread will be helpful for others starting new projects too
This one made me - I usually try to remove Timex from legacy projects unless there is some specific functionality it’s providing that can’t easily be replaced by built-in functionality.
I tend to include blindly dev/test deps only
{:mox, "~> 1.0", only: [:dev, :test]},
{:stream_data, "~> 1.0", only: [:dev, :test]},
{:doctest_formatter, "~> 0.2", only: [:dev], runtime: false},
{:enfiladex, "~> 0.3", only: [:dev, :test]},
{:excoveralls, "~> 0.14", only: [:test], runtime: false},
{:credo, "~> 1.0", only: [:dev, :test]},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:ex_doc, ">= 0.0.0", only: [:dev]}
Usually I also use some of my libs, such as estructura
, finitomata
, rambla
, telemetria
and antenna
.
Good point, I just realized I probably haven’t started a new project since v1.17 added Duration
and shift
and didn’t bother to refactor. Looking into one of my projects, it’s 50% Timex.shift
that could be removed but the other 50% is Timex.format
that I think is still worth the extra dependency. But granted, it doesn’t apply to all fresh projects.
After a few minutes of reading I have zero idea what a “common test” is. No links, no explanations, and I’m not going to the Erlang docs to search.
Bad DX. If the author can’t advertise the value of their library in a minute, it’s not going to get used too much.
Though I’ll admit “multi-node test” does sound a touch intriguing.
Libraries that I’ve seen on all my projects (excluding Phoeni and all the defaults, LiveView, Ecto, …).
Jobs
{:oban, “~> 2.19”}
Caching
{:nebulex, “~> 2.6”}
Utils
{:req, “~> 0.5”}
{:uniq, “~> 0.6”}
{:dotenvy, “~> 1.1”}
Development
{:credo, “~> 1.7”, only: :dev, runtime: false}
The UX is very carefully designed. If you don’t know what common_test
is, you don’t want to mess with this library. common_test
is so huge of a concept, that explaining it in enfiladex
docs would be alongside with explaining what Postgres
is in docs for Postgrex
ecto adapter.
A link to the common test docs (I assume this is it) would probably be helpful for the unenlightened.
Thank you! The thing is, I am still 102% sure enfiladex
is not designed for those who are unfamiliar with common_test
, because it only provides some helpers to convert ex_unit
into common tests, but it’d appear extremely unfriendly to anyone not having an experience with common test itself (imho.)
I pay a lot of attention to the documentation in all my libs save for that one, and I believe that’s right.