reid-rigo

reid-rigo

Code review request: codeowners package

Hello, I’m new to Elixir and created this package, which is the adaptation of some Ruby code I wrote, as a learning exercise: codeowners | Hex

I’m looking for feedback on:

  • How to make this code more idiomatic
  • More appropriate functions/modules to use
  • Best practices for libraries

Feedback is welcome here or in Github

Most Liked

sodapopcan

sodapopcan

For me it’s not about refactoring—a global rename is a global rename—it’s about ease of reading. When I see __MODULE__ I immediately think “local.” Seeing a fully-qualified self-referencing module name always causes a bit of a jarring pause where I have to go and confirm that it is indeed referencing itself. This is indeed on the minor end of readability issues and is not a hill I’d die on. I do, however, vehemently disagree with the advice in that guide to use an alias if you want “a prettier name” :face_with_raised_eyebrow: If it weren’t for the few legitimate uses cases it has, I wouldn’t be upset if the :as option for alias were removed from the language.

RudManusachi

RudManusachi

Hi, @reid-rigo :wave: and welcome!

I’d point you to this style guide: GitHub - christopheradams/elixir_style_guide: A community driven style guide for Elixir

Use the __MODULE__ pseudo variable when a module refers to itself.

It might look weird at first (becuase of double underscores and all caps) but it’s very common to refer to the module itself.

RudManusachi

RudManusachi

One of the point you were asking:

  • How to make this code more idiomatic

So I just pointed to what seemed more idiomatic to me :slightly_smiling_face:

Based on a suggestion in another thread I tried #{__MODULE__} , but that outputs Elixir.Codeowners when I run mix docs.

So it does with any module name, such as: #{Logger} would print "Elixir.Logger". If you want to nicely disregard the prefix Elixir. you could inspect/1 it:

"#{inspect(__MODULE__)}"

See example: elixir/lib/elixir/lib/kernel/utils.ex at c5816a227f5ad295ccbfcc5571308f76190d6bfe · elixir-lang/elixir · GitHub

al2o3cr

al2o3cr

Some thoughts, in no particular order:

  • rule_for_path could be slightly more efficient if the Enum.reverse was moved into build to avoid doing the same computation more than once

  • the typespec for Codeowners.Rule is not satisfied by the default values in the defstruct. rule_for_path can return a struct containing unexpected types in the “no rule matched” case.

  • the use of File.cwd! in build is odd; consider allowing callers to either supply a root directly or as an override. To reduce the need for most callers to pass a root, load could do some guessing based on if the supplied file is in a doc or .github directory.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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

We're in Beta

About us Mission Statement