jung-hunsoo
Pattern matching is an awesome feature. Many other languages use ifs a lot to support backward compatibility. This occurs often in the fast growing area including Android’s Kotlin.
Elixir and its libraries are not free from this problem too. But it can be resolved significantly by leveraging Pattern matching.
Here’s my concept:
# AS-IS
(prev) fn clean_obsolete_record(%{id: 31}), do: ...
(current) fn clean_unused_record(%{id: 31}), do: ...
(next) fn clean_unused_record_2(%{id: 31}), do: ...
# TO-BE
(prev) fn clean_obsolete_record(%{id: 31}), do: ...
(current) fn clean_obsolete_record(%{id: 31}, vsn: 2), do: ...
(next) fn clean_obsolete_record(%{id: 31}, vsn: 3), do: ...
This code convention provides three advantages:
- Backward-compatibility is achieved easily.
- Codes manageability is improved.
Is this feasible and useful approach?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
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
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Other Trending Topics
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tty
My preference would be:
This makes it clear from a data perspective which function would execute. If you happen to store the function argument in a database or have to replay the data there is a clear indicator which function would execute.
YMMV
Fl4m3Ph03n1x
I prefer this approach. this pattern is not really new in Elixir when you need to control flow.
There is a pattern called Token:
Which fits nicely into this. Basically a Token contains all the information of your request and workflow, and it allows you to pattern match on versions like you are doing.
jung-hunsoo
@tty Thanks. It would work too, since the pattern matching also compares parameters. What I’m thinking about is
fn clean_obsolete_record(general_args, vsn: vsn), do: ...which separates general_args with a predefinedvsnparameter.vsncan be overwritten If they are mingled in the collection. Also this approach enforces versioning to the developers.@Fl4m3Ph03n1x Thanks. I understand that the tokening in the link page is one good example of pattern matching. (Pattern matching is so useful and make the codes cleaner than
whenguard.) For me, the original idea was kindaAPI versioningcommonly used in API endpoint.Versioning APIs will provide backward compatibility and eliminate deprecation problems significantly and easily.