Crowdhailer

Crowdhailer

Creator of Raxx

My opinion very much undecided on this Question so all comments welcome.

This is probably best discussed using the concrete example I am considering at the moment in Raxx.
(Raxx has the goal of being a capable toolkit for developing lean web applications in Elixir.)

For simple endpoints applications implement the Raxx.SimpleServer behaviour.
Simple endpoints are when streaming is not required for either request or response, if streaming is required then the Raxx.Server behaviour is implemented

A simple example would look like the following.

defmodule MyServer do
  use Raxx.SimpleServer

  @impl Raxx.SimpleServer
  def handle_request(%{method: :GET, path: []}, _state) do
    response(:ok)
    |> set_header("content-type", "text/plain")
    |> set_body("Hello, World!")
  end
end

The line use Raxx.SimpleServer defined a default implementation of handle_request/2 which any application is always expected to overwrite.
The default implementation shows a page that explains what a user should be implementing, and this is done to help users.

https://github.com/CrowdHailer/raxx/blob/master/lib/raxx/simple_server.ex#L105-L111

I am no revisiting this choice for the following reasons.

  • behaviours create a compile time warning when one of their callbacks is not implemented,
    this is lost by implementing a default. Any mistakes are found only at runtime, hopefully by tests.
  • Safely generating this page required adding a dependency on eex_html, this dependency is included only to render pages that should never be rendered in a correctly set up application
  • These helper pages are useless if the client is not a human. i.e. when making api services.

In summary I am thinking of removing this default because a compile time warning is more useful than any information that might be show at runtime in the page, and in any case is just a copy of the information available in the documentation

Showing Posts 1 to 5

LostKobrakai

LostKobrakai

If you want to have a descriptive error page I feel it’s in the same realm as the phoenix error page with the debugging information: Enable it in :dev, but fail for other environments.

dimitarvp

dimitarvp

Ignoring warnings when compiling dependencies is fine but one should not ignore warnings in their own code – and warnings about non-implemented callbacks are important.

IMO get rid of the help page for exactly the reasons you mentioned.

@LostKobrakai has a point as well; you could keep the current behaviour in :dev environment only.

OvermindDL1

OvermindDL1

What phoenix does in such cases (like router callbacks into controllers and so forth) is it has a ‘jump’ function (action I think?) that is what actually calls the appropriate method, and if it throws, like it doesn’t exist, then it reports it as such. This means you don’t get compile warnings though as it’s an apply, however with macro work to ‘bake in’ the calls without using apply you could get the best of both worlds? It would require making a pre-call function in that same module and calling that instead, and having it call the real function that needs to be overridden. That would give both a warning, maybe even an error at compile-time, but if such a thing does somehow make it through then it would give a good message.

On the other hand, making a public function with a (mostly) uncallable name that just calls the functions that needs to be implemented locally then it wouldn’t compile if they didn’t exist, but you’d need to craft good default data to let dialyzer handle it properly and that can be pretty hard to do without taking ‘opaque’ arguments in (this function would never actually be called, it’s sole purpose is just to require those functions).

Although at that point you could just analyze the module info(:functions) at compile time from the thing that calls those implementations and verify they exist first, but that would involve requiring those files to be compiled first and the beam files to be scanned.

Honestly, I’d say just implement a behaviour, no default implementations, and let the compiler handle it as normal. :slight_smile:

josevalim

josevalim

Creator of Elixir

FWIW, we have been slowly migrating away from default implementations and using optional callbacks instead. If the user wants warnings, then @impl is the way to go. There is an old discussion about it here: Behaviours, defoverridable and implementations

Crowdhailer

Crowdhailer OP

Creator of Raxx

A lot of smart and interesting solutions there. thanks.

But I think I also agree with your summary, let the compiler handle it.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews