Fl4m3Ph03n1x

Fl4m3Ph03n1x

Do you use Credo?

Background

Recently I joined a new project in and I immediately saw some improvements could be done.
It so happens that many of these improvements are part of credo which I am a big fan of.

So naturally I suggested its use on our project.

Denied!

My request was denied and so we entered a constructive discussion. I pointed out all the warning types Credo checks (missing docs, refactors, software design issues, complexity, etc) and mentioned the community usually sees value in such a tool.

As a counter argument, some members of my team mentioned that none of the big Elixir project’s use it: Plug, Ecto, Phoenix. So, perhaps this tool doesn’t bring as much value as I think it does and so we should not use it.

Questions

  • This is IMO, a really good counter argument. Why don’t any of the big Elixir projects use Credo?
  • Do you use Credo? If not why?

Do notice that if you don’t like a specific rule or don’t agree with a specific recommendation you can ask Credo to not check them. So for me at least, not agreeing with 3% of the rules Credo suggests is not really an argument to not use it.

Most Liked

sasajuric

sasajuric

Author of Elixir In Action

I think credo is a great tool if you want to have a project-wide or company-wide styleguide and enforce as much of it as possible automatically.

I believe that having a styleguide together with consistent layout (which is handled by the formatter) makes it easier to keep the code understandable. To be clear, neither styleguide nor consistent layout are enough. It’s still possible to have a code which is nicely formatted and follows the styleguide, but is at the same time a convoluted mess and hard to understand. That said, I think that consistent styleguide and layout, especially if enforced automatically, can help the team focus on higher level issues, such as separation of concerns, building cohesive abstractions, reducing coupling, …

When I started working for my current client, introducing credo was one of the first thing I did (together with enforced formatting and treating warnings as errors on CI). We use the strict mode, enabling some of the additional checks, and disabling a few of them we don’t want to follow (e.g. TagTODO), and even writing a few of our own checks. Some of the things we enforce with credo:

  • consistent module layout (e.g. public funs are written before behaviour callbacks, are written before private funs)
  • proper file naming (module Foo.Bar.Baz should reside in lib/foo/bar/baz.ex)
  • mandatory typespecs for public functions
  • forbidding alias Foo, as: Bar

So I personally find credo very useful. Being very unopinionated, I think of it as a styleguide toolkit. It ships with a bunch of interesting and useful checks, such as detecting leftover IO.inspect, or redundant try, double negations, etc. It provides some sane defaults out of the box, which can be changed both globally (per project) and locally (on a case-by-case basis).

24
Post #7
devonestes

devonestes

I’ve used Credo on most of the projects I’ve ever been on. In fact, I just wrote a bunch of custom checks for my current job. There was no resistance there, but the argument I make in every case (when needed) is that things like Credo are good for teams. When a computer (or computer program) tells you to change your formatting or whatever, you just do it. When a teammate does it in PR review you get angry at them for making you change your code, which is “perfectly fine, by the way.” It’s way better to hate Credo for being picky than to hate your coworker for the same thing.

Plus, it’s nice to just remove things like that entirely from the code review process. When I review code, the only thing I need to look at are the contents of the code and not the formatting/style. If it passes the formatter and Credo checks, then it is 100% “correct” style & formatting.

Most of the big OSS projects actually pre-date Credo, and also most of them try and keep their dependencies as minimal as possible (which is a good thing). They’re actually doing their users a solid by not using Credo, since it makes dependency resolution easier. For example, if they were using Credo 1.0 and you were using Credo 0.9 or something, there would be a dependency conflict you’d need to manage.

sasajuric

sasajuric

Author of Elixir In Action

I’m not sure running it in a pre-commit hook is optimal. Credo isn’t very slow, but IMO it’s not that fast to do it on every commit. Moreover, I wouldn’t even want credo to prevent me from committing some intermediate WIP commits.

I run credo during CI check, and that’s good enough for me. Usually I remember to check credo locally before pushing the code, but even if I don’t, it’s not a big deal. I’ll get a CI error, and fix it.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement