joaoevangelista
Is there some tool that can help us refactoring our code base so we don’t leave undefined functions somewhere in the depths of our code?
Or if anyone has some tips on how to optimize it. Since we don’t have types and a compiler to check on those things, and I’m kind lost on how to approach it.
Thanks in advance!
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
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 have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Maybe dialyzer would help with
It certainly helps me with this.
Also tests.
svarlet
Mix xref may help a bit too
dom
What do you mean? There is most certainly a compiler, and it warns about undefined functions…
MalloZup
@joaoevangelista
I would vote for:
( to be safe: codecoverage run code but it’s up to human to have the right tests
when do unit_test focus on public interface tests. Don’t test private function to much because this will change . The public function should not change much, so you need to test this good, and if you test public you test private function that compose your public function/module.
this is needed when you want to spare cost maintenance of tests.
If you do this i think you can refractor with confidence
I would also suggest you the great book Search , it adress your question and more . ( i’m currently reading and i really like it
)
belaustegui
I can not stress the usefulness of
mix xrefenough. I use it alout to find unused functions and modules.mix xref callers MODULE_OR_FUNCTIONprovides very useful information about which file and from which line is calling the given module or function.Apart from the mandatory tests, I would also recommend using
credoto get insights about possible improvements, code duplication, function nesting, etc.If you have a CI setup, I would advice to use
mix compile --warnings-as-errorsto cause any builds with comilation errors to fail and to includemix format --check-formattedto ensure that the source is formatted properly.We can agree or disagree with Elixir default formatting settings, but having a common formatting accross all the source files makes them much more easier to work with.
joaoevangelista
That’s alot!
mix xrefwil be the most powerful tool for doing that, I keep forgetting about it,dialyzerwould help too, while coding Thanks Elixir-LS!. I think the problem with me is that I will need to change the way I iterate, even doing tests and using CI, I relied too much on IDEs to do that kind of stuff, just a shortcut and done! renamed.credowill support most of inspections I’m used of.Combining
xrefwith a defined public API can be the way to go, also a more “flowable” dependencies between modules. Maybe it been different than other languages leads us to think about what we are coding more than simply throw code into an editor.tme_317
I was trying to figure out how to use
mix xreftoday to find all unused (dead code) functions after a recent major refactoring. I know many stale functions in my project no longer have callers… is there an automated way to find them? I found GitHub - joshuaclayton/unused: Deprecated; see https://github.com/unused-code/unused · GitHub which looks promising also but couldn’t get it to install from homebrew.jswny
Yeah the compiler will definitely warn you about a function that doesn’t exist if you are trying to call it, or an unused function.
However, besides running Dialyxir on my codebase, I find that testing is the best way to approach this. Unit test all of your functions. Write good integration tests as well. That way, if you change anything, your tests will tell you what’s wrong, or at least what has changed so that you can fix it. Testing is important to make sure your code works as you intended but really, in my experience, a well-written test suite is extremely good at telling you what to fix after a refactoring.
My test suite gives me confidence that after I refactor something I know exactly what I missed.
belaustegui
As far as I know the compiler will only emit warnings about private unused functions. Public unused functions will not be notified in any way.
I’ve been playing myself with the idea of building an elixir command that used
mix xrefunderneath and report about unused functions. Turns out that the thing is really complicated because functions can be called dynamically usingapply,Task, etc.For the moment I’ve found that the best way to keep unused code out is to have proper interfaces between the application components (Phoenix Context are an example) and manually check (using the editor search across the project) that functions in that interface are being used from somewhere.
tme_317
Thanks for the help… definitely I wasn’t expecting dynamic function calls (i.e.
apply) to be easy to detect but thought the compiler orxrefcould maybe find unused functions referenced by static calls.Agree also on your last point… just being a bit lazy. I will manually go through all public interfaces (contexts) and use VSCode’s “Find All References” to see where they are called and make sure all private functions are properly
defp.Finally definitely agree on having a good test suite to ease refactoring… then you can use ExCoveralls also to uncover functions that are not used (or at least not tested).