fireproofsocks
I found an old post discussing @impl and @spec: @behaviour, @callback and @spec - #13 by Eiji
I couldn’t tell where this discussion left off.
When I define a @callback, it defines the spec that implementations should follow. So it feels redundant to add a @spec declaration to a function that already has @impl. I would think that saying @impl true is sufficient or even preferable (in a DRY sort of way).
What I’m noticing is in my generated docs, functions that implement a callback do not show a @spec unless it is added explicitly. (And this means more or less copying the @callback definition).
Is this by design? What is the thinking around this, and how does this square with the DRY ideal of not duplicating work?
Thanks for any input!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
FWIW, searching the core Elixir repo for
@impl trueshows a lot of implementations that are@moduledoc falseor at least have no@docannotation.Calendar.ISOdoes the repeating-spec thing:Eiji
The result of mentioned post was an issue:
with
José Valimsolution:Currently when you write this code:
You have:
ex_docshows:with a link to callback documentation.
Having in mind above you do not need to write a
spec. However if you write any@docto your implementation then you need to notec:Module.callback/arity, so for example inex_docyou can quickly navigate to said callback to see it’s@spec. Also modern editors are able to show same docs in popup. Therefore you do not need to write@specon yourself.However there is something weird if you add
@impl trueor@imple ExampletoSample.foo/0implementation. There are no documentation both iniexandex_doc, so maybe it at least was intended. It’s worth to open an issue for that.Eiji
Added 2 issues:
fireproofsocks
Thanks for filing those – they both were immediately closed, so I guess this behavior is intentional, but I can’t follow the reasoning as far as the spec is concerned. I still expect to see the original callback spec for functions that are implementing a callback.
Eiji
I’m a bit confused as well. However look that you can still use
@behaviourwithout@impl. For now that’s the only workaround I know about.al2o3cr
I feel like there’s a tension between two potential uses for
@behaviour:the original meaning, where it defined callbacks for mostly-internal use. For instance, you likely don’t want to see
handle_callheads in the documentation for a GenServera new meaning, where it defines an interface for Mox et al that are used externally. I’ve seen this done with a single module that declared
@callbacks and@impled them, where the only “alternative implementation” was inMIX_ENV=test.RudManusachi
I fell like even with mox we should aim to keep behaviour implementations as internal modules that are not documented publicly.
)
Looking at the example provided in the mox docs. We want to document high level functions in
display_temp/1anddisplay_humidity/1inMyApp.HumanizedWeather, but not the implementation ofMyApp.WeatherAPI(though, I see how it could be desirable as wellAlso for the same reason, once function is marked with
@impl true,iexshell doesn’t autocomplete it by pressing tab =)Eiji
That’s not the only problem. The documentation would be inconsistent. In theory (in docs) if we would not do anything then we will have a behaviour without any (public) implementations (like it’s private API used only internally) or if we mention that
Xmodule is implementation of some behaviour then we will have only@moduledocand all@docnot related to behaviour (if any).Some may say that in such case we can list all implementations in behaviour documentation. Well … good luck with documenting behaviour in libraries.
It would be terribly confusing to end user.
So we end up with a special group in sidebar for behaviour implementations. Those would look like an
extramarkdown pages in worst case (i.e. no other public functions) each having only one paragraph with a short description that this module implements said behaviour and it’s implemented for (…). This may look not bad if we would have few implementations (we would group them anyway). Now think how a single implementation would look with just one paragraph written in other library or app …Honestly I would expect to see a list of all implemented callbacks each with
@specand a first paragraph of@doc+ a link to fullcallbackdescription and as you said it would be much easier iniexand code editors to haveautocompleteworking.